@luxalgo/vela-pinets 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/index.cjs +47 -8
- package/dist/index.d.cts +83 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +47 -8
- package/dist/vela-pinets.global.js +8888 -6559
- package/dist/vela-pinets.global.min.js +45 -38
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -256,7 +256,7 @@ function isVisibleColor(color) {
|
|
|
256
256
|
if (lower === "na" || lower === "nan") return false;
|
|
257
257
|
const hex8 = /^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})$/.exec(s);
|
|
258
258
|
if (hex8 && parseInt(hex8[1] ?? "ff", 16) === 0) return false;
|
|
259
|
-
if (
|
|
259
|
+
if (/^rgba\([^)]*,\s*0(?:\.0+)?\s*\)$/i.test(s)) return false;
|
|
260
260
|
return true;
|
|
261
261
|
}
|
|
262
262
|
function normColor(color, fallback) {
|
|
@@ -1325,6 +1325,17 @@ function ensurePineMarkerPatch() {
|
|
|
1325
1325
|
};
|
|
1326
1326
|
}
|
|
1327
1327
|
|
|
1328
|
+
// src/pinets/footprints.ts
|
|
1329
|
+
function footprintSurface(source, chartSymbol, chartTimeframe) {
|
|
1330
|
+
if (!source) return {};
|
|
1331
|
+
return {
|
|
1332
|
+
getFootprintData: (symbol, timeframe, limit, sDate, eDate) => source(plainSymbol(symbol ?? chartSymbol()), timeframe ?? chartTimeframe(), { from: sDate, to: eDate, limit })
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
function plainSymbol(symbol) {
|
|
1336
|
+
return symbol.split(";")[0] ?? symbol;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1328
1339
|
// src/pinets/runtime.ts
|
|
1329
1340
|
function propsFor(scanned, defaultProps, filter) {
|
|
1330
1341
|
if (filter === "none") return [];
|
|
@@ -1358,13 +1369,14 @@ function indicatorFor(cache, source, inputs, props = {}) {
|
|
|
1358
1369
|
return cache.lastInd;
|
|
1359
1370
|
}
|
|
1360
1371
|
async function runPineStatic(opts) {
|
|
1361
|
-
const { ind, bars, market, visibleRange, prepared, instanceId, inputs, props, fetchSeries } = opts;
|
|
1372
|
+
const { ind, bars, market, visibleRange, prepared, instanceId, inputs, props, fetchSeries, footprints } = opts;
|
|
1362
1373
|
ensurePineTablePatch();
|
|
1363
1374
|
ensurePineMarkerPatch();
|
|
1364
1375
|
const klines = toKlines(bars, market.timeframe, market.symbolInfo);
|
|
1365
1376
|
const source = {
|
|
1366
1377
|
getMarketData: (sym, tf, limit, sDate, eDate) => isChartSeries(sym, tf, market) ? Promise.resolve(klines) : secondaryKlines(fetchSeries, sym, tf, limit, sDate, eDate, syminfoForSymbol(market, sym)),
|
|
1367
|
-
getSymbolInfo: async (sym) => syminfoForSymbol(market, sym)
|
|
1378
|
+
getSymbolInfo: async (sym) => syminfoForSymbol(market, sym),
|
|
1379
|
+
...footprintSurface(footprints, () => market.symbol, () => market.timeframe)
|
|
1368
1380
|
};
|
|
1369
1381
|
const pine = new PineTS(source, chartTickerOf(market), market.timeframe, klines.length);
|
|
1370
1382
|
await pine.ready();
|
|
@@ -1471,10 +1483,11 @@ async function secondaryKlines(fetchSeries, sym, tf, limit, sDate, eDate, syminf
|
|
|
1471
1483
|
const bars = await fetchSeries(sym, tf, { from: sDate, to: eDate, limit });
|
|
1472
1484
|
return toKlines(bars, tf, syminfo);
|
|
1473
1485
|
}
|
|
1474
|
-
function makeLiveProvider(getBars, getMarket, fetchSeries) {
|
|
1486
|
+
function makeLiveProvider(getBars, getMarket, fetchSeries, footprints) {
|
|
1475
1487
|
let lastKey = "";
|
|
1476
1488
|
let dirty = false;
|
|
1477
1489
|
return {
|
|
1490
|
+
...footprintSurface(footprints, () => getMarket().symbol, () => getMarket().timeframe),
|
|
1478
1491
|
markDirty: () => {
|
|
1479
1492
|
dirty = true;
|
|
1480
1493
|
},
|
|
@@ -1503,7 +1516,7 @@ function openLiveStream(opts) {
|
|
|
1503
1516
|
const ind = indicatorFor(opts.cache, opts.token.source, opts.inputs, opts.props ?? {});
|
|
1504
1517
|
const anchorTime = bars[0]?.time;
|
|
1505
1518
|
const initialLen = Math.max(1, bars.length);
|
|
1506
|
-
const provider = makeLiveProvider(opts.bars, opts.market, opts.fetchSeries);
|
|
1519
|
+
const provider = makeLiveProvider(opts.bars, opts.market, opts.fetchSeries, opts.footprints);
|
|
1507
1520
|
const pine = new PineTS(provider, chartTickerOf(opts.market()), opts.market().timeframe, initialLen);
|
|
1508
1521
|
if (opts.visibleRange) pine.setVisibleRange(opts.visibleRange.left, opts.visibleRange.right);
|
|
1509
1522
|
const evt = pine.stream(ind, { live: true, interval: 1e3, pageSize: initialLen });
|
|
@@ -1586,9 +1599,11 @@ var PineEngine = class {
|
|
|
1586
1599
|
capabilities = { streaming: true, visibleRange: true, inputs: true, props: true };
|
|
1587
1600
|
defaultProps;
|
|
1588
1601
|
propsVisibility;
|
|
1602
|
+
footprints;
|
|
1589
1603
|
constructor(opts = {}) {
|
|
1590
1604
|
this.defaultProps = opts.defaultProps;
|
|
1591
1605
|
this.propsVisibility = opts.props ?? "all";
|
|
1606
|
+
this.footprints = opts.footprints;
|
|
1592
1607
|
}
|
|
1593
1608
|
prepare(source, instanceId) {
|
|
1594
1609
|
return Promise.resolve(preparePine(source, instanceId, this.defaultProps, this.propsVisibility));
|
|
@@ -1615,6 +1630,7 @@ var PineEngine = class {
|
|
|
1615
1630
|
bars: getBars,
|
|
1616
1631
|
market: () => req.market,
|
|
1617
1632
|
fetchSeries: req.fetchSeries,
|
|
1633
|
+
footprints: this.footprints,
|
|
1618
1634
|
visibleRange,
|
|
1619
1635
|
onModel: (m) => {
|
|
1620
1636
|
if (!stopped) handlers.onModel(m);
|
|
@@ -1669,7 +1685,8 @@ var PineEngine = class {
|
|
|
1669
1685
|
instanceId: token.instanceId,
|
|
1670
1686
|
inputs,
|
|
1671
1687
|
props,
|
|
1672
|
-
fetchSeries: req.fetchSeries
|
|
1688
|
+
fetchSeries: req.fetchSeries,
|
|
1689
|
+
footprints: this.footprints
|
|
1673
1690
|
});
|
|
1674
1691
|
if (stopped) return;
|
|
1675
1692
|
lastCtx = outcome.ctx;
|
|
@@ -1708,7 +1725,7 @@ var PineEngine = class {
|
|
|
1708
1725
|
};
|
|
1709
1726
|
|
|
1710
1727
|
// inline-worker:C:\Users\alexgroverr\projects\LuxAlgo-vela\repos\Vela-pinets\src\pinets-worker\worker.ts
|
|
1711
|
-
var worker_default = '"use strict";(()=>{var qu=Object.defineProperty;var Hu=(t,e,n)=>e in t?qu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ja=(t,e,n)=>Hu(t,typeof e!="symbol"?e+"":e,n);function Ku(t){return e=>new Y(e.array.map(n=>Math.abs(n)),e.type,t)}function Yu(t){return e=>{let n=0,r=0;for(let i of e.array){let s=Number(i);isNaN(s)||(r++,n+=(s-n)/r)}return r===0?NaN:t.precision(n)}}function Gu(t){return(e,n)=>{let r=e.array,i=0,s=r.length-1;for(;i<=s;){let a=Math.floor((i+s)/2),o=r[a];if(o===n)return a;o<n?i=a+1:s=a-1}return-1}}function Xu(t){return(e,n)=>{let r=e.array,i=0,s=r.length;for(;i<s;){let a=Math.floor((i+s)/2);r[a]<n?i=a+1:s=a}return i<r.length&&r[i]===n?i:i-1}}function Zu(t){return(e,n)=>{let r=e.array,i=0,s=r.length;for(;i<s;){let a=Math.floor((i+s)/2);r[a]<=n?i=a+1:s=a}return i>0&&r[i-1]===n?i-1:i}}function Qu(t){return e=>{e.array.length=0}}function Ju(t){return(e,n)=>(e.array.push(...n.array),e)}function eh(t){return e=>new Y([...e.array],e.type,t)}function th(t){return(e,n,r=!0)=>{let i=e.array,s=n.array;if(i.length!==s.length)return NaN;let a=0,o=0,l=0,c=[];for(let f=0;f<i.length;f++){let m=Number(i[f]),_=Number(s[f]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(_)&&_!==null&&_!==void 0&&(a+=m,o+=_,l++,c.push(f))}if(l===0)return NaN;let u=a/l,p=o/l,h=0;for(let f of c){let m=Number(i[f]),_=Number(s[f]);h+=(m-u)*(_-p)}let d=r?l:l-1;return d<=0?NaN:t.precision(h/d)}}function nh(t){return e=>e.array.every(n=>!isNaN(n)&&n)}function rh(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?G.int:G.float:t.every(e=>typeof e=="string")?G.string:t.every(e=>typeof e=="boolean")?G.bool:G.any}function ft(t){return typeof t=="number"?Number.isInteger(t)?G.int:G.float:typeof t=="string"?G.string:typeof t=="boolean"?G.bool:G.any}function gr(t,e){if(typeof t=="number"&&isNaN(t)||e===G.any)return!0;switch(e){case G.int:return Number.isInteger(t)||isNaN(t);case G.float:return typeof t=="number";case G.string:return typeof t=="string";case G.bool:return typeof t=="boolean";case G.box:case G.label:case G.line:case G.linefill:case G.table:case G.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function ih(t){return(e,n,r=0,i)=>{let s=e.array.length,a=i!==void 0?Math.min(i,s):s;for(let o=r;o<a;o++){if(!gr(n,e.type))throw new Error(`Cannot call \'array.fill\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);e.array[o]=typeof n=="number"?t.precision(n):n}}}function sh(t){return e=>e.array.length>0?e.array[0]:t.NA}function ah(t){return(e,n)=>(n<0&&(n=e.array.length+n),n<0||n>=e.array.length?(t.warn(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.get"),NaN):e.array[n])}function oh(t){return(e,n)=>e.array.includes(n)}function lh(t){return(e,n)=>typeof n=="number"&&n!==n?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(n)}function ch(t){return(e,n,r)=>{if(!gr(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(n<0&&(n=e.array.length+n),n<0||n>e.array.length){t.warn(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.insert");return}e.array.splice(n,0,r)}}function uh(t){return(e,n=",")=>e.array.join(n)}function hh(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function ph(t){return(e,n)=>e.array.lastIndexOf(n)}function dh(t){return(e,n=0)=>{let r=e.array;if(r.length===0)return t.NA;if(n===0){let i=r[0];for(let s=1;s<r.length;s++)r[s]>i&&(i=r[s]);return i??t.NA}return[...r].sort((i,s)=>s-i)[n]??t.NA}}function fh(t){return e=>{let n=e.array;if(n.length===0)return NaN;let r=new Array(n.length);for(let s=0;s<n.length;s++)r[s]=n[s];r.sort((s,a)=>s-a);let i=Math.floor(r.length/2);return r.length%2!==0?r[i]:(r[i-1]+r[i])/2}}function mh(t){return(e,n=0)=>{let r=e.array;if(r.length===0)return t.NA;if(n===0){let i=r[0];for(let s=1;s<r.length;s++)r[s]<i&&(i=r[s]);return i??t.NA}return[...r].sort((i,s)=>i-s)[n]??t.NA}}function yh(t){return e=>{if(e.array.length===0)return NaN;let n=new Map,r=0;for(let s of e.array){let a=(n.get(s)||0)+1;n.set(s,a),a>r&&(r=a)}let i=[];for(let[s,a]of n)a===r&&i.push(s);return i.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),i[0]}}function gh(t){return(e,n)=>{let r=e.array,i=r.length;if(i===0)return NaN;let s=new Array(i);for(let c=0;c<i;c++){let u=Number(r[c]);if(isNaN(u)||u===null||u===void 0)return NaN;s[c]=u}s.sort((c,u)=>c-u),n<0&&(n=0),n>100&&(n=100);let a=n/100*i-.5;if(a<=0)return t.precision(s[0]);if(a>=i-1)return t.precision(s[i-1]);let o=Math.floor(a),l=a-o;return t.precision(s[o]*(1-l)+s[o+1]*l)}}function xh(t){return(e,n)=>{let r=e.array,i=r.length;if(i===0)return NaN;let s=new Array;for(let o=0;o<i;o++){let 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),n<0&&(n=0),n>100&&(n=100);let a=Math.ceil(n/100*i);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function _h(t){return(e,n)=>{if(e.array.length===0)return NaN;let r=Math.floor(n);if(r<0||r>=e.array.length)return NaN;let i=Number(e.array[r]);if(isNaN(i)||i===null||i===void 0)return NaN;let s=0;for(let o of e.array){let l=Number(o);!isNaN(l)&&l!==null&&l!==void 0&&l<i&&s++}let a=e.array.length-1;return a<=0?NaN:s/a*100}}function bh(t){return e=>e.array.pop()}function vh(t){return(e,n)=>{if(!gr(n,e.type))throw new Error(`Cannot call \'array.push\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);e.array.push(typeof n=="number"?t.precision(n):n)}}function wh(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function Sh(t){return(e,n)=>(n<0&&(n=e.array.length+n),n<0||n>=e.array.length?(t.warn(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.remove"),NaN):e.array.splice(n,1)[0])}function Eh(t){return e=>{e.array.reverse()}}function Ch(t){return(e,n,r)=>{if(!gr(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(n<0&&(n=e.array.length+n),n<0||n>=e.array.length){t.warn(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.set");return}e.array[n]=typeof r=="number"?t.precision(r):r}}function Ih(t){return e=>e.array.shift()}function Nh(t){return e=>e.array.length}function kh(t){return(e,n,r)=>{let i=r!==void 0?r:void 0;return new Y(e.array.slice(n,i),e.type,t)}}function Ah(t){return e=>e.array.some(n=>!isNaN(n)&&n)}var Vn=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(Vn||{}),Fo=(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))(Fo||{}),Bo=(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))(Bo||{}),Vo=(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))(Vo||{}),Wo=(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))(Wo||{}),$o=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))($o||{}),jo=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(jo||{}),Uo=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Uo||{}),Mh=(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))(Mh||{}),zo=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(zo||{}),qo=(t=>(t.bar_index="bi",t.bar_time="bt",t))(qo||{}),Ho=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(Ho||{}),Ko=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Ko||{}),Yo=(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))(Yo||{}),Go=(t=>(t.family_default="default",t.family_monospace="monospace",t))(Go||{}),Xo=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(Xo||{}),Zo=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Zo||{}),Qo=(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))(Qo||{}),Jo=(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))(Jo||{}),el=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(el||{}),tl=(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))(tl||{}),nl=(t=>(t.left="left",t.none="none",t.right="right",t))(nl||{}),rl=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(rl||{}),Th={order:Vn,currency:Fo,dayofweek:Bo,display:Vo,shape:Wo,location:$o,size:jo,format:Uo,barmerge:zo,xloc:qo,yloc:Ho,extend:Ko,text:Yo,font:Go,adjustment:Xo,backadjustment:Zo,earnings:Qo,dividends:Jo,splits:el,position:tl,scale:nl,settlement_as_close:rl};function Ph(t){return(e,n=Vn.ascending)=>{e.array.sort((r,i)=>{let s=isNaN(r)?1/0:r,a=isNaN(i)?1/0:i;return n===Vn.ascending?s-a:a-s})}}function Dh(t){return(e,n=Vn.ascending)=>{let r=e.array.map((i,s)=>s);return r.sort((i,s)=>{let a=isNaN(e.array[i])?1/0:e.array[i],o=isNaN(e.array[s])?1/0:e.array[s];return n===Vn.ascending?a-o:o-a}),new Y(r,G.int,t)}}function Rh(t){return e=>{let n=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new Y(e.array.map(()=>NaN),G.int,t):r===0?new Y(e.array.map(()=>1),G.int,t):new Y(e.array.map(i=>(i-n)/r),G.int,t)}}function Oh(t){return(e,n=!0)=>{let r=e.array,i=r.length;if(i===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<i;u++){let p=Number(r[u]);!isNaN(p)&&p!==null&&p!==void 0&&(s+=p,a+=p*p,o++)}if(o===0)return NaN;let l=s/o,c=a/o-l*l;return c<0?NaN:(!n&&o>1&&(c=c*o/(o-1)),!n&&o===1?0:t.precision(Math.sqrt(c)))}}function Lh(t){return e=>t.precision(e.array.reduce((n,r)=>{let i=Number(r);return isNaN(i)?n:n+i},0))}function Fh(t){return(e,n)=>{if(!gr(n,e.type))throw new Error(`Cannot call \'array.unshift\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);e.array.unshift(typeof n=="number"?t.precision(n):n)}}function Bh(t){return(e,n=!0)=>{let r=0,i=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,i++)}if(i===0)return NaN;let s=r/i,a=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-s)*(c-s))}let o=n?i:i-1;return o<=0?NaN:t.precision(a/o)}}var Vh=Object.defineProperty,Wh=(t,e,n)=>e in t?Vh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Q=(t,e,n)=>Wh(t,typeof e!="symbol"?e+"":e,n),G=(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))(G||{}),Y=class{constructor(e,n,r){this.array=e,this.type=n,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=Ku(this.context),this._avg=Yu(this.context),this._binary_search=Gu(this.context),this._binary_search_leftmost=Xu(this.context),this._binary_search_rightmost=Zu(this.context),this._clear=Qu(this.context),this._concat=Ju(this.context),this._copy=eh(this.context),this._covariance=th(this.context),this._every=nh(this.context),this._fill=ih(this.context),this._first=sh(this.context),this._get=ah(this.context),this._includes=oh(this.context),this._indexof=lh(this.context),this._insert=ch(this.context),this._join=uh(this.context),this._last=hh(this.context),this._lastindexof=ph(this.context),this._max=dh(this.context),this._median=fh(this.context),this._min=mh(this.context),this._mode=yh(this.context),this._percentile_linear_interpolation=gh(this.context),this._percentile_nearest_rank=xh(this.context),this._percentrank=_h(this.context),this._pop=bh(this.context),this._push=vh(this.context),this._range=wh(this.context),this._remove=Sh(this.context),this._reverse=Eh(this.context),this._set=Ch(this.context),this._shift=Ih(this.context),this._size=Nh(this.context),this._slice=kh(this.context),this._some=Ah(this.context),this._sort=Ph(this.context),this._sort_indices=Dh(this.context),this._standardize=Rh(this.context),this._stdev=Oh(this.context),this._sum=Lh(this.context),this._unshift=Fh(this.context),this._variance=Bh(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 $h(t){return(...e)=>new Y([...e],rh(e),t)}function jh(t){return(e,n)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(n===void 0){let i=r?Array(r).fill(0):[];return new Y(i,G.any,t)}return new Y(Array(r).fill(t.precision(n||0)),ft(n||0),t)}}function Uh(t){return(e=0,n=!1)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.bool,t)}}function zh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.box,t)}}function qh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.color,t)}}function Hh(t){return(e=0,n=NaN)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(t.precision(n)),G.float,t)}}function Kh(t){return(e=0,n=0)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(t.precision(n)),G.int,t)}}function Yh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.label,t)}}function Gh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.line,t)}}function Xh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.linefill,t)}}function Zh(t){return(e=0,n="")=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.string,t)}}function Qh(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),G.table,t)}}var y=class t{constructor(e,n=0){this.data=e,this.offset=n}get(e){let n=this.offset+e;Number.isInteger(n)||(n=Math.trunc(n));let r=this.data.length-1-n;return r<0||r>=this.data.length?NaN:this.data[r]}set(e,n){let r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=n)}get length(){return this.data.length}toArray(){return this.data}static from(e){return e instanceof t?e:Array.isArray(e)?new t(e):e!=null&&typeof e=="object"&&"__value"in e&&e.__value instanceof t?e.__value:new t([e])}};function Jh(t){return(e,n=0)=>y.from(e).get(n)}var rs=class{constructor(e){this.context=e,this.abs=(n,...r)=>n.abs(...r),this.avg=(n,...r)=>n.avg(...r),this.binary_search=(n,...r)=>n.binary_search(...r),this.binary_search_leftmost=(n,...r)=>n.binary_search_leftmost(...r),this.binary_search_rightmost=(n,...r)=>n.binary_search_rightmost(...r),this.clear=(n,...r)=>n.clear(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.covariance=(n,...r)=>n.covariance(...r),this.every=(n,...r)=>n.every(...r),this.fill=(n,...r)=>n.fill(...r),this.first=(n,...r)=>n.first(...r),this.from=$h(e),this.get=(n,...r)=>n.get(...r),this.includes=(n,...r)=>n.includes(...r),this.indexof=(n,...r)=>n.indexof(...r),this.insert=(n,...r)=>n.insert(...r),this.join=(n,...r)=>n.join(...r),this.last=(n,...r)=>n.last(...r),this.lastindexof=(n,...r)=>n.lastindexof(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.new=jh(e),this.new_bool=Uh(e),this.new_box=zh(e),this.new_color=qh(e),this.new_float=Hh(e),this.new_int=Kh(e),this.new_label=Yh(e),this.new_line=Gh(e),this.new_linefill=Xh(e),this.new_string=Zh(e),this.new_table=Qh(e),this.param=Jh(),this.percentile_linear_interpolation=(n,...r)=>n.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(n,...r)=>n.percentile_nearest_rank(...r),this.percentrank=(n,...r)=>n.percentrank(...r),this.pop=(n,...r)=>n.pop(...r),this.push=(n,...r)=>n.push(...r),this.range=(n,...r)=>n.range(...r),this.remove=(n,...r)=>n.remove(...r),this.reverse=(n,...r)=>n.reverse(...r),this.set=(n,...r)=>n.set(...r),this.shift=(n,...r)=>n.shift(...r),this.size=(n,...r)=>n.size(...r),this.slice=(n,...r)=>n.slice(...r),this.some=(n,...r)=>n.some(...r),this.sort=(n,...r)=>n.sort(...r),this.sort_indices=(n,...r)=>n.sort_indices(...r),this.standardize=(n,...r)=>n.standardize(...r),this.stdev=(n,...r)=>n.stdev(...r),this.sum=(n,...r)=>n.sum(...r),this.unshift=(n,...r)=>n.unshift(...r),this.variance=(n,...r)=>n.variance(...r)}};function ep(t){return e=>{e.map.clear()}}function tp(t){return(e,n)=>e.map.has(n)}function np(t){return e=>{let n=new Ur(t);return n.map=new Map(e.map),n}}function rp(t){return(e,n)=>{let r=e.map.get(n);return r===void 0?NaN:r}}function ip(t){return e=>{let n=Array.from(e.map.keys()),r=ft(n[0]);return new Y(n,r,t)}}function sp(t){return(e,n,r)=>{let i=e.map.get(n);return e.map.set(n,r),i===void 0?NaN:i}}function ap(t){return(e,n)=>{for(let[r,i]of n.map)e.map.set(r,i)}}function op(t){return(e,n)=>{let r=e.map.get(n);return e.map.delete(n)?r:NaN}}function lp(t){return e=>e.map.size}function cp(t){return e=>{let n=Array.from(e.map.values()),r=ft(n[0]);return new Y(n,r,t)}}var up=Object.defineProperty,hp=(t,e,n)=>e in t?up(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xt=(t,e,n)=>hp(t,typeof e!="symbol"?e+"":e,n),Ur=class{constructor(e){this.context=e,xt(this,"map"),xt(this,"_clear"),xt(this,"_contains"),xt(this,"_copy"),xt(this,"_get"),xt(this,"_keys"),xt(this,"_put"),xt(this,"_put_all"),xt(this,"_remove"),xt(this,"_size"),xt(this,"_values"),this.map=new Map,this._clear=ep(this.context),this._contains=tp(this.context),this._copy=np(this.context),this._get=rp(this.context),this._keys=ip(this.context),this._put=sp(this.context),this._put_all=ap(this.context),this._remove=op(this.context),this._size=lp(this.context),this._values=cp(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 pp(t){return()=>new Ur(t)}function dp(t){return(e,n=0)=>y.from(e).get(n)}var is=class{constructor(e){this.context=e,this.clear=(n,...r)=>n.clear(...r),this.contains=(n,...r)=>n.contains(...r),this.copy=(n,...r)=>n.copy(...r),this.get=(n,...r)=>n.get(...r),this.keys=(n,...r)=>n.keys(...r),this.new=pp(e),this.param=dp(),this.put=(n,...r)=>n.put(...r),this.put_all=(n,...r)=>n.put_all(...r),this.remove=(n,...r)=>n.remove(...r),this.size=(n,...r)=>n.size(...r),this.values=(n,...r)=>n.values(...r)}};function fp(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r&&(r instanceof Y?s=r.array:Array.isArray(r)?s=r:s=[r]),i===0){for(let l=0;l<s.length;l++){let c=s[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}let a=e.matrix[0].length,o=n!==void 0?n:a;for(let l=0;l<i;l++){let c=l<s.length?s[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function mp(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r)if(r instanceof Y)s=r.array;else if(Array.isArray(r))s=r;else if(r instanceof y){let c=r.get(0);Array.isArray(c)?s=c:s=[c]}else s=[r];let a=i>0?e.matrix[0].length:s.length,o=n!==void 0?n:i,l=[];for(let c=0;c<a;c++)if(c<s.length){let u=s[c];u instanceof y&&(u=u.get(0)),l.push(u)}else l.push(NaN);e.matrix.splice(o,0,l)}}function yp(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length;if(r===0)return NaN;let i=0,s=0;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(i+=l,s++)}return s===0?NaN:i/s}}function gp(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n<0||n>=i){t.warn(`Column index ${n} is out of bounds, matrix has ${i} columns.`,"matrix.col");let o=r>0?ft(e.matrix[0][0]):"float";return new Y([],o,t)}let s=[];for(let o=0;o<r;o++)s.push(e.matrix[o][n]);let a=ft(s[0]);return new Y(s,a,t)}}function xp(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function _p(t){return(e,n)=>{let r=e.matrix.length,i=n.matrix.length;if(r===0){for(let o=0;o<i;o++)e.matrix.push([...n.matrix[o]]);return}let s=e.matrix[0].length,a=i>0?n.matrix[0].length:0;if(s!==a&&i>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<i;o++)e.matrix.push([...n.matrix[o]])}}function bp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0,i=new oe(n,r,NaN,t);return i.matrix=e.matrix.map(s=>[...s]),i}}function vp(t){let e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];let n=t.map(i=>[...i]),r=1;for(let i=0;i<e;i++){let s=i;for(;s<e&&n[s][i]===0;)s++;if(s===e)return 0;s!==i&&([n[i],n[s]]=[n[s],n[i]],r*=-1),r*=n[i][i];for(let a=i+1;a<e;a++){let o=n[a][i]/n[i][i];for(let l=i;l<e;l++)n[a][l]-=o*n[i][l]}}return r}function wp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;return n!==r?NaN:vp(e.matrix)}}function Sp(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new oe(0,0,NaN,t);let i=e.matrix[0].length,s=new oe(r,i,NaN,t);if(n instanceof oe)for(let a=0;a<r;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=l-c}else{let a=n;for(let o=0;o<r;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]-a}return s}}function Ep(t){let e=t.length;if(e!==2)return Array(e).fill(NaN);let n=t[0][0],r=t[0][1],i=t[1][0],s=t[1][1],a=n+s,o=n*s-r*i,l=a*a-4*o;if(l<0)return[NaN,NaN];let c=(a+Math.sqrt(l))/2,u=(a-Math.sqrt(l))/2;return[c,u]}function Cp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r){let a=ft(e.matrix[0][0]);return new Y([],a,t)}let i=Ep(e.matrix),s=ft(i[0]);return new Y(i,s,t)}}function Ip(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new oe(0,0,NaN,t);let i=new oe(n,r,0,t);for(let s=0;s<n;s++)i.matrix[s][s]=1;return i}}function Np(t){return e=>{let n=e.matrix.length;return n===0?0:n*e.matrix[0].length}}function kp(t){return(e,n,r,i,s,a)=>{let o=e.matrix.length;if(o===0)return;let l=e.matrix[0].length,c=r!==void 0?r:0,u=i!==void 0?i:o,p=s!==void 0?s:0,h=a!==void 0?a:l;for(let d=c;d<u&&!(d>=o);d++)for(let f=p;f<h&&!(f>=l);f++)e.matrix[d][f]=n}}function Ap(t){return(e,n,r)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0;if(n<0||n>=i)return t.warn(`Row index ${n} is out of bounds, matrix has ${i} 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;let a=e.matrix[n][r];return a===void 0?NaN:a}}function Fr(t){let e=t.length;if(e===0)return[];let n=new Array(e);for(let i=0;i<e;i++){n[i]=new Array(2*e);for(let s=0;s<e;s++)n[i][s]=t[i][s];for(let s=0;s<e;s++)n[i][e+s]=i===s?1:0}for(let i=0;i<e;i++){let s=Math.abs(n[i][i]),a=i;for(let l=i+1;l<e;l++){let c=Math.abs(n[l][i]);c>s&&(s=c,a=l)}if(s<1e-14)return t.map(l=>l.map(()=>NaN));if(a!==i){let l=n[i];n[i]=n[a],n[a]=l}let o=n[i][i];for(let l=i;l<2*e;l++)n[i][l]/=o;for(let l=0;l<e;l++){if(l===i)continue;let c=n[l][i];if(c!==0)for(let u=i;u<2*e;u++)n[l][u]-=c*n[i][u]}}let r=new Array(e);for(let i=0;i<e;i++){r[i]=new Array(e);for(let s=0;s<e;s++)r[i][s]=n[i][e+s]}return r}function Mp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new oe(n,r,NaN,t);let i=Fr(e.matrix),s=new oe(n,r,NaN,t);return s.matrix=i,s}}function Tp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i+s!==n-1&&e.matrix[i][s]!==0)return!1;return!0}}function Pp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(e.matrix[s][i]!==-e.matrix[i][s])return!1;return!0}}function Dp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++){let a=e.matrix[i][s];if(a!==0&&a!==1)return!1}return!0}}function Rp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i!==s&&e.matrix[i][s]!==0)return!1;return!0}}function Op(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i===s){if(e.matrix[i][s]!==1)return!1}else if(e.matrix[i][s]!==0)return!1;return!0}}function Lp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;return n===r}}function Fp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;for(let i=0;i<n;i++){let s=0;for(let a=0;a<r;a++){let o=e.matrix[i][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Bp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<i;s++)if(e.matrix[i][s]!==e.matrix[s][i])return!1;return!0}}function Vp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;let i=!0,s=!0;for(let a=0;a<n;a++)for(let o=0;o<r;o++)a>o&&e.matrix[a][o]!==0&&(i=!1),a<o&&e.matrix[a][o]!==0&&(s=!1);return i||s}}function Wp(t){return e=>{let n=e.matrix.length;if(n===0)return!0;let r=e.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(e.matrix[i][s]!==0)return!1;return!0}}function $p(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0,s=n.matrix.length,a=s>0?n.matrix[0].length:0,o=r*s,l=i*a,c=new oe(o,l,NaN,t);for(let u=0;u<r;u++)for(let p=0;p<i;p++){let h=e.matrix[u][p];for(let d=0;d<s;d++)for(let f=0;f<a;f++){let m=n.matrix[d][f];c.matrix[u*s+d][p*a+f]=h*m}}return c}}function jp(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=-1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(l>i&&(i=l),s=!0)}return s?i:NaN}}function Up(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=[];for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||i.push(l)}if(i.length===0)return NaN;i.sort((a,o)=>a-o);let s=Math.floor(i.length/2);return i.length%2!==0?i[s]:(i[s-1]+i[s])/2}}function zp(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(l<i&&(i=l),s=!0)}return s?i:NaN}}function qp(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=new Map,s=0,a=NaN;for(let o=0;o<n;o++)for(let l=0;l<r;l++){let c=e.matrix[o][l];if(!isNaN(c)){let u=(i.get(c)||0)+1;i.set(c,u),u>s?(s=u,a=c):u===s&&c<a&&(a=c)}}return a}}function Hp(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n instanceof oe){let s=n.matrix.length,a=s>0?n.matrix[0].length:0;if(i!==s)return new oe(0,0,NaN,t);let o=new oe(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<i;p++)u+=e.matrix[l][p]*n.matrix[p][c];o.matrix[l][c]=u}return o}else if(n instanceof Y||Array.isArray(n.array||n)){let s=n.array||n;if(i!==s.length)return new Y([],"float",t);let a=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<i;c++)l+=e.matrix[o][c]*s[c];a.push(l)}return new Y(a,"float",t)}else{let s=n,a=new oe(r,i,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<i;l++)a.matrix[o][l]=e.matrix[o][l]*s;return a}}}function Kp(t){return e=>{let n=e.matrix.length;if(n===0)return new oe(0,0,NaN,t);let r=e.matrix[0].length;if(n===r){let u=Fr(e.matrix),p=new oe(n,r,NaN,t);return p.matrix=u,p}let i=u=>{let p=u.length,h=u[0].length,d=new Array(h);for(let f=0;f<h;f++){d[f]=new Array(p);for(let m=0;m<p;m++)d[f][m]=u[m][f]}return d},s=(u,p)=>{let h=u.length,d=u[0].length,f=p[0].length,m=new Array(h);for(let _=0;_<h;_++){m[_]=new Array(f).fill(0);for(let b=0;b<d;b++){let v=u[_][b];if(v!==0)for(let S=0;S<f;S++)m[_][S]+=v*p[b][S]}}return m},a=e.matrix,o=i(a),l;if(n>r){let u=s(o,a),p=Fr(u);l=s(p,o)}else{let u=s(a,o),p=Fr(u);l=s(o,p)}let c=new oe(r,n,NaN,t);return c.matrix=l,c}}function Yp(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(r!==i)return new oe(0,0,NaN,t);let s=new oe(r,i,0,t);for(let l=0;l<r;l++)s.matrix[l][l]=1;let a=new oe(r,i,NaN,t);for(let l=0;l<r;l++)a.matrix[l]=[...e.matrix[l]];let o=Math.floor(n);if(o<0)return new oe(r,i,NaN,t);for(;o>0;){if(o%2===1){let c=new oe(r,i,0,t);for(let u=0;u<r;u++)for(let p=0;p<i;p++){let h=0;for(let d=0;d<r;d++)h+=s.matrix[u][d]*a.matrix[d][p];c.matrix[u][p]=h}s=c}let l=new oe(r,i,0,t);for(let c=0;c<r;c++)for(let u=0;u<i;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 Gp(t){return e=>{let n=e.matrix.length;if(n===0)return 0;let r=e.matrix[0].length,i=e.matrix.map(a=>[...a]),s=0;for(let a=0;a<r&&s<n;a++){let o=s;for(;o<n&&Math.abs(i[o][a])<1e-10;)o++;if(o<n){[i[s],i[o]]=[i[o],i[s]];let l=i[s][a];for(let c=a;c<r;c++)i[s][c]/=l;for(let c=0;c<n;c++)if(c!==s){let u=i[c][a];for(let p=a;p<r;p++)i[c][p]-=u*i[s][p]}s++}}return s}}function Xp(t){return(e,n)=>{let r=e.matrix.length;if(r===0){let a=ft(e.matrix[0][0]);return new Y([],a,t)}let i=[];for(let a=0;a<r;a++){let o=e.matrix[a].splice(n,1);i.push(o[0])}let s=ft(i[0]);return new Y(i,s,t)}}function Zp(t){return(e,n)=>{let r=e.matrix.splice(n,1),i=ft(r[0][0]);return new Y(r[0]||[],i,t)}}function Qp(t){return(e,n,r)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0,a=n*r,o=[];for(let u=0;u<i;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);let l=[],c=0;for(let u=0;u<n;u++){let p=[];for(let h=0;h<r;h++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Jp(t){return e=>{e.matrix.reverse();for(let n of e.matrix)n.reverse()}}function ed(t){return(e,n)=>{let r=e.matrix.length;if(n<0||n>=r){t.warn(`Row index ${n} is out of bounds, matrix has ${r} rows.`,"matrix.row");let s=r>0?ft(e.matrix[0][0]):"float";return new Y([],s,t)}let i=ft(e.matrix[n][0]);return new Y([...e.matrix[n]],i,t)}}function td(t){return e=>e.matrix.length}function nd(t){return(e,n,r,i)=>{let s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(n<0||n>=s){t.warn(`Row index ${n} 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[n][r]=i}}function rd(t){return(e,n=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((i,s)=>{let a=i[n],o=s[n];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function id(t){return(e,n,r,i,s)=>{let a=r-n,o=s-i,l=new oe(a,o,NaN,t);for(let c=0;c<a;c++){let u=n+c;if(u>=e.matrix.length)break;for(let p=0;p<o;p++){let h=i+p;if(h>=e.matrix[u].length)break;l.matrix[c][p]=e.matrix[u][h]}}return l}}function sd(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new oe(0,0,NaN,t);let i=e.matrix[0].length,s=new oe(r,i,NaN,t);if(n instanceof oe)for(let a=0;a<r;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=l+c}else{let a=n;for(let o=0;o<r;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]+a}return s}}function ad(t){return(e,n,r)=>{let i=e.matrix.length;for(let s=0;s<i;s++){let a=e.matrix[s][n];e.matrix[s][n]=e.matrix[s][r],e.matrix[s][r]=a}}}function od(t){return(e,n,r)=>{let i=e.matrix[n];e.matrix[n]=e.matrix[r],e.matrix[r]=i}}function ld(t){return e=>{let n=e.matrix.length;if(n===0)return 0;let r=e.matrix[0].length,i=Math.min(n,r),s=0;for(let a=0;a<i;a++)s+=e.matrix[a][a];return s}}function cd(t){return e=>{let n=e.matrix.length;if(n===0)return new oe(0,0,NaN,t);let r=e.matrix[0].length,i=new oe(r,n,NaN,t);for(let s=0;s<n;s++)for(let a=0;a<r;a++)i.matrix[a][s]=e.matrix[s][a];return i}}var ud=Object.defineProperty,hd=(t,e,n)=>e in t?ud(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e,n)=>hd(t,typeof e!="symbol"?e+"":e,n),oe=class{constructor(e=0,n=0,r=NaN,i){if(this.context=i,H(this,"matrix"),H(this,"_add_col"),H(this,"_add_row"),H(this,"_avg"),H(this,"_col"),H(this,"_columns"),H(this,"_concat"),H(this,"_copy"),H(this,"_det"),H(this,"_diff"),H(this,"_eigenvalues"),H(this,"_eigenvectors"),H(this,"_elements_count"),H(this,"_fill"),H(this,"_get"),H(this,"_inv"),H(this,"_is_antidiagonal"),H(this,"_is_antisymmetric"),H(this,"_is_binary"),H(this,"_is_diagonal"),H(this,"_is_identity"),H(this,"_is_square"),H(this,"_is_stochastic"),H(this,"_is_symmetric"),H(this,"_is_triangular"),H(this,"_is_zero"),H(this,"_kron"),H(this,"_max"),H(this,"_median"),H(this,"_min"),H(this,"_mode"),H(this,"_mult"),H(this,"_pinv"),H(this,"_pow"),H(this,"_rank"),H(this,"_remove_col"),H(this,"_remove_row"),H(this,"_reshape"),H(this,"_reverse"),H(this,"_row"),H(this,"_rows"),H(this,"_set"),H(this,"_sort"),H(this,"_submatrix"),H(this,"_sum"),H(this,"_swap_columns"),H(this,"_swap_rows"),H(this,"_trace"),H(this,"_transpose"),this.matrix=[],e>0&&n>0)for(let s=0;s<e;s++)this.matrix.push(Array(n).fill(r));this._add_col=fp(this.context),this._add_row=mp(this.context),this._avg=yp(this.context),this._col=gp(this.context),this._columns=xp(this.context),this._concat=_p(this.context),this._copy=bp(this.context),this._det=wp(this.context),this._diff=Sp(this.context),this._eigenvalues=Cp(this.context),this._eigenvectors=Ip(this.context),this._elements_count=Np(this.context),this._fill=kp(this.context),this._get=Ap(this.context),this._inv=Mp(this.context),this._is_antidiagonal=Tp(this.context),this._is_antisymmetric=Pp(this.context),this._is_binary=Dp(this.context),this._is_diagonal=Rp(this.context),this._is_identity=Op(this.context),this._is_square=Lp(this.context),this._is_stochastic=Fp(this.context),this._is_symmetric=Bp(this.context),this._is_triangular=Vp(this.context),this._is_zero=Wp(this.context),this._kron=$p(this.context),this._max=jp(this.context),this._median=Up(this.context),this._min=zp(this.context),this._mode=qp(this.context),this._mult=Hp(this.context),this._pinv=Kp(this.context),this._pow=Yp(this.context),this._rank=Gp(this.context),this._remove_col=Xp(this.context),this._remove_row=Zp(this.context),this._reshape=Qp(this.context),this._reverse=Jp(this.context),this._row=ed(this.context),this._rows=td(this.context),this._set=nd(this.context),this._sort=rd(this.context),this._submatrix=id(this.context),this._sum=sd(this.context),this._swap_columns=ad(this.context),this._swap_rows=od(this.context),this._trace=ld(this.context),this._transpose=cd(this.context)}toString(){let e="";for(let n=0;n<this.matrix.length;n++)e+=e===""?"":`\n`,e+="["+this.matrix[n].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 _t(t){return(e,n,r)=>new oe(e,n,r,t)}function pd(t){return(e,n=0)=>y.from(e).get(n)}var ss=class{constructor(e){this.context=e,this.add_col=(n,...r)=>n.add_col(...r),this.add_row=(n,...r)=>n.add_row(...r),this.avg=(n,...r)=>n.avg(...r),this.col=(n,...r)=>n.col(...r),this.columns=(n,...r)=>n.columns(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.det=(n,...r)=>n.det(...r),this.diff=(n,...r)=>n.diff(...r),this.eigenvalues=(n,...r)=>n.eigenvalues(...r),this.eigenvectors=(n,...r)=>n.eigenvectors(...r),this.elements_count=(n,...r)=>n.elements_count(...r),this.fill=(n,...r)=>n.fill(...r),this.get=(n,...r)=>n.get(...r),this.inv=(n,...r)=>n.inv(...r),this.is_antidiagonal=(n,...r)=>n.is_antidiagonal(...r),this.is_antisymmetric=(n,...r)=>n.is_antisymmetric(...r),this.is_binary=(n,...r)=>n.is_binary(...r),this.is_diagonal=(n,...r)=>n.is_diagonal(...r),this.is_identity=(n,...r)=>n.is_identity(...r),this.is_square=(n,...r)=>n.is_square(...r),this.is_stochastic=(n,...r)=>n.is_stochastic(...r),this.is_symmetric=(n,...r)=>n.is_symmetric(...r),this.is_triangular=(n,...r)=>n.is_triangular(...r),this.is_zero=(n,...r)=>n.is_zero(...r),this.kron=(n,...r)=>n.kron(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.mult=(n,...r)=>n.mult(...r),this.new=_t(e),this.param=pd(),this.pinv=(n,...r)=>n.pinv(...r),this.pow=(n,...r)=>n.pow(...r),this.rank=(n,...r)=>n.rank(...r),this.remove_col=(n,...r)=>n.remove_col(...r),this.remove_row=(n,...r)=>n.remove_row(...r),this.reshape=(n,...r)=>n.reshape(...r),this.reverse=(n,...r)=>n.reverse(...r),this.row=(n,...r)=>n.row(...r),this.rows=(n,...r)=>n.rows(...r),this.set=(n,...r)=>n.set(...r),this.sort=(n,...r)=>n.sort(...r),this.submatrix=(n,...r)=>n.submatrix(...r),this.sum=(n,...r)=>n.sum(...r),this.swap_columns=(n,...r)=>n.swap_columns(...r),this.swap_rows=(n,...r)=>n.swap_rows(...r),this.trace=(n,...r)=>n.trace(...r),this.transpose=(n,...r)=>n.transpose(...r),this.new_float=_t(e),this.new_int=_t(e),this.new_string=_t(e),this.new_bool=_t(e),this.new_color=_t(e),this.new_line=_t(e),this.new_label=_t(e),this.new_box=_t(e),this.new_linefill=_t(e),this.new_table=_t(e)}},dd=Object.defineProperty,fd=(t,e,n)=>e in t?dd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,md=(t,e,n)=>fd(t,typeof e!="symbol"?e+"":e,n),as=class{constructor(e){this.context=e,md(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){let e=this.context.idx,n=this.context.length;if(e===n-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===n-2){let r=this.context.marketData?.[n-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}},yd=Object.defineProperty,gd=(t,e,n)=>e in t?yd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hi=(t,e,n)=>gd(t,typeof e!="symbol"?e+"":e,n),qe=class t{constructor(e,n,r){Hi(this,"time"),Hi(this,"index"),Hi(this,"price"),this.time=e,this.index=n,this.price=r}copy(){return new t(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}};function xd(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}var eo={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 qe,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 qe)&&!xd(t)};function St(t){let e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function ye(t,e,n,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);let i={},s={},a=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){let l=t[o];if(eo.remaining_options(l)){s=l;break}let c=e.map((u,p)=>a[p]?u[o]:void 0);for(let u=0;u<c.length;u++){let p=c[u];if(p===void 0){a[u]=!1;continue}let h=n[p];if(typeof l=="number"&&isNaN(l)&&(h==="number"||h==="series"))i[p]=l;else{let d=eo[n[p]];typeof d=="function"&&d(l)?i[p]=l:a[u]=!1}}}return{...i,...s,...r}}var _d=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/;function bd(t){if(typeof t!="string")return null;let e=t.trim();if(!e)return null;if(e==="24x7")return{windows:[{start:0,end:1440}],days:new Set([1,2,3,4,5,6,7])};let n=e.split(":");if(n.length>2)return null;let r=new Set;if(n.length===2){if(!/^[1-7]+$/.test(n[1]))return null;for(let s of n[1])r.add(parseInt(s,10))}else for(let s=1;s<=7;s++)r.add(s);let i=[];for(let s of n[0].split(",")){let a=s.match(_d);if(!a)return null;let o=parseInt(a[1],10),l=parseInt(a[2],10),c=parseInt(a[3],10),u=parseInt(a[4],10);if(o>23||l>59||c>23||u>59)return null;let p=o*60+l,h=c===0&&u===0?1440:c*60+u;i.push({start:p,end:h})}return{windows:i,days:r}}function vd(t,e,n){let r=n+1,i=r%7+1;for(let{start:s,end:a}of t.windows)if(s<a){if(e>=s&&e<a&&t.days.has(r))return!0}else if(e>=s&&t.days.has(i)||e<a&&t.days.has(r))return!0;return!1}var wd=Object.defineProperty,Sd=(t,e,n)=>e in t?wd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ed=(t,e,n)=>Sd(t,typeof e!="symbol"?e+"":e,n),zr=class extends Error{constructor(e,n){super(e),Ed(this,"method"),this.name="PineRuntimeError",this.method=n}},Cd=Object.defineProperty,Id=(t,e,n)=>e in t?Cd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qr=(t,e,n)=>Id(t,typeof e!="symbol"?e+"":e,n);function os(t){if(!t)return"";let e=t.trim().toUpperCase();return e==="1D"||e==="D"?"D":e==="1W"||e==="W"?"W":e==="1M"||e==="M"?"M":e}function ls(t,e){let n=Nd(e);if(e==="M"){let o=new Date(t);return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),1)}if(e==="W"){let o=new Date(t),l=o.getUTCDay(),c=l===0?6:l-1;return Date.UTC(o.getUTCFullYear(),o.getUTCMonth(),o.getUTCDate()-c)}if(e==="D"||n>=1440)return Math.floor(t/864e5)*864e5;let r=n*6e4,i=Math.floor(t/864e5)*864e5,s=t-i,a=Math.floor(s/r)*r;return i+a}function Nd(t){if(t==="D")return 1440;if(t==="W")return 10080;if(t==="M")return 43200;let e=parseInt(t,10);return isNaN(e)?1440:e}function rn(t,e){let n=e.trim();if(n==="UTC"||n==="GMT"||n==="Etc/UTC"){let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}let r=n.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(r){let i=r[1]==="+"?1:-1,s=parseInt(r[2],10),a=parseInt(r[3]||"0",10),o=i*(s*60+a)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),s=c=>parseInt(i.find(u=>u.type===c)?.value||"0",10),a=s("hour");a===24&&(a=0);let o=i.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:s("year"),month:s("month"),day:s("day"),hour:a,minute:s("minute"),second:s("second"),dayOfWeek:l[o]??0}}catch{let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}}function kd(t,e,n){let r=new Date(Date.UTC(t,e-1,n)),i=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-i);let s=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-s.getTime())/864e5+1)/7)}var Ad=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Md={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},Hr=class{constructor(e,n="openTime"){qr(this,"context"),qr(this,"dataField"),this.context=e,this.dataField=n}get __value(){return this.context.data[this.dataField]}param(e,n=0){return y.from(e).get(n)}any(...e){let n=e.map(h=>h instanceof y?h.get(0):h),r=ye(n,Ad,Md),i=r.bars_back??0,s=r.timeframe||"",a=this.context.data[this.dataField],o=y.from(a).get(i);if(isNaN(o)||o==null)return NaN;let l=this.context.timeframe||"",c=os(s),u=os(l),p;if(!c||c===u?p=o:p=ls(o,c),r.session!==void 0&&r.session!==""){let h=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(p,r.session,h)?p:NaN}return p}_isInSession(e,n,r){let i=bd(n);if(!i)throw new zr(`Invalid session specification: "${n}"`,"time");let s=rn(e,r),a=s.hour*60+s.minute;return vd(i,a,s.dayOfWeek)}},Td=[[],["time"],["time","timezone"]],Pd={time:"number",timezone:"string"},Dt=class{constructor(e,n){qr(this,"context"),qr(this,"extractor"),this.context=e,this.extractor=n}get __value(){let e=y.from(this.context.data.openTime).get(0);if(isNaN(e))return NaN;let n=this.context.pine?.syminfo?.timezone||"UTC",r=rn(e,n);return this.extractor(r)}param(e,n=0){return y.from(e).get(n)}any(...e){let n=e.map(o=>o instanceof y?o.get(0):o);if(n.length===0)return this.__value;let r=ye(n,Td,Pd),i=r.time;if(i===void 0||isNaN(i))return NaN;let s=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=rn(i,s);return this.extractor(a)}},Qt={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=>kd(t.year,t.month,t.day),year:t=>t.year},Dd=Object.defineProperty,Rd=(t,e,n)=>e in t?Dd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,to=(t,e,n)=>Rd(t,typeof e!="symbol"?e+"":e,n),cs=class{constructor(e){this.context=e,to(this,"regular","regular"),to(this,"extended","extended")}get _timezone(){return this.context.pine?.syminfo?.timezone||"UTC"}_dayKey(e){let n=rn(e,this._timezone);return`${n.year}-${n.month}-${n.day}`}get isfirstbar(){let e=this.context.idx,n=this.context.marketData;return!Array.isArray(n)||!n[e]?!1:e===0?!0:this._dayKey(n[e].openTime)!==this._dayKey(n[e-1].openTime)}get islastbar(){let e=this.context.idx,n=this.context.marketData;return!Array.isArray(n)||!n[e]?!1:e===n.length-1?!0:this._dayKey(n[e].openTime)!==this._dayKey(n[e+1].openTime)}get isfirstbar_regular(){return this.isfirstbar}get islastbar_regular(){return this.islastbar}get ismarket(){return!0}get ispremarket(){return!1}get ispostmarket(){return!1}},Od=Object.defineProperty,Ld=(t,e,n)=>e in t?Od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fd=(t,e,n)=>Ld(t,typeof e!="symbol"?e+"":e,n),en=class t{constructor(e,n,r){this._definition=e,this.context=n,Fd(this,"_udt");for(let i in e)this[i]=e[i];this._udt=r}get __def__(){return this._definition}copy(){return new t(this.__def__,this.context,this._udt)}toString(){let e={};for(let n in this.__def__){let r=this[n];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[n]=r.toString():e[n]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(n=>`"${n}":${String(e[n])}`).join(",")+"}"}}};function M(t,e,n){let r=n.value;return typeof r!="function"||(n.value=function(...i){return this&&this.context&&this.context.isSecondaryContext?null:r.apply(this,i)}),n}var il=Object.defineProperty,Bd=Object.getOwnPropertyDescriptor,Vd=(t,e,n)=>e in t?il(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,sl=(t,e,n,r)=>{for(var i=r>1?void 0:r?Bd(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&il(e,n,i),i},Fn=(t,e,n)=>Vd(t,typeof e!="symbol"?e+"":e,n),Wd=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],$d={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},jd=["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"],Ud={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 zd(t){return ye(t,jd,Ud)}var at=class t{get __value(){return NaN}param(e,n=0){return y.from(e).get(n)}any(e){if(e instanceof t)return!0;let n=y.from(e).get(0);return n instanceof t||n==null?!0:typeof n=="number"?n!==n:!1}},An={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"},Kr=class{constructor(e){this.context=e,Fn(this,"_firedKeys",new Set),Fn(this,"_fallbackCounter",0),Fn(this,"_fallbackLastExecTick",-1)}get freq_all(){return An.freq_all}get freq_once_per_bar(){return An.freq_once_per_bar}get freq_once_per_bar_close(){return An.freq_once_per_bar_close}param(e,n,r){return y.from(e).get(0)}any(e,n,r){let i=y.from(e).get(0),s=n?y.from(n).get(0):An.freq_once_per_bar,a;if(r&&typeof r=="object"&&r.__callsiteId)a=r.__callsiteId;else{let u=this.context._execTick||0;u!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=u),a=`alert_${this._fallbackCounter++}`}let o=this.context.idx,l=this.context.pine?.barstate?.isrealtime??o===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${a}:${o}`;if(s===An.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===An.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(c))return;this._firedKeys.add(c)}this.context.alerts.push({type:"alert",id:a,message:i,freq:s,bar_index:o,time:this.context.data.openTime?.data?.[o]??0})}};sl([M],Kr.prototype,"any",1);var Yr=class{constructor(e){this.context=e,Fn(this,"_acCounter",0),Fn(this,"_acLastExecTick",-1),Fn(this,"_acFiredKeys",new Set)}extractPlotOptions(e){let n={};for(let r in e)n[r]=y.from(e[r]).get(0);return n}indicator(...e){let n=e.map(s=>s instanceof y?s.get(0):s),r=zd(n),i={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...i,...r,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){let n=y.from(e).get(0);return n==null||typeof n=="number"&&isNaN(n)}nz(e,n=0){let r=y.from(e).get(0),i=y.from(n).get(0);return r==null||typeof r=="number"&&isNaN(r)?i:r}fixnan(e){let n=y.from(e);for(let r=0;r<n.length;r++){let i=n.get(r);if(!isNaN(i))return i}return NaN}alertcondition(e,n,r){let i=y.from(e).get(0),s=this.context.idx,a=this.context._execTick||0;a!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=a);let o=`alertcondition_${this._acCounter++}`;if(!i)return;let l=this.context.pine?.barstate?.isrealtime??s===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${o}:${s}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);let u=n?y.from(n).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,n){}timestamp(...e){let n=e.map(i=>i instanceof y?i.get(0):i),r=ye(n,Wd,$d);if(r.year!==void 0){let i=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,i,s,a,o,l,c)}if(r.dateString!==void 0){let i=r.dateString.trim();if(/[Zz]$/.test(i)||/[+-]\\d{2}:?\\d{2}$/.test(i))return new Date(i).getTime();let s=i.includes("T")?i+"Z":i.replace(/\\s+/,"T")+"Z",a=new Date(s);if(!isNaN(a.getTime())){let o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,a.getUTCFullYear(),a.getUTCMonth()+1,a.getUTCDate(),a.getUTCHours(),a.getUTCMinutes(),a.getUTCSeconds())}return new Date(i).getTime()}return NaN}_timestampFromComponents(e,n,r,i,s,a,o){let l=new Date(Date.UTC(n,r-1,i,s,a,o));n>=0&&n<100&&l.setUTCFullYear(n);let c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();let u=c.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(u){let p=u[1]==="+"?1:-1,h=parseInt(u[2],10),d=parseInt(u[3]||"0",10),f=p*(h*60+d)*60*1e3;return l.getTime()-f}try{return this._timestampFromIANA(e,n,r,i,s,a,o)}catch{return l.getTime()}}_timestampFromIANA(e,n,r,i,s,a,o){let l=new Date(Date.UTC(n,r-1,i,s,a,o));n>=0&&n<100&&l.setUTCFullYear(n);let c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),u=S=>parseInt(c.find(w=>w.type===S)?.value||"0",10),p=u("year"),h=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),_=u("second"),b=new Date(Date.UTC(p,h-1,d,f,m,_));p>=0&&p<100&&b.setUTCFullYear(p);let v=b.getTime()-l.getTime();return l.getTime()-v}bool(e){let n=y.from(e).get(0);return!isNaN(n)&&n!==0}int(e){let n=y.from(e).get(0);if(typeof n!="number")throw new Error(`Cannot call "int" with argument "x"="${n}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(n)}float(e){let n=y.from(e).get(0);if(typeof n!="number")throw new Error(`Cannot call "float" with argument "x"="${n}". An argument of "literal string" type was used but a "const float" is expected.`);return n}string(e){return y.from(e).get(0).toString()}Type(e){let n=Object.keys(e),r={};for(let s of n){let a=e[s];a instanceof y&&(a=a.data),Array.isArray(a)&&(a[0],r[s]=a[1])}let i={new:function(...s){let a={},o=null;if(s.length>0){let l=s[s.length-1];if(l&&typeof l=="object"&&!(l instanceof y)&&!Array.isArray(l)&&!(l instanceof en)){let c=Object.keys(l);c.length>0&&c.some(u=>n.includes(u))&&(o=l,s=s.slice(0,-1))}}for(let l=0;l<n.length;l++){let c=n[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 en(a,this.context,i)},copy:function(s){return new en(s.__def__,this.context,i)},_fieldDefaults:r,_definitionKeys:n};return i}};sl([M],Yr.prototype,"alertcondition",1);function hn(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){let n=t.slice(1);return n.length===6?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),1]:n.length===8?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),parseInt(n.slice(6,8),16)/255]:null}let e=t.match(/rgba?\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\s*\\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function qd(t,e,n,r){let i=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,n))).toString(16).padStart(2,"0");if(r>=1)return`#${i}${s}${a}`.toUpperCase();let o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${i}${s}${a}${o}`.toUpperCase()}var Ce={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 al(t){if(typeof t!="string")return null;let e=t.trim(),n=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(Ce,n)&&(e=Ce[n]),hn(e)}function us(t,e,n,r){let i=s=>Math.round(Math.max(0,Math.min(255,s))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(n)}${i(r*255)}`.toUpperCase()}function Hd(t){let e=al(t);return e?us(e[0],e[1],e[2],e[3]):t}function Tt(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}var hs=class{constructor(e){this.context=e}any(e){let n=y.from(e).get(0);return typeof n=="number"&&isNaN(n)?null:n}param(e,n=0){return y.from(e).get(n)}new(e,n){if(e=Tt(e),!e||typeof e!="string")return e;if(typeof n=="number"&&isNaN(n)&&(n=void 0),e.startsWith("#")){let r=e.slice(1),i=r.length===8?r.slice(0,6):r;return n!=null?`#${i}${Math.round(255/100*(100-n)).toString(16).padStart(2,"0").toUpperCase()}`:`#${r}`}else{let r=Ce[e];if(r)return n!=null?`#${r.slice(1)}${Math.round(255/100*(100-n)).toString(16).padStart(2,"0").toUpperCase()}`:r;let i=e.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([\\d.]+))?\\s*\\)/);if(i){let s=i[1],a=i[2],o=i[3];if(n!=null){let l=parseInt(s).toString(16).padStart(2,"0"),c=parseInt(a).toString(16).padStart(2,"0"),u=parseInt(o).toString(16).padStart(2,"0"),p=Math.round(255/100*(100-n)).toString(16).padStart(2,"0").toUpperCase();return`#${l}${c}${u}${p}`}return e}return n!=null?`rgba(${e}, ${(100-n)/100})`:e}}rgb(e,n,r,i){return typeof i=="number"&&isNaN(i)&&(i=void 0),i!=null?`rgba(${e}, ${n}, ${r}, ${(100-i)/100})`:`rgb(${e}, ${n}, ${r})`}from_gradient(e,n,r,i,s){if(e=Tt(e),n=Tt(n),r=Tt(r),i=Tt(i),s=Tt(s),e==null||typeof e=="number"&&isNaN(e)||n==null||typeof n=="number"&&isNaN(n)||r==null||typeof r=="number"&&isNaN(r)||i==null||typeof i=="number"&&isNaN(i)||s==null||typeof s=="number"&&isNaN(s))return;let a=0;r!==n&&(a=(e-n)/(r-n)),a=Math.max(0,Math.min(1,a));let o=hn(typeof i=="string"?i:"#000000")||[0,0,0,1],l=hn(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 qd(c,u,p,h)}r(e){if(e=Tt(e),!e||typeof e!="string")return NaN;let n=hn(e);return n?n[0]:NaN}g(e){if(e=Tt(e),!e||typeof e!="string")return NaN;let n=hn(e);return n?n[1]:NaN}b(e){if(e=Tt(e),!e||typeof e!="string")return NaN;let n=hn(e);return n?n[2]:NaN}t(e){if(e=Tt(e),!e||typeof e!="string")return NaN;let n=hn(e);return n?Math.round(100-n[3]*100):NaN}aqua(){return Ce.aqua}black(){return Ce.black}blue(){return Ce.blue}fuchsia(){return Ce.fuchsia}gray(){return Ce.gray}green(){return Ce.green}lime(){return Ce.lime}maroon(){return Ce.maroon}navy(){return Ce.navy}olive(){return Ce.olive}orange(){return Ce.orange}purple(){return Ce.purple}red(){return Ce.red}silver(){return Ce.silver}teal(){return Ce.teal}white(){return Ce.white}yellow(){return Ce.yellow}},ra=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]);function ol(t,e){if(!ra.has(e))return;let n=t?.data?.[e];if(n!=null)return y.from(n).get(0)}var Kd=[["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"]],Yd={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function et(t){let e,n=t[t.length-1];n&&typeof n=="object"&&Object.prototype.hasOwnProperty.call(n,"__varId")&&(e=n.__varId,t=t.slice(0,-1));let r=ye(t,Kd,Yd);return e!==void 0&&(r.__varId=e),r}function ot(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 Gd(t){return(...e)=>{let n=et(e),r=ot(t,n);if(typeof r=="string"&&typeof n.defval=="number"){let i=ol(t,r);if(i!==void 0)return i}return r}}function Xd(t){return(...e)=>{let n=et(e);return ot(t,n)}}function Zd(t){return(...e)=>{let n=et(e);return ot(t,n)}}function Qd(t){return(...e)=>{let n=et(e);return ot(t,n)}}function Jd(t){return(...e)=>{let n=et(e);return ot(t,n)}}function ef(t){return(...e)=>{let n=et(e);return ot(t,n)}}function tf(t){return(e,n=0)=>y.from(e).get(n)}function nf(t){return(...e)=>{let n=et(e);return ot(t,n)}}function rf(t){return(...e)=>{let n=et(e);return ot(t,n)}}function sf(t){return(...e)=>{let n=et(e),r=ot(t,n);if(typeof r=="string"){let i=ol(t,r);return i!==void 0?i:n.defval}return r}}function af(t){return(...e)=>{let n=et(e);return ot(t,n)}}function of(t){return(...e)=>{let n=et(e);return ot(t,n)}}function lf(t){return(...e)=>{let n=et(e);return ot(t,n)}}function cf(t){return(...e)=>{let n=et(e);return ot(t,n)}}function uf(t){return(...e)=>et(e).defval}var hf=Object.defineProperty,pf=(t,e,n)=>e in t?hf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ue=(t,e,n)=>pf(t,typeof e!="symbol"?e+"":e,n),df={any:Gd,bool:Xd,color:Zd,enum:Qd,float:Jd,int:ef,param:tf,price:nf,session:rf,source:sf,string:af,symbol:of,text_area:lf,time:cf,timeframe:uf},ps=class{constructor(e){this.context=e,Ue(this,"any"),Ue(this,"bool"),Ue(this,"color"),Ue(this,"enum"),Ue(this,"float"),Ue(this,"int"),Ue(this,"param"),Ue(this,"price"),Ue(this,"session"),Ue(this,"source"),Ue(this,"string"),Ue(this,"symbol"),Ue(this,"text_area"),Ue(this,"time"),Ue(this,"timeframe"),Object.entries(df).forEach(([n,r])=>{this[n]=r(e)})}};function ff(t){return e=>Math.abs(y.from(e).get(0))}function mf(t){return e=>Math.acos(y.from(e).get(0))}function yf(t){return e=>Math.asin(y.from(e).get(0))}function gf(t){return e=>Math.atan(y.from(e).get(0))}function xf(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function _f(t){return e=>Math.ceil(y.from(e).get(0))}function bf(t){return e=>Math.cos(y.from(e).get(0))}function vf(t){return()=>Math.E}function wf(t){return e=>Math.exp(y.from(e).get(0))}function Sf(t){return e=>Math.floor(y.from(e).get(0))}function Ef(t){return e=>Math.log(y.from(e).get(0))}function Cf(t){return e=>Math.log(y.from(e).get(0))}function If(t){return e=>Math.log10(y.from(e).get(0))}function Nf(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.max(...n)}}function kf(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.min(...n)}}function Af(t){return(e,n,r)=>typeof e=="string"?e:e instanceof y?n?new y(e.data,e.offset+n):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,n||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],n||0)))}function Mf(t){return()=>1.618033988749895}function Tf(t){return()=>Math.PI}function Pf(t){return(e,n)=>Math.pow(y.from(e).get(0),y.from(n).get(0))}function Df(t){return()=>Math.random()}function Ki(t){return t!==t?NaN:Math.sign(t)*Math.round(Math.abs(t))}function Rf(t){return(e,n)=>{let r=y.from(e).get(0);if(n==null)return Ki(r);let i=y.from(n).get(0);if(i===0)return Ki(r);let s=Math.pow(10,i);return Ki(r*s)/s}}function Of(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Lf(t){return()=>.6180339887498948}function Ff(t){return e=>Math.sign(y.from(e).get(0))}function Bf(t){return e=>Math.sin(y.from(e).get(0))}function Vf(t){return e=>Math.sqrt(y.from(e).get(0))}function Wf(t){return(e,n)=>{let r=y.from(n).get(0),i=y.from(e),s=0;for(let a=0;a<r;a++){let o=i.get(a);s+=o}return s}}function $f(t){return e=>Math.tan(y.from(e).get(0))}function jf(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(180/Math.PI)}}function Uf(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(Math.PI/180)}}function zf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10:r===i}}function qf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!0:r>i:r>=i}}function Hf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!1:r>i:r>i}}function Kf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r!="number"||typeof i!="number"?r/i:isNaN(r)||isNaN(i)?NaN:Math.trunc(r/i)}}function Yf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!0:r<i:r<=i}}function Gf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!1:r<i:r<i}}function Xf(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)>=1e-10:r!==i}}var Zf=Object.defineProperty,Qf=(t,e,n)=>e in t?Zf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J=(t,e,n)=>Qf(t,typeof e!="symbol"?e+"":e,n),Jf={abs:ff,acos:mf,asin:yf,atan:gf,avg:xf,ceil:_f,cos:bf,e:vf,exp:wf,floor:Sf,ln:Ef,log:Cf,log10:If,max:Nf,min:kf,param:Af,phi:Mf,pi:Tf,pow:Pf,random:Df,round:Rf,round_to_mintick:Of,rphi:Lf,sign:Ff,sin:Bf,sqrt:Vf,sum:Wf,tan:$f,todegrees:jf,toradians:Uf,__eq:zf,__ge:qf,__gt:Hf,__idiv:Kf,__le:Yf,__lt:Gf,__neq:Xf},ds=class{constructor(e){this.context=e,J(this,"_cache",{}),J(this,"abs"),J(this,"acos"),J(this,"asin"),J(this,"atan"),J(this,"avg"),J(this,"ceil"),J(this,"cos"),J(this,"e"),J(this,"exp"),J(this,"floor"),J(this,"ln"),J(this,"log"),J(this,"log10"),J(this,"max"),J(this,"min"),J(this,"param"),J(this,"phi"),J(this,"pi"),J(this,"pow"),J(this,"random"),J(this,"round"),J(this,"round_to_mintick"),J(this,"rphi"),J(this,"sign"),J(this,"sin"),J(this,"sqrt"),J(this,"sum"),J(this,"tan"),J(this,"todegrees"),J(this,"toradians"),J(this,"__eq"),J(this,"__ge"),J(this,"__gt"),J(this,"__idiv"),J(this,"__le"),J(this,"__lt"),J(this,"__neq"),Object.entries(Jf).forEach(([n,r])=>{this[n]=r(e)})}};function em(t){return(e,n,r)=>{t.params[r]||(t.params[r]=[]);let i;if(e instanceof y)i=e.get(n||0);else if(Array.isArray(e)){let s=e.some(o=>o instanceof y),a=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(s||a)&&e.length>=1?i=e.map(o=>o instanceof y?o.get(0):o):i=y.from(e).get(n||0)}else i=e;return t.params[r].length===0?t.params[r].push(i):t.params[r][t.params[r].length-1]=i,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[r]=e,[i,r]}}var tm=new Set(["heikinashi","standard"]);function dr(t){if(typeof t!="string")return{symbol:t,modifier:null};let e=t.lastIndexOf(";");if(e<=0||e===t.length-1)return{symbol:t,modifier:null};let n=t.slice(e+1).toLowerCase();return tm.has(n)?{symbol:t.slice(0,e),modifier:n}:{symbol:t,modifier:null}}function tn(t){return dr(t).symbol}function fs(t,e){return`${tn(t)};${e}`}var Wn=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Nr={"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 Gr(t){if(Wn.includes(t))return t;if(Nr[t])return Nr[t];let e=t.toLowerCase();if(Nr[e])return Nr[e];let n=t.toUpperCase();return Wn.includes(n)?n:t}function no(t,e,n,r,i=!1,s=!1){for(let a=0;a<n.length;a++)if(n[a]<=t&&t<r[a])return i||s||e>=r[a]?a:a-1;return-1}function ro(t,e,n,r,i=!1,s,a=!1){for(let o=n.length-1;o>=0;o--){if(r[o]<=e&&n[o]>=t){let l=s&&e>s;if(a&&i)for(let c=0;c<n.length;c++){if(n[c]>=t&&n[c]<e)return c;if(n[c]>=e)break}if(l&&i&&!a)for(let c=0;c<n.length;c++){if(n[c]>=t&&n[c]<e)return c;if(n[c]>=e)break}return o}if(r[o]<t)break}return-1}var io=[["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"]],nm={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function ia(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function rm(t,e){return t.map(n=>ia(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Mn(t){return ia(t)?t[0]:t}function im(t,e,n,r){let i=e[e.length-1].indexOf(t);if(i>=0&&i<n.length&&n[i]!==void 0)return n[i];if(ia(r))return r[1]}function ms(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(ms):t}function sm(t){return async(...e)=>{let n=[],r=rm(e,n),i=ye(r,io,nm),s=Mn(i.symbol),a=Mn(i.timeframe),o=Mn(i.expression),l=Mn(i.gaps),c=Mn(i.lookahead),u=s instanceof y?s.get(0):s,p=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId,h=typeof p=="string"?dr(p):{symbol:p,modifier:null},d=h.modifier==="standard"?null:h.modifier,f=u===""?t.tickerId:u,m=typeof f=="string"&&f.includes(":")?f.split(":")[1]:f,_=a instanceof y?a.get(0):a,b=_===""?t.timeframe:typeof _=="string"?_:String(_??""),v=o,S=im("expression",io,n,i.expression),w=l,I=c,E=w===!0||w==="gaps_on",A=I===!0||I==="lookahead_on",F=(()=>{let Le=Mn(i.calc_bars_count);return typeof Le=="number"&&Le>0?Le:void 0})();if(t.isSecondaryContext){let Le=ms(v);return Array.isArray(Le)?[Le]:Le}let N=Wn.indexOf(Gr(t.timeframe)),j=Wn.indexOf(Gr(b));if(N==-1||j==-1)throw new Error("Invalid timeframe");let T=typeof m=="string"?dr(m):{symbol:m,modifier:null},q=T.modifier==="standard"?null:T.modifier,B=!m||m===""||T.symbol===h.symbol&&q===d;if(N===j&&B){let Le=ms(v);return Array.isArray(Le)?[Le]:Le}let O=N>j,K=y.from(t.data.openTime).get(0),ae=y.from(t.data.closeTime).get(0),ke=t.idx===t.length-1&&ae>Date.now(),he=`${m}_${b}_${S}`,je=`${he}_prevIdx`;if(t.cache[he]){let Le=t.cache[he];t.dataVersion>Le.dataVersion&&(await Le.pineTS.updateTail(Le.context),Le.dataVersion=t.dataVersion);let Qn=Le.context,Ir=O?ro(K,ae,Qn.data.openTime.data,Qn.data.closeTime.data,A,t.eDate,E):no(K,ae,Qn.data.openTime.data,Qn.data.closeTime.data,A,ke);if(Ir==-1)return NaN;let kn=Qn.params[S][Ir];if(!O&&E){let Qa=t.cache[je];return Qa!==void 0&&Qa===Ir?NaN:(t.cache[je]=Ir,Array.isArray(kn)?[kn]:kn)}return Array.isArray(kn)?[kn]:kn}let Zn=1e3*60*60*24*30,Ga=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),ju=F?void 0:Ga?Ga-Zn:void 0,Uu=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),Cr=new on(t.source,m,b,F,ju,Uu);Cr.markAsSecondary();let Xa=typeof S=="string"?S:"",zu=Xa.match(/p\\d+$/)?.[0]??Xa,Za=t._ltfTruncatedBodies?.[zu],Nn=Za?await Cr.runPretranspiled(Za):await Cr.run(t.pineTSCode);t.cache[he]={pineTS:Cr,context:Nn,dataVersion:t.dataVersion};let zi=O?ro(K,ae,Nn.data.openTime.data,Nn.data.closeTime.data,A,t.eDate,E):no(K,ae,Nn.data.openTime.data,Nn.data.closeTime.data,A,ke);if(zi==-1)return NaN;let qi=Nn.params[S][zi];return!O&&E?(t.cache[je]=zi,NaN):Array.isArray(qi)?[qi]:qi}}var so=[["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"]],am={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function sa(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function om(t,e){return t.map(n=>sa(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Tn(t){return sa(t)?t[0]:t}function lm(t,e,n,r){let i=e[e.length-1].indexOf(t);if(i>=0&&i<n.length&&n[i]!==void 0)return n[i];if(sa(r))return r[1]}function Pn(t){return typeof t=="number"?G.float:typeof t=="boolean"?G.bool:typeof t=="string"?G.string:G.any}var ll={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 ys(t,e){if(!(t instanceof y))return null;let n=e?.data;if(!n)return null;for(let r of Object.keys(ll))if(t===n[r])return r;return null}function cm(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof en))return null;let n=t._udt;if(!n||!n._fieldDefaults||!Array.isArray(n._definitionKeys))return null;let r=n._definitionKeys;if(r.length===0)return null;let i=[];for(let s of r){if(!(s in n._fieldDefaults))return null;let a=n._fieldDefaults[s],o=ys(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:r,udt:n}}function um(t,e){if(t===void 0)return null;if(Array.isArray(t)){let r=[];for(let i of t){let s=ys(i,e);if(s===null)return null;r.push(s)}return r.length>0?{kind:"tuple",builtinNames:r}:null}let n=ys(t,e);return n!==null?{kind:"series",builtinNames:[n]}:cm(t,e)}async function ao(t,e,n,r,i,s){let a=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),o=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),l=new on(t.source,e,n,r,a,o);l.markAsSecondary(),await l.ready();let c=l.openTime,u=l.closeTime,p=l.data,h=i.builtinNames.map(f=>ll[f]),d;if(i.kind==="series")d=p.map(f=>h[0](f));else if(i.kind==="tuple")d=p.map(f=>h.map(m=>m(f)));else{let f=i.fieldNames,m=i.udt;d=p.map(_=>{let b={};for(let v=0;v<f.length;v++)b[f[v]]=h[v](_);return new en(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function hm(t){return async(...e)=>{let n=[],r=om(e,n),i=ye(r,so,am),s=Tn(i.symbol),a=Tn(i.timeframe),o=Tn(i.expression),l=s instanceof y?s.get(0):s,c=l===""?t.tickerId:l,u=typeof c=="string"&&c.includes(":")?c.split(":")[1]:c,p=a instanceof y?a.get(0):a,h=p===""?t.timeframe:typeof p=="string"?p:String(p??""),d=o,f=lm("expression",so,n,i.expression);Tn(i.ignore_invalid_symbol);let m=Tn(i.ignore_invalid_timeframe),_=(()=>{let O=Tn(i.calc_bars_count);return typeof O=="number"&&O>0?O:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(O=>new Y([O],Pn(O),t))]:new Y([d],Pn(d),t);let b=Wn.indexOf(Gr(t.timeframe)),v=Wn.indexOf(Gr(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(d)?[d.map(O=>new Y([O],Pn(O),t))]:new Y([d],Pn(d),t);let S=`${u}_${h}_${f}_lower`,w=t._requestParamSources?.[f],I=um(w,t);if(!t.cache[S])if(I!==null){let O=await ao(t,u,h,_,I,f);t.cache[S]={pineTS:null,context:O,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:I}}}else{let O=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(),ae=new on(t.source,u,h,_,O,K);ae.markAsSecondary();let ke=typeof f=="string"?f:"",he=ke.match(/p\\d+$/)?.[0]??ke,je=t._ltfTruncatedBodies?.[he],Zn;je?Zn=await ae.runPretranspiled(je):Zn=await ae.run(t.pineTSCode),t.cache[S]={pineTS:ae,context:Zn,dataVersion:t.dataVersion}}let E=t.cache[S];if(t.dataVersion>E.dataVersion)if(E._fastPath){let O=await ao(t,u,h,_,E._fastPathArgs.builtinExpr,f);E.context=O,E.dataVersion=t.dataVersion}else await E.pineTS.updateTail(E.context),E.dataVersion=t.dataVersion;let A=E.context,F=y.from(t.data.openTime).get(0),N=y.from(t.data.closeTime).get(0),j=A.data.openTime.data,T=A.data.closeTime.data,q=A.params[f];if(!q)return Array.isArray(d)?[d.map(()=>new Y([],G.float,t))]:new Y([],G.float,t);let B=[];for(let O=0;O<j.length;O++){let K=j[O];if(!(T[O]<=F)){if(K>=N)break;K>=F&&K<N&&B.push(q[O])}}if(B.length>0&&Array.isArray(B[0])){let O=B[0].length,K=[];for(let ae=0;ae<O;ae++){let ke=B.map(je=>je[ae]),he=ke.length>0?Pn(ke[0]):G.float;K.push(new Y(ke,he,t))}return[K]}else{let O=B.length>0?Pn(B[0]):G.float;return new Y(B,O,t)}}}var pm=Object.defineProperty,dm=(t,e,n)=>e in t?pm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kr=(t,e,n)=>dm(t,typeof e!="symbol"?e+"":e,n),fm={param:em,security:sm,security_lower_tf:hm},gs=class{constructor(e){this.context=e,kr(this,"_cache",{}),kr(this,"param"),kr(this,"security"),kr(this,"security_lower_tf"),Object.entries(fm).forEach(([n,r])=>{this[n]=r(e)})}};function mm(t){return e=>{t.taState||(t.taState={});let n=e||"accdist";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=s-a,c=0;l!==0&&(c=(i-a-(s-i))/l*o);let u=r.prevCumulativeSum+c;return r.currentCumulativeSum=u,t.precision(u)}}function ym(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=y.from(i).get(0);t.taState||(t.taState={});let c=s||`alma_${a}_${o}_${l}`;if(!t.taState[c]){let m=o*(a-1),_=a/l,b=[],v=0;for(let S=0;S<a;S++){let w=Math.exp(-Math.pow(S-m,2)/(2*_*_));b.push(w),v+=w}for(let S=0;S<b.length;S++)b[S]/=v;t.taState[c]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weights:b}}let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.prevWindow=[...u.currentWindow],u.prevCallCount=u.currentCallCount),u.lastIdx=t.idx);let p=y.from(e).get(0),h=[...u.prevWindow];for(h.unshift(p);h.length>a;)h.pop();let d=u.prevCallCount+1;if(h.length<a&&(d>=a||t.idx>=a-1)){let m=y.from(e);for(;h.length<a;)h.push(m.get(h.length))}if(u.currentWindow=h,u.currentCallCount=d,h.length<a)return NaN;let f=0;for(let m=0;m<a;m++)f+=u.weights[m]*h[a-1-m];return t.precision(f)}}function gm(t){return(e,n)=>{let r=y.from(e).get(0);t.taState||(t.taState={});let i=n||`atr_${r}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevAtr=s.currentAtr,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return NaN;let c=t.idx>0?t.get(t.data.close,1):null,u;if(c!==null&&!isNaN(c)){let m=a-o,_=Math.abs(a-c),b=Math.abs(o-c);u=Math.max(m,_,b)}else u=a-o;let p=s.prevInitCount,h=s.prevInitSum,d=s.prevAtr;if(p<r){if(h+=u,p++,s.currentInitSum=h,s.currentInitCount=p,p===r){let m=h/r;return s.currentAtr=m,t.precision(m)}return NaN}let f=(d*(r-1)+u)/r;return s.currentAtr=f,t.precision(f)}}function xm(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevLastTrueIndex=i.currentLastTrueIndex),i.lastIdx=t.idx);let s=y.from(e).get(0),a=i.prevLastTrueIndex;return s&&(a=t.idx),i.currentLastTrueIndex=a,a===null?NaN:t.idx-a}}function _m(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`bb_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];let u=[...l.prevWindow],p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){let b=u.pop();p-=b}if(u.length<s&&t.idx>=s-1){let b=y.from(e);for(;u.length<s;){let 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]];let h=p/s,d=0;for(let b=0;b<s;b++)d+=Math.pow(u[b]-h,2);let f=Math.sqrt(d/s),m=h+a*f,_=h-a*f;return[[t.precision(h),t.precision(m),t.precision(_)]]}}function bm(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`bbw_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;let u=[...l.prevWindow],p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){let v=u.pop();p-=v}if(u.length<s&&t.idx>=s-1){let v=y.from(e);for(;u.length<s;){let S=v.get(u.length);if(isNaN(S))break;u.push(S),p+=S}}if(l.currentWindow=u,l.currentSum=p,u.length<s)return NaN;let h=p/s,d=0;for(let v=0;v<s;v++){let S=u[v]-h;d+=S*S}let f=d/s,m=Math.sqrt(f),_=a*m;if(h===0)return t.precision(0);let b=2*_/h*100;return t.precision(b)}}function vm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`cci_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(isNaN(o))return NaN;let l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let m=l.pop();c-=m}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;){let _=m.get(l.length);if(isNaN(_))break;l.push(_),c+=_}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let p=c/i,h=0;for(let m=0;m<i;m++)h+=Math.abs(l[m]-p);let d=h/i;if(d===0)return 0;let f=(o-p)/(.015*d);return t.precision(f)}}function wm(t){return(e,n=1,r)=>{typeof n=="string"&&(r=n,n=1);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`change_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let p=y.from(e);for(;l.length<i+1;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=o-l[i];return t.precision(u)}}function Sm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`cmo_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevGainsWindow=[...a.currentGainsWindow],a.prevLossesWindow=[...a.currentLossesWindow],a.prevGainsSum=a.currentGainsSum,a.prevLossesSum=a.currentLossesSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;let c=o-l,u=c>=0?c:0,p=c>=0?0:-c,h=[...a.prevGainsWindow],d=[...a.prevLossesWindow],f=a.prevGainsSum,m=a.prevLossesSum;if(h.unshift(u),d.unshift(p),f+=u,m+=p,h.length<i)return a.currentGainsWindow=h,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m,NaN;if(h.length>i){let v=h.pop(),S=d.pop();f-=v,m-=S}a.currentGainsWindow=h,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m;let _=f+m;if(_===0)return t.precision(0);let b=100*(f-m)/_;return t.precision(b)}}function Em(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e),a=0,o=!1;for(let u=0;u<i;u++){let p=s.get(u);if(isNaN(p)){o=!0;break}a+=p}if(o)return NaN;let l=0;for(let u=0;u<i;u++){let p=s.get(u);l+=p*(u+1)}if(a===0)return NaN;let c=-l/a;return t.precision(c)}}function Cm(t){return(e,n,r,i)=>{let s=y.from(r).get(0),a=y.from(e),o=y.from(n);if(t.idx<s-1)return NaN;let l=0,c=0,u=0,p=0,h=0,d=0;for(let v=0;v<s;v++){let S=a.get(v),w=o.get(v);isNaN(S)||isNaN(w)||(l+=S,c+=w,u+=S*w,p+=S*S,h+=w*w,d++)}if(d<2)return NaN;let f=d*u-l*c,m=d*p-l*l,_=d*h-c*c;if(m<=0||_<=0)return t.precision(0);let b=f/Math.sqrt(m*_);return t.precision(b)}}function Im(t){return(e,n,r)=>{let i=y.from(e),s=y.from(n),a=i.get(0),o=s.get(0),l=i.get(1),c=s.get(1);if(isNaN(a)||isNaN(o)||isNaN(l)||isNaN(c))return!1;let u=a>o&&l<=c,p=a<o&&l>=c;return u||p}}function Nm(t){return(e,n)=>{let r=y.from(e),i=y.from(n),s=r.get(0),a=i.get(0),o=r.get(1),l=i.get(1);return o<=l&&s>a}}function km(t){return(e,n)=>{let r=y.from(e),i=y.from(n),s=r.get(0),a=i.get(0),o=r.get(1),l=i.get(1);return o>=l&&s<a}}function Am(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativeSum=i.currentCumulativeSum),i.lastIdx=t.idx);let s=y.from(e).get(0);if(isNaN(s))return i.currentCumulativeSum=i.prevCumulativeSum,t.precision(i.prevCumulativeSum);let a=i.prevCumulativeSum+s;return i.currentCumulativeSum=a,t.precision(a)}}function Mm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`dev_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=[...a.prevWindow],c=a.prevSum;for(l.unshift(o),c+=o;l.length>i;){let f=l.pop();c-=f}let u=a.prevCallCount+1;if(l.length<i&&(u>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;){let m=f.get(l.length);l.push(m),c+=m}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let p=c/i,h=0;for(let f=0;f<i;f++)h+=Math.abs(l[f]-p);let d=h/i;return t.precision(d)}}function Tm(t){return(e,n,r)=>{let i=y.from(e).get(0),s=y.from(n).get(0);t.taState||(t.taState={});let a=r||`dmi_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN,NaN]];let p=t.idx>0?t.get(t.data.high,1):NaN,h=t.idx>0?t.get(t.data.low,1):NaN,d=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];let f=Math.max(l-c,Math.abs(l-d),Math.abs(c-d)),m=l-p,_=h-c,b=m>_&&m>0?m:0,v=_>m&&_>0?_:0,S=o.prevInitCount,w=o.prevTrInitSum,I=o.prevPlusInitSum,E=o.prevMinusInitSum,A=o.prevSmoothedTR,F=o.prevSmoothedPlus,N=o.prevSmoothedMinus;if(S++,S<=i)w+=f,I+=b,E+=v,S===i&&(A=w/i,F=I/i,N=E/i);else{let he=1/i;A=he*f+(1-he)*A,F=he*b+(1-he)*F,N=he*v+(1-he)*N}if(o.currentInitCount=S,o.currentTrInitSum=w,o.currentPlusInitSum=I,o.currentMinusInitSum=E,o.currentSmoothedTR=A,o.currentSmoothedPlus=F,o.currentSmoothedMinus=N,S<i)return[[NaN,NaN,NaN]];let j=A===0?0:100*F/A,T=A===0?0:100*N/A,q=j+T,B=q===0?0:100*Math.abs(j-T)/q,O=o.prevAdxInitCount,K=o.prevDxInitSum,ae=o.prevADX,ke=NaN;if(O++,O<=s)K+=B,O===s&&(ae=K/s,ke=ae);else{let he=1/s;ae=he*B+(1-he)*ae,ke=ae}return o.currentAdxInitCount=O,o.currentDxInitSum=K,o.currentADX=ae,[[t.precision(j),t.precision(T),t.precision(ke)]]}}function Pm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`ema_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevEma=a.currentEma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevEma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentEma=d,t.precision(d)}return NaN}let p=2/(i+1),h=o*p+u*(1-p);return a.currentEma=h,t.precision(h)}}function Dm(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o>=l)return!1}return!0}}function Rm(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.high);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`highest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let h=y.from(e);for(;l.length<i;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;let p=Math.max(...u);return t.precision(p)}}function Om(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=-1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c>a)&&(a=c,o=-l)}return o}}function Lm(t){return(e,n,r)=>{let i=y.from(n).get(0),s=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),o=t.pine.ta.wma,l=o(e,s,r?`${r}_wma1`:void 0),c=o(e,i,r?`${r}_wma2`:void 0);if(isNaN(l)||isNaN(c))return NaN;t.taState||(t.taState={});let u=r||`hma_raw_${i}`;t.taState[u]||(t.taState[u]={lastIdx:-1,prevValues:[],currentValues:[]});let p=t.taState[u];t.idx>p.lastIdx&&(p.lastIdx>=0&&(p.prevValues=[...p.currentValues]),p.lastIdx=t.idx);let h=2*l-c,d=[...p.prevValues];d.unshift(h),d.length>a+1&&d.pop(),p.currentValues=d;let f=r?`${r}_hma_final`:`hma_final_${i}`;t.taState[f]||(t.taState[f]={lastIdx:-1,prevWindow:[],currentWindow:[]});let m=t.taState[f];t.idx>m.lastIdx&&(m.lastIdx>=0&&(m.prevWindow=[...m.currentWindow]),m.lastIdx=t.idx);let _=[...m.prevWindow];if(_.unshift(h),_.length<a)return m.currentWindow=_,NaN;for(;_.length>a;)_.pop();m.currentWindow=_;let b=0,v=0;for(let w=0;w<a;w++){let I=a-w;b+=_[w]*I,v+=I}let S=b/v;return t.precision(S)}}function Fm(t){return e=>{let n=t.get(t.data.close,0),r=t.get(t.data.high,0),i=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s))return NaN;let a=(r-i)*s;if(a===0)return t.precision(0);let o=(2*n-r-i)/a;return t.precision(o)}}function Bm(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0));let c,u=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){let w=t.get(t.data.close,1);isNaN(w)?c=NaN:c=Math.max(u-p,Math.abs(u-w),Math.abs(p-w))}else c=u-p;let h=y.from(e).get(0);t.taState||(t.taState={});let d=s||`kc_${a}_${o}_${l}`;t.taState[d]||(t.taState[d]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let f=t.taState[d];t.idx>f.lastIdx&&(f.lastIdx>=0&&(f.basisState={...f.currentBasisState},f.rangeState={...f.currentRangeState}),f.lastIdx=t.idx);let m=(w,I,E,A)=>{if(isNaN(E))return Object.assign(I,w),I.prevEma!==null?I.prevEma:NaN;let F=w.initCount,N=w.initSum,j=w.prevEma;if(F<A){if(N+=E,F++,I.initSum=N,I.initCount=F,I.prevEma=j,F===A){let B=N/A;return I.prevEma=B,B}return NaN}let T=2/(A+1),q=E*T+j*(1-T);return I.prevEma=q,I.initSum=N,I.initCount=F,q},_=m(f.basisState,f.currentBasisState,h,a),b=m(f.rangeState,f.currentRangeState,c,a);if(isNaN(_)||isNaN(b))return[[NaN,NaN,NaN]];let v=_+b*o,S=_-b*o;return[[t.precision(_),t.precision(v),t.precision(S)]]}}function Vm(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0)),t.taState||(t.taState={});let c=s||`kcw_${a}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);let p=(S,w,I,E)=>{if(isNaN(I))return Object.assign(w,S),w.prevEma!==null?w.prevEma:NaN;let A=S.initCount,F=S.initSum,N=S.prevEma;if(A<E){if(F+=I,A++,w.initSum=F,w.initCount=A,w.prevEma=N,A===E){let q=F/E;return w.prevEma=q,q}return NaN}let j=2/(E+1),T=I*j+N*(1-j);return w.prevEma=T,w.initSum=F,w.initCount=A,T},h,d=t.get(t.data.high,0),f=t.get(t.data.low,0);if(l){let S=t.get(t.data.close,1);isNaN(S)?h=NaN:h=Math.max(d-f,Math.abs(d-S),Math.abs(f-S))}else h=d-f;let m=y.from(e).get(0),_=p(u.basisState,u.currentBasisState,m,a),b=p(u.rangeState,u.currentRangeState,h,a);if(isNaN(_)||isNaN(b))return NaN;if(_===0)return t.precision(0);let v=2*b*o/_;return t.precision(v)}}function Wm(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`linreg_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>s;)u.pop();let p=l.prevCallCount+1;if(u.length<s&&(p>=s||t.idx>=s-1)){let w=y.from(e);for(;u.length<s;)u.push(w.get(u.length))}if(l.currentWindow=u,l.currentCallCount=p,u.length<s)return NaN;let h=0,d=0,f=0,m=0,_=s;for(let w=0;w<s;w++){let I=s-1-w,E=u[w];h+=I,d+=E,f+=I*E,m+=I*I}let b=_*m-h*h;if(b===0)return NaN;let v=(_*f-h*d)/b,S=(d-v*h)/_+v*(s-1-a);return t.precision(S)}}function $m(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.low);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`lowest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let h=y.from(e);for(;l.length<i;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.filter(h=>!isNaN(h)&&h!==void 0);if(u.length===0)return NaN;let p=Math.min(...u);return t.precision(p)}}function jm(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);isNaN(c)||(isNaN(o)||c<a)&&(a=c,o=-l)}return o}}function Um(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=y.from(i).get(0),c=s||`macd_${a}_${o}_${l}`,u=`${c}_fast`,p=`${c}_slow`,h=`${c}_signal`,d=t.pine.ta.ema(e,a,u),f=t.pine.ta.ema(e,o,p),m=NaN;!isNaN(d)&&!isNaN(f)&&(m=d-f);let _=NaN;isNaN(m)||(_=t.pine.ta.ema(m,l,h));let b=NaN;return!isNaN(m)&&!isNaN(_)&&(b=m-_),[[t.precision(m),t.precision(_),t.precision(b)]]}}function zm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`median_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.slice().sort((d,f)=>d-f),p=Math.floor(i/2),h=i%2===0?(u[p-1]+u[p])/2:u[p];return t.precision(h)}}function qm(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`mfi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevUpperWindow=[...a.currentUpperWindow],a.prevLowerWindow=[...a.currentLowerWindow],a.prevUpperSum=a.currentUpperSum,a.prevLowerSum=a.currentLowerSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;let u=isNaN(l)?NaN:o-l,p=c*(u<=0?0:o),h=c*(u>=0?0:o),d=[...a.prevUpperWindow],f=[...a.prevLowerWindow],m=a.prevUpperSum,_=a.prevLowerSum;if(d.unshift(p),f.unshift(h),m+=p,_+=h,d.length<i)return a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=_,NaN;if(d.length>i){let v=d.pop(),S=f.pop();m-=v,_-=S}if(a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=_,_===0)return t.precision(100);if(m===0)return t.precision(0);let b=100-100/(1+m/_);return t.precision(b)}}function Hm(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=new Map;for(let c=0;c<i;c++){let u=s.get(c);isNaN(u)||a.set(u,(a.get(u)||0)+1)}if(a.size===0)return NaN;let o=NaN,l=-1;for(let[c,u]of a.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function Km(t){return(e,n,r)=>{let i=y.from(n).get(0);return t.pine.ta.change(e,i,r)}}function Ym(t){return e=>{t.taState||(t.taState={});let n=e||"nvi";t.taState[n]||(t.taState[n]={lastIdx:-1,committedNVI:1,tentativeNVI:1});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o,h=r.committedNVI;if(!(l===0||c===0)&&u<p){let d=(l-c)/c;h=h+d*h}return r.tentativeNVI=h,t.precision(h)}}function Gm(t){return()=>{t.taState||(t.taState={});let e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});let n=t.taState[e];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedOBV=n.tentativeOBV),n.lastIdx=t.idx);let r=t.get(t.data.close,0),i=t.get(t.data.volume,0),s=t.get(t.data.close,1);if(isNaN(s))return n.tentativeOBV=0,t.precision(0);let a=n.committedOBV;return r>s?a+=i:r<s&&(a-=i),n.tentativeOBV=a,t.precision(a)}}function Xm(t){return(e,n,r)=>e instanceof y?n?new y(e.data,e.offset+n):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,n||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],n||0)))}function Zm(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let f=0;f<s;f++){let m=o.get(f);if(isNaN(m))return NaN;l.push(m)}l.sort((f,m)=>f-m);let c=a/100*s-.5;c<0&&(c=0),c>s-1&&(c=s-1);let u=Math.floor(c),p=Math.ceil(c);if(u===p)return t.precision(l[u]);let h=c-u,d=l[u]+h*(l[p]-l[u]);return t.precision(d)}}function Qm(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let u=0;u<s;u++){let 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 Jm(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i)return NaN;let a=s.get(0);if(isNaN(a))return NaN;let o=0,l=0;for(let c=1;c<=i;c++){let u=s.get(c);isNaN(u)||(l++,u<=a&&o++)}return l===0?NaN:t.precision(o/l*100)}}function ey(t,e,n){let r=new Array(t.length).fill(NaN);for(let i=e+n;i<t.length;i++){let s=t[i-n],a=!0;for(let o=1;o<=e;o++)if(t[i-n-o]>=s){a=!1;break}if(a){for(let o=1;o<=n;o++)if(t[i-n+o]>=s){a=!1;break}}a&&(r[i]=s)}return r}function ty(t){return(e,n,r,i)=>{typeof r=="string"&&(r=n,n=e,e=t.data.high);let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=ey(o,s,a),c=t.idx;return t.precision(l[c])}}function ny(t,e,n){let r=new Array(t.length).fill(NaN);for(let i=e+n;i<t.length;i++){let s=t[i-n],a=!0;for(let o=1;o<=e;o++)if(t[i-n-o]<=s){a=!1;break}if(a){for(let o=1;o<=n;o++)if(t[i-n+o]<=s){a=!1;break}}a&&(r[i]=s)}return r}function ry(t){return(e,n,r,i)=>{typeof r=="string"&&(r=n,n=e,e=t.data.low);let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=ny(o,s,a),c=t.idx;return t.precision(l[c])}}function iy(t){return e=>{t.taState||(t.taState={});let n=e||"pvi";t.taState[n]||(t.taState[n]={lastIdx:-1,committedPVI:1,tentativePVI:1});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o,h=r.committedPVI;if(!(l===0||c===0)&&u>p){let d=(l-c)/c;h=h+d*h}return r.tentativePVI=h,t.precision(h)}}function sy(t){return e=>{t.taState||(t.taState={});let n=e||"pvt";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=r.prevCumulativeSum;if(!isNaN(i)&&!isNaN(s)&&!isNaN(a)&&s!==0){let l=(i-s)/s*a;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function ay(t){return(e,n,r)=>{let i=t.pine.ta.highest(e,n,(r||"range")+"_h"),s=t.pine.ta.lowest(e,n,(r||"range")+"_l");return isNaN(i)||isNaN(s)?NaN:t.precision(i-s)}}function oy(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);for(let a=0;a<i;a++){let o=s.get(a),l=s.get(a+1);if(isNaN(o)||isNaN(l)||o<=l)return!1}return!0}}function ly(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`rma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevRma=a.currentRma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0)||0,l=a.prevInitCount,c=a.prevInitSum,u=a.prevRma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentRma=d,t.precision(d)}return NaN}let p=1/i,h=o*p+u*(1-p);return a.currentRma=h,t.precision(h)}}function cy(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`roc_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let h=y.from(e);for(;l.length<i+1;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=l[i],p=(o-u)/u*100;return t.precision(p)}}function uy(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`rsi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevPrevValue=a.currentPrevValue,a.prevAvgGain=a.currentAvgGain,a.prevAvgLoss=a.currentAvgLoss,a.prevInitGains=[...a.currentInitGains],a.prevInitLosses=[...a.currentInitLosses]),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevPrevValue;if(l===null||isNaN(l))return a.currentPrevValue=o,a.currentInitGains=[...a.prevInitGains],a.currentInitLosses=[...a.prevInitLosses],a.currentAvgGain=a.prevAvgGain,a.currentAvgLoss=a.prevAvgLoss,NaN;let c=a.prevAvgGain,u=a.prevAvgLoss,p=[...a.prevInitGains],h=[...a.prevInitLosses],d=o-l,f=d>0?d:0,m=d<0?-d:0;if(p.length<i){if(p.push(f),h.push(m),a.currentInitGains=p,a.currentInitLosses=h,a.currentPrevValue=o,p.length===i){c=p.reduce((v,S)=>v+S,0)/i,u=h.reduce((v,S)=>v+S,0)/i,a.currentAvgGain=c,a.currentAvgLoss=u;let b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(i-1)+f)/i,u=(u*(i-1)+m)/i,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;let _=u===0?100:100-100/(1+c/u);return t.precision(_)}}function hy(t){return(e,n,r,i)=>{let s=y.from(e).get(0),a=y.from(n).get(0),o=y.from(r).get(0);t.taState||(t.taState={});let l=i||`sar_${s}_${a}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});let c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let u=c.prevResult,p=c.prevMaxMin,h=c.prevAcceleration,d=c.prevIsBelow,f=c.prevBarIndex,m=t.get(t.data.high,0),_=t.get(t.data.low,0),b=t.get(t.data.close,0),v=t.get(t.data.close,1),S=t.get(t.data.high,1),w=t.get(t.data.low,1),I=t.get(t.data.high,2),E=t.get(t.data.low,2);if(isNaN(m)||isNaN(_)||isNaN(b))return c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,NaN;let A=!1;return f===1&&(b>v?(d=!0,p=m,u=w):(d=!1,p=_,u=S),A=!0,h=s),f>=1&&(u=u+h*(p-u),d?u>_&&(A=!0,d=!1,u=Math.max(m,p),p=_,h=s):u<m&&(A=!0,d=!0,u=Math.min(_,p),p=m,h=s),A||(d?m>p&&(p=m,h=Math.min(h+a,o)):_<p&&(p=_,h=Math.min(h+a,o))),d?(u=Math.min(u,w),f>1&&(u=Math.min(u,E))):(u=Math.max(u,S),f>1&&(u=Math.max(u,I)))),f++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function py(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`sma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1,u=!1;if(l.length<i&&(c>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;)l.push(m.get(l.length));u=!0}let p,h=o==null||Number.isNaN(o),d=!Number.isNaN(a.prevSum)&&!h&&!u;if(d){let m=a.prevSum+o;if(a.prevWindow.length>=i){let _=a.prevWindow[a.prevWindow.length-1];_==null||Number.isNaN(_)?d=!1:m-=_}d&&(p=m)}if(!d){p=0;let m=!1;for(let _ of l){if(_==null||Number.isNaN(_)){m=!0;break}p+=_}m&&(p=NaN)}if(a.currentWindow=l,a.currentSum=p,a.currentCallCount=c,l.length<i)return NaN;let f=p/i;return t.precision(f)}}function dy(t){return(e,n,r=!0,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`stdev_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum,l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0);if(c==null||isNaN(c))return NaN;let u=[...l.prevWindow],p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){let b=u.pop();p-=b}let h=l.prevCallCount+1;if(u.length<s&&(h>=s||t.idx>=s-1)){let b=y.from(e);for(;u.length<s;){let 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;let d=p/s,f=0;for(let b=0;b<s;b++)f+=Math.pow(u[b]-d,2);let m=a?s:s-1,_=Math.sqrt(f/m);return t.precision(_)}}function fy(t){return(e,n,r,i,s)=>{let a=y.from(i).get(0);t.taState||(t.taState={});let o=s||`stoch_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow]),l.lastIdx=t.idx);let c=y.from(e).get(0),u=y.from(n).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;let h=[...l.prevHighWindow],d=[...l.prevLowWindow];if(h.unshift(u),d.unshift(p),h.length>a&&(h.pop(),d.pop()),l.currentHighWindow=h,l.currentLowWindow=d,h.length<a)return NaN;let f=h[0],m=d[0];for(let v=1;v<a;v++)h[v]>f&&(f=h[v]),d[v]<m&&(m=d[v]);let _=f-m;if(_===0)return NaN;let b=100*(c-m)/_;return t.precision(b)}}function my(t){return(e,n,r)=>{let i=y.from(e).get(0),s=y.from(n).get(0);t.taState||(t.taState={});let a=r||`supertrend_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrSum=o.currentTrSum,o.prevAtrValue=o.currentAtrValue,o.prevAtrCount=o.currentAtrCount,o.prevLowerBand=o.currentLowerBand,o.prevUpperBand=o.currentUpperBand,o.prevSuperTrend=o.currentSuperTrend,o.prevDirection=o.currentDirection),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN]];let p=(l+c)/2,h=t.idx>0?t.get(t.data.close,1):NaN,d;isNaN(h)?d=l-c:d=Math.max(l-c,Math.abs(l-h),Math.abs(c-h));let f=o.prevAtrCount,m=o.prevTrSum,_=o.prevAtrValue;f++,f<=s?(m+=d,f===s&&(_=m/s)):_=(_*(s-1)+d)/s;let b=_;if(o.currentAtrCount=f,o.currentTrSum=m,o.currentAtrValue=_,isNaN(b))return[[NaN,NaN]];let v=p+i*b,S=p-i*b,w=isNaN(o.prevLowerBand)?0:o.prevLowerBand,I=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||S>w||h<w||(S=w),isNaN(o.prevUpperBand)||v<I||h>I||(v=I);let E,A,F=o.prevSuperTrend;return f===s?E=1:F===o.prevUpperBand?E=u>v?-1:1:E=u<S?1:-1,A=E===-1?S:v,o.currentLowerBand=S,o.currentUpperBand=v,o.currentSuperTrend=A,o.currentDirection=E,[[t.precision(A),E]]}}function yy(t){return(e,n)=>{let r=[1,2,2,1],i=6;t.taState||(t.taState={});let s=n||"swma";t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],currentWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){let u=y.from(e);for(;l.length<4;)l.push(u.get(l.length))}if(a.currentWindow=l,l.length<4)return NaN;let c=0;for(let u=0;u<4;u++)c+=r[u]*l[3-u];return c/=i,t.precision(c)}}function gy(t){return(e,n)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));let i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.close,1);if(isNaN(a))return r?t.precision(i-s):NaN;let o=Math.max(i-s,Math.abs(i-a),Math.abs(s-a));return t.precision(o)}}function xy(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`tsi_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return NaN;let u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;let p=Math.abs(u),h=2/(a+1),d=2/(s+1),f=2/(a+1),m=2/(s+1),_=l.prevEma1PcCount,b=l.prevEma1PcSum,v=l.prevEma1PcValue;_++,_<=a?(b+=u,_===a&&(v=b/a)):v=u*h+v*(1-h);let S=l.prevEma1AbsCount,w=l.prevEma1AbsSum,I=l.prevEma1AbsValue;if(S++,S<=a?(w+=p,S===a&&(I=w/a)):I=p*f+I*(1-f),isNaN(v)||isNaN(I))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=S,l.currentEma1AbsSum=w,l.currentEma1AbsValue=I,NaN;let E=l.prevEma2PcCount,A=l.prevEma2PcSum,F=l.prevEma2PcValue;E++,E<=s?(A+=v,E===s&&(F=A/s)):F=v*d+F*(1-d);let N=l.prevEma2AbsCount,j=l.prevEma2AbsSum,T=l.prevEma2AbsValue;if(N++,N<=s?(j+=I,N===s&&(T=j/s)):T=I*m+T*(1-m),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=S,l.currentEma1AbsSum=w,l.currentEma1AbsValue=I,l.currentEma2PcCount=E,l.currentEma2PcSum=A,l.currentEma2PcValue=F,l.currentEma2AbsCount=N,l.currentEma2AbsSum=j,l.currentEma2AbsValue=T,isNaN(F)||isNaN(T))return NaN;if(T===0)return t.precision(0);let q=F/T;return t.precision(q)}}function _y(t){return(e,n,r,i)=>{t.taState||(t.taState={});let s=i||"valuewhen";t.taState[s]||(t.taState[s]={lastIdx:-1,prevValues:[],currentValues:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevValues=[...a.currentValues]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(n).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;let p=u.length-1-c;if(p<0)return NaN;let h=u[p];return typeof h=="number"?t.precision(h):h}}function by(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`variance_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let f=y.from(e);for(;l.length<i;)l.push(f.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,p=0;for(let f=0;f<i;f++)u+=l[f],p+=l[f]*l[f];let h=u/i,d=p/i-h*h;return t.precision(d)}}function vy(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"vwap";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentLastSessionDate:null});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativePV=i.currentCumulativePV,i.prevCumulativeVolume=i.currentCumulativeVolume,i.prevLastSessionDate=i.currentLastSessionDate),i.lastIdx=t.idx);let s=y.from(e).get(0),a=y.from(t.data.volume).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.timezone||"UTC",c=rn(o,l),u=`${c.year}-${String(c.month).padStart(2,"0")}-${String(c.day).padStart(2,"0")}`,p=i.prevCumulativePV,h=i.prevCumulativeVolume,d=i.prevLastSessionDate;if(d!==u&&(p=0,h=0,d=u),p+=s*a,h+=a,i.currentCumulativePV=p,i.currentCumulativeVolume=h,i.currentLastSessionDate=d,h===0)return NaN;let f=p/h;return t.precision(f)}}function wy(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`vwma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevVolumeWindow:[],currentWindow:[],currentVolumeWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevVolumeWindow=[...a.currentVolumeWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=t.get(t.data.volume,0),c=[...a.prevWindow],u=[...a.prevVolumeWindow];for(c.unshift(o),u.unshift(l);c.length>i;)c.pop(),u.pop();if(c.length<i&&t.idx>=i-1){let f=y.from(e),m=y.from(t.data.volume);for(;c.length<i;)c.push(f.get(c.length)),u.push(m.get(u.length))}if(a.currentWindow=c,a.currentVolumeWindow=u,c.length<i)return NaN;let p=0,h=0;for(let f=0;f<i;f++)p+=c[f]*u[f],h+=u[f];let d=p/h;return t.precision(d)}}function Sy(t){return e=>{t.taState||(t.taState={});let n=e||"wad";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(i)||isNaN(s)||isNaN(a))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){let u=Math.max(s,o),p=Math.min(a,o),h=i-o;h>0?l=i-p:h<0&&(l=i-u)}let c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function Ey(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`wma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=0,p=0;for(let d=0;d<i;d++){let f=i-d;u+=l[d]*f,p+=f}let h=u/p;return t.precision(h)}}function Cy(t){return(e,n)=>{let r=y.from(e).get(0);t.taState||(t.taState={});let i=n||`wpr_${r}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevHighWindow=[...s.currentHighWindow],s.prevLowWindow=[...s.currentLowWindow]),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return s.currentHighWindow=[...s.prevHighWindow],s.currentLowWindow=[...s.prevLowWindow],NaN;let c=[...s.prevHighWindow],u=[...s.prevLowWindow];if(c.unshift(a),u.unshift(o),c.length>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]);let d=p-h;if(d===0)return t.precision(0);let f=(p-l)/d*-100;return t.precision(f)}}function Iy(t){return e=>{let n=t.get(t.data.close,0),r=t.get(t.data.open,0),i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s)||isNaN(a))return NaN;let o=i-s;if(o===0)return t.precision(0);let l=(n-r)/o*a;return t.precision(l)}}var Ny=Object.defineProperty,ky=(t,e,n)=>e in t?Ny(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,V=(t,e,n)=>ky(t,typeof e!="symbol"?e+"":e,n),Ay={accdist:mm,alma:ym,atr:gm,barssince:xm,bb:_m,bbw:bm,cci:vm,change:wm,cmo:Sm,cog:Em,correlation:Cm,cross:Im,crossover:Nm,crossunder:km,cum:Am,dev:Mm,dmi:Tm,ema:Pm,falling:Dm,highest:Rm,highestbars:Om,hma:Lm,iii:Fm,kc:Bm,kcw:Vm,linreg:Wm,lowest:$m,lowestbars:jm,macd:Um,median:zm,mfi:qm,mode:Hm,mom:Km,nvi:Ym,obv:Gm,param:Xm,percentile_linear_interpolation:Zm,percentile_nearest_rank:Qm,percentrank:Jm,pivothigh:ty,pivotlow:ry,pvi:iy,pvt:sy,range:ay,rising:oy,rma:ly,roc:cy,rsi:uy,sar:hy,sma:py,stdev:dy,stoch:fy,supertrend:my,swma:yy,tr:gy,tsi:xy,valuewhen:_y,variance:by,vwap:vy,vwma:wy,wad:Sy,wma:Ey,wpr:Cy,wvad:Iy},xs=class{constructor(e){this.context=e,V(this,"accdist"),V(this,"alma"),V(this,"atr"),V(this,"barssince"),V(this,"bb"),V(this,"bbw"),V(this,"cci"),V(this,"change"),V(this,"cmo"),V(this,"cog"),V(this,"correlation"),V(this,"cross"),V(this,"crossover"),V(this,"crossunder"),V(this,"cum"),V(this,"dev"),V(this,"dmi"),V(this,"ema"),V(this,"falling"),V(this,"highest"),V(this,"highestbars"),V(this,"hma"),V(this,"iii"),V(this,"kc"),V(this,"kcw"),V(this,"linreg"),V(this,"lowest"),V(this,"lowestbars"),V(this,"macd"),V(this,"median"),V(this,"mfi"),V(this,"mode"),V(this,"mom"),V(this,"nvi"),V(this,"obv"),V(this,"param"),V(this,"percentile_linear_interpolation"),V(this,"percentile_nearest_rank"),V(this,"percentrank"),V(this,"pivothigh"),V(this,"pivotlow"),V(this,"pvi"),V(this,"pvt"),V(this,"range"),V(this,"rising"),V(this,"rma"),V(this,"roc"),V(this,"rsi"),V(this,"sar"),V(this,"sma"),V(this,"stdev"),V(this,"stoch"),V(this,"supertrend"),V(this,"swma"),V(this,"tr"),V(this,"tsi"),V(this,"valuewhen"),V(this,"variance"),V(this,"vwap"),V(this,"vwma"),V(this,"wad"),V(this,"wma"),V(this,"wpr"),V(this,"wvad"),Object.entries(Ay).forEach(([n,r])=>{this[n]=r(e)})}};function My(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];let e={};typeof t[0]=="string"&&(e.title=t[0]);let n=null;for(let r=1;r<t.length;r++){let i=t[r];typeof i=="string"?e.shorttitle===void 0&&(e.shorttitle=i):typeof i=="object"&&i!==null&&(n=i)}return n&&Object.assign(e,n),e}function tr(t,e,n){if(!n||n<=0||!Number.isFinite(t)||t===e)return t;let r=t/n,i=1e-9;return t>e?Math.ceil(r-i)*n:Math.floor(r+i)*n}function Xr(t,e,n,r){return Math.abs(t)*e*r*n/100}function Ty(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of wi(n)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*r}return n.initial_capital+n.netprofit+i}function Py(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of n.opentrades){let a=Math.sign(s.size)===1?n.config.margin_long??100:n.config.margin_short??100;i+=Xr(s.size,e,a,r)}return i}function aa(t,e,n,r){let i=t.strategy,s=i.config.default_qty_type||"fixed",a=i.config.default_qty_value||1;typeof s=="function"&&(s=s()),typeof a=="function"&&(a=a());let o=1e6,l=u=>Math.floor(u*o)/o;if(e!=null)return l(Math.abs(e));let c;switch(s){case"fixed":c=a;break;case"cash":c=a/r;break;case"percent_of_equity":{c=i.equity*a/100/r;break}default:c=a}return l(c)}function Dy(t){if(!t.strategy)return;let e=t.strategy,{pending_orders:n}=e,r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.pointvalue??1;for(let c of e.opentrades){let u=Math.abs(c.size),p=c.size>0,h=c.commission??0,d=p?(c.entry_price-s)*u*l:(i-c.entry_price)*u*l,f=p?(i-c.entry_price)*u*l:(c.entry_price-s)*u*l,m=Math.max(0,d)+h,_=Math.max(0,f-h);m>(c.max_drawdown??0)&&(c.max_drawdown=m),_>(c.max_runup??0)&&(c.max_runup=_)}Zr(t,r);for(let c of n){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){let h=nn(c.direction);(h===1&&s<=c.limit||h===-1&&i>=c.limit)&&(u=!0,p=c.limit)}break;case"stop":if(c.stop!==void 0){let h=nn(c.direction);(h===1&&i>=c.stop||h===-1&&s<=c.stop)&&(u=!0,p=c.stop)}break}if(u){if(Oy(e,c)){c.status="cancelled";continue}let h=nn(c.direction);p=_s(t,h,p);let d=h===1?e.config.margin_long??100:e.config.margin_short??100;{let f=e.position_size,m=Math.sign(f),_=m!==0&&m!==h,b=_?Math.max(0,c.qty-Math.abs(f)):c.qty;if(b>0){let v=t.pine?.syminfo?.pointvalue??1,S=0;m===h&&(S=Py(t,r));let w=e.equity-S;if(Xr(b,p,d,v)>w){let I=Math.min(Math.abs(f),c.qty);_&&I>0?(fn(t,I,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}}}Fy(t,c,p,o),c.status="filled",c.fill_price=p,c.fill_bar=t.idx,c.fill_time=o}}e.pending_orders=n.filter(c=>c.status==="pending"),Zr(t,a),Yy(t)}function nn(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function cl(t,e,n,r){let i=e.config.commission_type??"percent",s=e.config.commission_value??0;if(!s||s===0)return 0;let a=t.pine?.syminfo?.pointvalue??1;switch(i){case"percent":return Math.abs(n)*r*a*(s/100);case"cash_per_contract":return Math.abs(n)*s;case"cash_per_order":return s;default:return 0}}function _s(t,e,n){let r=t.strategy.config.slippage??0;if(!r||r===0)return n;let i=t.pine?.syminfo?.mintick??.01,s=r*i;return e===1?n+s:n-s}function ul(t){let e=Math.abs(t.position_size);e>t.max_contracts_held_all&&(t.max_contracts_held_all=e),t.position_size>t.max_contracts_held_long&&(t.max_contracts_held_long=t.position_size),-t.position_size>t.max_contracts_held_short&&(t.max_contracts_held_short=-t.position_size)}function Ry(t,e){let n=t.config.pyramiding??1,r=0;for(let i of t.opentrades)Math.sign(i.size)===e&&r++;return r>=n}function Oy(t,e){if(t.risk_halted)return!0;let n=t.risk_rules,r=e.direction;if(n.allow_entry_in&&(n.allow_entry_in==="long"&&r===-1||n.allow_entry_in==="short"&&r===1))return!0;if(n.max_position_size!==void 0){let i=t.position_size+r*e.qty;if(Math.abs(i)>n.max_position_size)return!0}return!1}function Ly(t){if(t.risk_halted)return;let e=t.risk_rules;if(e.max_drawdown){let n=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=n){t.risk_halted=!0;return}}if(e.max_intraday_loss){let n=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>=n){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let n=0;for(let r=t.closedtrades.length-1;r>=0&&(t.closedtrades[r].profit??0)<0;r--)n++;n>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function Ar(t,e,n,r,i,s,a,o){let l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",p=o&&u==="cash_per_order",h=cl(t,l,r,i),d=p?h/2:h,f={id:`trade_${c}`,entry_id:e,entry_comment:a??e,entry_price:i,_bracket_entry:i,entry_bar_index:t.idx,entry_time:s,size:n*r,commission:d,max_drawdown:0,max_runup:0,status:"open"};l.opentrades.push(f),l._first_entry_price===void 0&&(l._first_entry_price=i),(l._ledger_entries??(l._ledger_entries=[])).push({entry_id:e,entry_price:i,entry_time:s,entry_bar_index:t.idx,entry_comment:f.entry_comment,qty:r,commission:d}),d>0&&(l.netprofit-=d,l.grossloss+=d);let m=y.from(t.data.high).get(0),_=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01,v=n===1?_:m,S=n===1?m:_;for(let N of l.pending_orders){if((N.category??"entry")!=="exit"||N.from_entry&&N.from_entry!==e)continue;let j;N.stop!==void 0?j=N.stop:N.loss!==void 0&&(j=n===1?i-N.loss*b:i+N.loss*b);let T;N.limit!==void 0?T=N.limit:N.profit!==void 0&&(T=n===1?i+N.profit*b:i-N.profit*b),n===1?(j!==void 0&&j>v&&(v=j),T!==void 0&&T<S&&(S=T)):(j!==void 0&&j<v&&(v=j),T!==void 0&&T>S&&(S=T))}let w=t.pine?.syminfo?.pointvalue??1,I=n===1?(i-v)*r*w:(v-i)*r*w,E=n===1?(S-i)*r*w:(i-S)*r*w;f.max_drawdown=Math.max(0,I)+d,f.max_runup=Math.max(0,E-d);let A=l.position_size,F=A+f.size;if(A===0)l.position_size=F,l.position_avg_price=i,l.position_entry_name=e;else if(Math.sign(A)===Math.sign(F)){let N=Math.abs(A)*l.position_avg_price+r*i,j=Math.abs(F);l.position_avg_price=N/j,l.position_size=F}ul(l)}function Fy(t,e,n,r){let i=t.strategy,s=nn(e.direction),a=i.position_size,o=Math.sign(a);if(o===1&&s===-1||o===-1&&s===1){let l=Math.min(Math.abs(a),e.qty),c=e.qty-l,u=c>0;if(fn(t,l,n,r,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0){let p=e._base_qty;p!==void 0&&c>p+1e-9?(Ar(t,e.id,s,p,n,r,e.comment,!0),Ar(t,e.id,s,c-p,n,r,e.comment,!0)):Ar(t,e.id,s,c,n,r,e.comment,!0)}}else Ar(t,e.id,s,e.qty,n,r,e.comment)}function By(t,e,n){let r=[],i=n,s=t._ledger_entries??[];for(let a of s){if(i<=1e-9)break;if(a.entry_id!==e.entry_id||a.qty<=1e-9)continue;let o=Math.min(a.qty,i),l=a.qty>0?a.commission*(o/a.qty):0;r.push({qty:o,entry_price:a.entry_price,entry_time:a.entry_time,entry_bar_index:a.entry_bar_index,entry_comment:a.entry_comment,commission:l}),a.qty-=o,a.commission-=l,i-=o}if(t._ledger_entries=s.filter(a=>a.qty>1e-9),i>1e-9){let a=Math.abs(e.size);r.push({qty:i,entry_price:e.entry_price,entry_time:e.entry_time,entry_bar_index:e.entry_bar_index,entry_comment:e.entry_comment,commission:a>0?(e.commission??0)*(i/a):0})}return r}function fn(t,e,n,r,i){let s=t.strategy,a=t.pine?.syminfo?.pointvalue??1,o=e,l=[...s.opentrades];s.opentrades=[];for(let h of l){if(o<=0){s.opentrades.push(h);continue}let d=Math.abs(h.size),f=Math.min(d,o),m=Math.sign(h.size),_=b=>{let v=s.config.commission_type??"percent",S=i?.isImplicitReversal&&v==="cash_per_order",w=cl(t,s,b,n),I=S?w/2:w,E=By(s,h,b);for(let A of E){let F=I*(A.qty/b),N=(m===1?n-A.entry_price:A.entry_price-n)*A.qty*a,j={id:`trade_${s.opentrades.length+s.closedtrades.length+l.length}`,entry_id:h.entry_id,entry_comment:A.entry_comment,entry_price:A.entry_price,_bracket_entry:h._bracket_entry,entry_bar_index:A.entry_bar_index,entry_time:A.entry_time,size:m*A.qty,commission:A.commission+F,max_drawdown:h.max_drawdown,max_runup:h.max_runup,status:"closed",exit_price:n,exit_bar_index:t.idx,exit_time:r,exit_id:i?.exitId??h.exit_id,exit_comment:i?.exitComment??h.exit_comment,profit:N-A.commission-F};i?.triggerKind==="loss"&&(j.max_runup=0),i?.triggerKind==="profit"&&(j.max_drawdown=A.commission),s.netprofit+=N-F,s.grossloss-=A.commission,j.profit>0?(s.grossprofit+=j.profit,s.wintrades++,s.wintrades_total_profit+=j.profit):j.profit<0?(s.grossloss+=Math.abs(j.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(j.profit)):s.eventrades++,s.closedtrades.push(j)}};if(f>=d-1e-9)h.status="closed",h.exit_price=n,h.exit_bar_index=t.idx,h.exit_time=r,_(d),o-=f;else{_(f);let b=(h.commission??0)*(f/d);h.size=m*(d-f),h.commission=(h.commission??0)-b,s.opentrades.push(h),o=0}}Ly(s);let c=s.position_size,u=Math.sign(c)*e,p=c-u;if(Math.abs(p)<1e-9&&(p=0),s.position_size=p,ul(s),p===0)s.position_avg_price=NaN,s.position_entry_name="";else if(s.opentrades.length>0){let h=0,d=0;for(let f of wi(s))h+=f.qty*f.entry_price,d+=f.qty;s.position_avg_price=h/d,s.position_entry_name=s.opentrades[0].entry_id}}function wi(t){let e=t._ledger_entries??[],n=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:n})):t.opentrades.map(r=>({qty:Math.abs(r.size),entry_price:r.entry_price,commission:r.commission??0,dir:Math.sign(r.size)}))}function Zr(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of wi(n)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*r}n.openprofit=i,n.equity=n.initial_capital+n.netprofit+i}function Vy(t,e,n){let r=t.strategy,i=t.pine?.syminfo?.pointvalue??1,s=r.initial_capital+r.netprofit,a=0;for(let f of wi(r))a+=f.commission;let o=s+a;o>r.equity_peak&&(r.equity_peak=o),s<r.equity_trough&&(r.equity_trough=s);let l=r.position_size,c=r.position_avg_price,u=0,p=0;if(l!==0&&Number.isFinite(c)){let f=l>0?n:e,m=l>0?e:n;u=l*(c-f)*i,p=l*(m-c)*i}let 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)){let f=100*h/r.equity_peak;f>r.max_drawdown_percent_value&&(r.max_drawdown_percent_value=f)}let d=s-r.equity_trough+p;if(d>r.max_runup&&(r.max_runup=d,r.equity_at_runup_peak=s+p,r.equity_at_runup_peak>0)){let f=100*d/r.equity_at_runup_peak;f>r.max_runup_percent_value&&(r.max_runup_percent_value=f)}}function oo(t,e,n,r,i,s,a){let o=t.strategy;if(a!==void 0){let h=[],d=[];for(let m of o.opentrades)m.id===a?h.push(m):d.push(m);if(h.length===0)return;let f=Math.abs(h[0].size);o.opentrades=[...h,...d],fn(t,Math.min(n,f),r,i,s);return}if(!e||e===""){fn(t,n,r,i,s);return}let l=[],c=[];for(let h of o.opentrades)h.entry_id===e?l.push(h):c.push(h);let u=l.reduce((h,d)=>h+Math.abs(d.size),0);if(u===0)return;let p=Math.min(n,u);o.opentrades=[...l,...c],fn(t,p,r,i,s)}function Wy(t,e="intrabar"){if(!t.strategy)return;let n=t.strategy;if(n.pending_orders.length===0)return;let r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.mintick??.01;for(let c of n.pending_orders){if(c.status!=="pending"||(c.category??"entry")!=="exit")continue;let u=n.opentrades.filter(T=>!c.from_entry||T.entry_id===c.from_entry);if(c._intended_trade_ids){let T=new Set(c._intended_trade_ids);u=u.filter(q=>T.has(q.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}let p=u.reduce((T,q)=>T+Math.abs(q.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 T=c.immediately?a:r;T=_s(t,-h,T);let q=p;c.qty&&c.qty>0?q=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(q=p*(c.qty_percent/100)),oo(t,c.from_entry,q,T,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=T,c.fill_bar=t.idx,c.fill_time=o;continue}let d=0;for(let T of u)d+=Math.abs(T.size)*T.entry_price;let f=d/p,m=h===1,_=c.limit,b=c.stop;c._isPersistent||(b!==void 0&&((m?b<f:b>f)||(b=void 0)),_!==void 0&&((m?_>f:_<f)||(_=void 0))),c._attachedAtReversal&&!c._isPersistent&&(c.limit!==void 0&&(_=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 T;c.trail_price!==void 0?T=c.trail_price:c.trail_points!==void 0&&(T=m?f+c.trail_points*l:f-c.trail_points*l),T!==void 0&&(m?i>=T:s<=T)&&(c.trail_armed=!0,c.trail_peak=m?i:s,v=!0)}let S=Math.abs(i-r)<=Math.abs(r-s),w=m?S:!S,I=[],E=[],A=n._mc_exit_lock,F=A&&A.bar===t.idx;for(let T of u){if(F&&T.id!==A.tradeId)continue;let q=T._bracket_entry??T.entry_price,B=Math.abs(T.size),O=_;O===void 0&&c.profit!==void 0&&(O=m?q+c.profit*l:q-c.profit*l);let K=b;K===void 0&&c.loss!==void 0&&(K=m?q-c.loss*l:q+c.loss*l);let ae=O!==void 0&&(e==="open"?m?r>=O:r<=O:m?i>=O:s<=O),ke=K!==void 0&&(e==="open"?m?r<=K:r>=K:m?s<=K:i>=K),he=null;if(ae&&ke?he=w?"profit":"loss":ae?he="profit":ke&&(he="loss"),he==="loss"){let je=m?r<=K:r>=K;!m&&je&&T.entry_bar_index===t.idx?ae&&(he="profit"):E.push({qty:B,price:je?r:K,kind:"loss",tradeId:T.id})}if(he==="profit"){let je=m?r>=O:r<=O;I.push({qty:B,price:je?r:O,kind:"profit",tradeId:T.id})}}I.sort((T,q)=>m?T.price-q.price:q.price-T.price),E.sort((T,q)=>m?q.price-T.price:T.price-q.price);let N=null;if(e==="intrabar"&&!F&&c.trail_armed&&c.trail_offset!==void 0){let T=()=>{m?c.trail_peak=Math.max(c.trail_peak??-1/0,i):c.trail_peak=Math.min(c.trail_peak??1/0,s)},q=()=>m?c.trail_peak-c.trail_offset*l:c.trail_peak+c.trail_offset*l,B=O=>{N={qty:1/0,price:O,kind:"trailing"}};if(v){let O=q();w?(m?s<=O:i>=O)&&B(O):(m?a<=O:a>=O)&&B(O)}else if(w){T();let O=q();(m?s<=O:i>=O)&&B(O)}else{let O=q();if(m?s<=O:i>=O)B(O);else{T();let K=q();(m?a<=K:a>=K)&&B(K)}}}let j=w?[...I,...E,...N?[N]:[]]:[...E,...N?[N]:[],...I];if(j.length>0){let T=p;c.qty&&c.qty>0?T=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(T=p*(c.qty_percent/100));let q=()=>n.opentrades.filter(K=>!c.from_entry||K.entry_id===c.from_entry).reduce((K,ae)=>K+Math.abs(ae.size),0),B=NaN,O=!1;for(let K of j){if(T<=1e-9)break;let ae=q();if(ae<=1e-9)break;let ke=Math.min(K.qty===1/0?ae:K.qty,T,ae),he=_s(t,-h,K.price),je=K.kind==="profit"?c.comment_profit??c.comment:K.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;oo(t,c.from_entry,ke,he,o,{triggerKind:K.kind,exitId:c.id,exitComment:je},K.tradeId),T-=ke,B=he,O=!0}O&&(q()<=1e-9||T<=1e-9)&&(c.status="filled",c.fill_price=B,c.fill_bar=t.idx,c.fill_time=o)}}n.pending_orders=n.pending_orders.filter(c=>c.status==="pending"),Zr(t,a)}function $y(t){let e=t.strategy;if(!e)return;let n=e._pending_close_mc;if(n&&(e._pending_close_mc=null,!(e.opentrades.length===0||Math.sign(e.position_size)!==n.dir)&&(fn(t,Math.min(n.qty,Math.abs(e.position_size)),n.price,n.time,{exitId:"Margin call",exitComment:"Margin call"}),Math.abs(e.position_size)>1e-9))){for(let r of e.pending_orders)r.status==="pending"&&(r.category??"entry")==="entry"&&!r._isReversalEntry&&nn(r.direction)===n.dir&&(r.status="cancelled");e.pending_orders=e.pending_orders.filter(r=>r.status==="pending")}}function jy(t){let e=t.strategy,n=Math.sign(e?.position_size??0);if(n===0)return!1;let r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=Math.abs(i-r)<=Math.abs(r-s);return n===1?!a:a}function Yi(t,e="extreme"){let n=t.strategy;if(!n||n.opentrades.length===0)return;let r=Math.sign(n.position_size);if(r===0)return;let i=r===1?n.config.margin_long??100:n.config.margin_short??100,s=y.from(t.data.open).get(0),a=y.from(t.data.high).get(0),o=y.from(t.data.low).get(0),l=y.from(t.data.close).get(0),c=y.from(t.data.openTime).get(0),u=t.pine?.syminfo?.pointvalue??1,p=e==="open"?s:e==="close"?l:r===1?o:a,h=Math.abs(n.position_size),d=Ty(t,p),f=Xr(h,p,i,u);if(d<f){let m=f-d,_=i/100,b=m/(p*u*_),v=Math.min(h,4*b),S=[...n.opentrades],w=S[0],I=Math.abs(w.size),E=w.entry_price;if(fn(t,v,p,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&v>=I-1e-9&&Math.abs(n.position_size)>1e-9){let F=Xr(I,p,i,u),N=I*(p-E)*r*u,j=m-F+N;if(j>0){let T=y.from(t.data.close).get(0),q=(O=>Math.trunc(O*1e6)/1e6)(j/(p*u*_)),B=Math.min(Math.abs(n.position_size),4*q);B>1e-9&&(n._pending_close_mc={qty:B,price:T,time:c,dir:r})}}let A=S.find(F=>F.status==="open");n._mc_exit_lock={bar:t.idx,tradeId:A?.id??null}}}function Uy(t){if(!t.strategy)return;let e=t.strategy,n=y.from(t.data.high).get(0),r=y.from(t.data.low).get(0),i=y.from(t.data.close).get(0);Zr(t,i),Vy(t,n,r);let s=y.from(t.data.openTime).get(0);if(Number.isFinite(s)){let a=new Date(s),o=a.getUTCFullYear()*12+a.getUTCMonth(),l=e._monthly_equity??(e._monthly_equity=[]);e._last_month_key===o&&l.length>0?l[l.length-1]=e.equity:(l.push(e.equity),e._last_month_key=o)}}function zy(t){let e=t?.strategy;if(!e)return;e.cagr=Hy(t),Ky(t);let n=e._monthly_equity??[],r=[e.initial_capital,...n],i=[];for(let d=1;d<r.length;d++){let f=r[d-1];f!==0&&Number.isFinite(f)&&Number.isFinite(r[d])&&i.push(r[d]/f-1)}if(i.length<2){e.sharpe_ratio=0,e.sortino_ratio=0;return}let s=(e.config.risk_free_rate??2)/100/12,a=i.length,o=i.reduce((d,f)=>d+f,0)/a,l=o-s,c=i.reduce((d,f)=>d+(f-o)**2,0)/a,u=Math.sqrt(c),p=i.reduce((d,f)=>d+Math.min(0,f-s)**2,0)/a,h=Math.sqrt(p);e.sharpe_ratio=u>0?l/u:0,e.sortino_ratio=h>0?l/h:0}var qy=1440*60*1e3;function Hy(t){let e=t?.strategy;if(!e)return NaN;let n=t?.marketData;if(!Array.isArray(n)||n.length===0)return NaN;let r=n[0]?.openTime,i=n[n.length-1]?.openTime;if(!Number.isFinite(r)||!Number.isFinite(i))return NaN;let s=e.initial_capital??0,a=s+(e.netprofit??0),o=(i-r)/qy;if(o<1||!Number.isFinite(s)||!Number.isFinite(a)||s===0)return NaN;let l=o/365;return 100*(Math.pow(a/s,1/l)-1)}function Ky(t){let e=t?.strategy;if(!e)return;let n=e._first_entry_price,r=t?.marketData,i=Array.isArray(r)&&r.length>0?r[r.length-1]?.close:NaN;if(!Number.isFinite(n)||!Number.isFinite(i)||n===0){e.buy_and_hold_pnl=NaN,e.buy_and_hold_per_gain=NaN,e.strategy_outperformance=NaN;return}let s=n,a=(i-s)/s;e.buy_and_hold_per_gain=a*100,e.buy_and_hold_pnl=(e.initial_capital??0)*a,e.strategy_outperformance=(e.netprofit??0)-e.buy_and_hold_pnl}function Yy(t){t.strategy}function Gy(t,e){let n={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=n.initial_capital;t.strategy={config:n,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:r,account_currency:n.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,cagr:NaN,buy_and_hold_pnl:NaN,buy_and_hold_per_gain:NaN,strategy_outperformance:NaN,_first_entry_price:void 0,_monthly_equity:[],_last_month_key:-1,wintrades:0,losstrades:0,eventrades:0,wintrades_total_profit:0,losstrades_total_loss:0,max_contracts_held_all:0,max_contracts_held_long:0,max_contracts_held_short:0,risk_rules:{},risk_halted:!1,_exit_call_history:new Map,_exit_fallback_counter:0,_exit_fallback_last_bar:-1}}function nr(t){if(Array.isArray(t))return t.map(nr);if(t instanceof Map){let e=new Map;return t.forEach((n,r)=>e.set(r,nr(n))),e}if(t!==null&&typeof t=="object"){let e={};for(let n of Object.keys(t))e[n]=nr(t[n]);return e}return t}function Xy(t){if(!t)return null;let e={};for(let n of Object.keys(t))n==="config"||n==="closedtrades"||(e[n]=nr(t[n]));return{fields:e,closedtradesLength:t.closedtrades.length}}function Zy(t,e){if(!(!t||!e)){for(let n of Object.keys(t))n==="config"||n==="closedtrades"||Object.prototype.hasOwnProperty.call(e.fields,n)||delete t[n];t.closedtrades.length>e.closedtradesLength&&(t.closedtrades.length=e.closedtradesLength);for(let n of Object.keys(e.fields))t[n]=nr(e.fields[n])}}function Qy(t){return(...e)=>{let n=My(e);return t.strategy?t.strategy.config={...t.strategy.config,...n,...t._propOverrides??{}}:Gy(t,n),t.strategy.config}}var Jy=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],eg={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 tg(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let n=ye(e,Jy,eg),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,i=r(n.id),s=r(n.direction),a=r(n.qty),o=r(n.limit),l=r(n.stop),c=r(n.oca_name),u=r(n.oca_type),p=r(n.comment),h=nn(s),d=y.from(t.data.close).get(0),f=aa(t,a,h,d),m="market";o!==void 0&&l!==void 0?m="stop-limit":o!==void 0?m="limit":l!==void 0&&(m="stop");let _=y.from(t.data.openTime).get(0),b={id:i,direction:h,qty:f,type:m,limit:o,stop:l,bar:t.idx,time:_,status:"pending",oca_name:c,oca_type:u,comment:p};return t.strategy.pending_orders.push(b),b}}function ng(t){return(e,n)=>y.from(e).get(n||0)}function rg(t){return()=>{let e=(t.strategy?.opentrades??[]).slice(),n=h=>e[Number(h)],r=()=>{let h=t.marketData;return Array.isArray(h)&&t.idx>=0&&t.idx<h.length?h[t.idx]?.close??NaN:NaN},i={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},s=t.pine?.syminfo?.pointvalue??1,a=(h,d)=>{let f=t.strategy?.config,m=f?.commission_type??"percent",_=f?.commission_value??0;if(!_)return 0;let b=Math.abs(h.size);switch(m){case"percent":return b*d*s*(_/100);case"cash_per_contract":return b*_;case"cash_per_order":return _;default:return 0}},o=h=>Math.abs(h.size)*h.entry_price*s+(h.commission??0);i.profit=h=>{let d=n(h);if(!d)return NaN;let f=r();return Number.isFinite(f)?(Math.sign(d.size)===1?f-d.entry_price:d.entry_price-f)*Math.abs(d.size)*s-(d.commission??0)-a(d,f):NaN},i.profit_percent=h=>{let d=n(h);if(!d)return NaN;let f=i.profit(h);if(!Number.isFinite(f))return NaN;let m=o(d);return m>0?100*f/m:NaN},i.size=h=>n(h)?.size??NaN,i.commission=h=>n(h)?.commission??NaN,i.entry_price=h=>n(h)?.entry_price??NaN,i.entry_bar_index=h=>n(h)?.entry_bar_index??NaN,i.entry_id=h=>n(h)?.entry_id??"",i.entry_comment=h=>n(h)?.entry_comment??n(h)?.entry_id??"",i.entry_time=h=>n(h)?.entry_time??NaN,i.max_drawdown=h=>n(h)?.max_drawdown??0,i.max_drawdown_percent=h=>{let d=n(h);if(!d||!d.max_drawdown)return 0;let f=o(d);return f>0?100*d.max_drawdown/f:0},i.max_runup=h=>n(h)?.max_runup??0,i.max_runup_percent=h=>{let d=n(h);if(!d||!d.max_runup)return 0;let f=o(d);return f>0?100*d.max_runup/f:0};let l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,p=c!==100||u!==100;if(!l||l.opentrades.length===0||!p)i.capital_held=NaN;else{let h=0;for(let d of l.opentrades){let f=Math.abs(d.size)*d.entry_price,m=d.size>0?c:u;h+=f*(m/100)}i.capital_held=h}return i}}function ig(t){return()=>{let e=(t.strategy?.closedtrades??[]).slice(),n=a=>e[Number(a)],r={valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},i=t.pine?.syminfo?.pointvalue??1,s=a=>{let o=Math.abs(a.size)*a.entry_price*i,l=(a.commission??0)/2;return o+l};return r.profit=a=>n(a)?.profit??NaN,r.profit_percent=a=>{let o=n(a);if(!o||o.profit===void 0)return NaN;let l=s(o);return l>0?100*o.profit/l:NaN},r.size=a=>n(a)?.size??NaN,r.commission=a=>n(a)?.commission??NaN,r.entry_price=a=>n(a)?.entry_price??NaN,r.entry_bar_index=a=>n(a)?.entry_bar_index??NaN,r.entry_id=a=>n(a)?.entry_id??"",r.entry_comment=a=>n(a)?.entry_comment??n(a)?.entry_id??"",r.entry_time=a=>n(a)?.entry_time??NaN,r.exit_price=a=>n(a)?.exit_price??NaN,r.exit_bar_index=a=>n(a)?.exit_bar_index??NaN,r.exit_id=a=>n(a)?.exit_id??"",r.exit_comment=a=>n(a)?.exit_comment??n(a)?.exit_id??"",r.exit_time=a=>n(a)?.exit_time??NaN,r.max_drawdown=a=>n(a)?.max_drawdown??0,r.max_drawdown_percent=a=>{let o=n(a);if(!o||!o.max_drawdown)return 0;let l=s(o);return l>0?100*o.max_drawdown/l:0},r.max_runup=a=>n(a)?.max_runup??0,r.max_runup_percent=a=>{let o=n(a);if(!o||!o.max_runup)return 0;let l=s(o);return l>0?100*o.max_runup/l:0},r.first_index=0,r}}function sg(t){return()=>t.strategy?.netprofit??0}function ag(t){return()=>t.strategy?.position_size??0}function og(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function lg(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function cg(t){return()=>"long"}function ug(t){return()=>"short"}function hg(t){return()=>"cash"}function pg(t){return()=>"percent_of_equity"}function dg(t){return()=>"fixed"}function fg(t){return()=>t.strategy?.openprofit??0}function mg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function yg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function gg(t){return()=>t.strategy?.grossprofit??0}function xg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function _g(t){return()=>t.strategy?.grossloss??0}function bg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function vg(t){return()=>t.strategy?.wintrades??0}function wg(t){return()=>t.strategy?.losstrades??0}function Sg(t){return()=>t.strategy?.eventrades??0}function Eg(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function Cg(t){return()=>{let e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let n=0;for(let r of e.closedtrades){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.closedtrades.length}}function Ig(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function Ng(t){return()=>{let e=t.strategy;if(!e||e.wintrades===0)return NaN;let n=0;for(let r of e.closedtrades)if((r.profit??0)>0){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.wintrades}}function kg(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function Ag(t){return()=>{let e=t.strategy;if(!e||e.losstrades===0)return NaN;let n=0;for(let r of e.closedtrades)if((r.profit??0)<0){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.losstrades}}function Mg(t){return()=>t.strategy?.max_drawdown??0}function Tg(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function Pg(t){return()=>t.strategy?.max_runup??0}function Dg(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function Rg(t){return()=>t.strategy?.max_contracts_held_all??0}function Og(t){return()=>t.strategy?.max_contracts_held_long??0}function Lg(t){return()=>t.strategy?.max_contracts_held_short??0}function Fg(t){return()=>t.strategy?.position_entry_name??""}function Bg(t){return()=>t.strategy?.initial_capital??0}function Vg(t){return()=>t.strategy?.account_currency??"USD"}function Wg(t){return()=>{let e=t.strategy;if(!e||e.position_size===0)return NaN;let n=e.position_avg_price;if(!Number.isFinite(n))return NaN;let r=Math.sign(e.position_size),i=r===1?e.config.margin_long??100:e.config.margin_short??100;if(i>=100)return NaN;let s=Math.abs(e.position_size),a=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(a*s)-r*n,l=i/100-r,c=o/l,u=t.pine?.syminfo?.mintick??.01;return r===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}var $g=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],jg={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 Ug(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let n=ye(e,$g,jg),r=N=>N==null||typeof N=="string"||typeof N=="number"||typeof N=="boolean"?N:typeof N=="function"?N():N instanceof y?N.get(0):Array.isArray(N)?N[N.length-1]:typeof N=="object"&&N.get!==void 0?N.get(0):N,i=r(n.id),s=r(n.direction),a=r(n.qty),o=r(n.limit),l=r(n.stop),c=r(n.oca_name),u=r(n.oca_type),p=r(n.comment),h=nn(s),d=t.strategy,f=d.position_size;for(let N of d.pending_orders)N.bar===t.idx&&N.category==="entry"&&N.type==="market"&&(f+=nn(N.direction)*N.qty);if(Math.sign(f)===h&&f!==0&&Ry(d,h))return;let m=y.from(t.data.close).get(0),_=aa(t,a,h,m),b=f!==0&&Math.sign(f)!==h,v=b?Math.abs(f)+_:_,S="market";o!==void 0&&l!==void 0?S="stop-limit":o!==void 0?S="limit":l!==void 0&&(S="stop");let w=t.pine?.syminfo?.mintick??0,I=o!==void 0?tr(o,m,w):void 0,E=l!==void 0?tr(l,m,w):void 0,A=y.from(t.data.openTime).get(0),F={id:i,direction:h,qty:v,type:S,limit:I,stop:E,bar:t.idx,time:A,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:p,_isReversalEntry:b,_base_qty:_};d.pending_orders.push(F)}}var zg=[["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"]],qg={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 Hg(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let n=St(e);if(n===void 0){let B=t.strategy;B._exit_fallback_last_bar!==t.idx&&(B._exit_fallback_counter=0,B._exit_fallback_last_bar=t.idx),n=`exit_raw_${B._exit_fallback_counter++}`}let r=ye(e,zg,qg),i=B=>B==null||typeof B=="string"||typeof B=="number"||typeof B=="boolean"?B:typeof B=="function"?B():B instanceof y?B.get(0):Array.isArray(B)?B[B.length-1]:typeof B=="object"&&B.get!==void 0?B.get(0):B,s=i(r.id),a=i(r.from_entry),o=i(r.qty),l=i(r.qty_percent),c=i(r.profit),u=i(r.limit),p=i(r.loss),h=i(r.stop),d=i(r.trail_price),f=i(r.trail_points),m=i(r.trail_offset),_=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),v=u!==void 0?tr(u,b,_):void 0,S=h!==void 0?tr(h,b,_):void 0,w=d!==void 0?tr(d,b,_):void 0,I=a??"",E=!!(I?t.strategy.pending_orders.find(B=>B.category==="entry"&&B.id===I&&B.status==="pending"):t.strategy.pending_orders.find(B=>B.category==="entry"&&B.status==="pending"))?._isReversalEntry,A=t.strategy._exit_call_history,F=A.get(n),N=F!==void 0&&F===t.idx-1;A.set(n,t.idx);let j={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:I,profit:c,loss:p,limit:v,stop:S,trail_price:w,trail_points:f,trail_offset:m,oca_name:i(r.oca_name),comment:i(r.comment),comment_profit:i(r.comment_profit),comment_loss:i(r.comment_loss),comment_trailing:i(r.comment_trailing),alert_message:i(r.alert_message),alert_profit:i(r.alert_profit),alert_loss:i(r.alert_loss),alert_trailing:i(r.alert_trailing),disable_alert:i(r.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:E,_isPersistent:N,_callsiteId:n},T=j.id,q=t.strategy.pending_orders;for(let B=q.length-1;B>=0;B--){let O=q[B];O.category==="exit"&&O.id===T&&(O.from_entry??"")===(j.from_entry??"")&&O.status==="pending"&&(O.trail_armed&&(j.trail_armed=!0,j.trail_peak=O.trail_peak),q.splice(B,1))}q.push(j)}}var Kg=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],Yg={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Gg(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let n=ye(e,Kg,Yg),r=n.id;if(r==null||!t.strategy.opentrades.some(o=>o.entry_id===r))return;let i=o=>(o.category??"entry")==="exit"&&(o.profit!==void 0||o.loss!==void 0||o.limit!==void 0||o.stop!==void 0||o.trail_price!==void 0||o.trail_points!==void 0),s=t.strategy.pending_orders;for(let o of s)i(o)&&(o.from_entry??"")===r&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=s.filter(o=>o.status==="pending");let 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:n.qty_percent,comment:n.comment,alert_message:n.alert_message,immediately:n.immediately===!0,disable_alert:n.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===r).map(o=>o.id)};n.qty!==void 0&&(a.qty=Math.abs(Number(n.qty))),t.strategy.pending_orders.push(a)}}var Xg=[["comment","alert_message","immediately","disable_alert"]],Zg={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function Qg(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let n=ye(e,Xg,Zg);if(t.strategy.opentrades.length===0)return;let 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),i=t.strategy.pending_orders;for(let a of i)r(a)&&a.status==="pending"&&(a.status="cancelled");t.strategy.pending_orders=i.filter(a=>a.status==="pending");let s={id:"close_all",direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:"",comment:n.comment,alert_message:n.alert_message,immediately:n.immediately===!0,disable_alert:n.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(a=>a.id)};t.strategy.pending_orders.push(s)}}var Jg=[["id","immediately"]],e0={id:"string",immediately:"boolean"};function t0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let n=ye(e,Jg,e0).id;n!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===n)))}}function n0(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 r0(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,n)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:n})},max_drawdown:(e,n,r)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:n})},max_intraday_filled_orders:(e,n)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:n})},max_intraday_loss:(e,n,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:n})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function i0(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function s0(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function a0(t){return e=>t.strategy?aa(t,void 0,1,e):0}var o0={any:Qy,order:tg,param:ng,opentrades:rg,closedtrades:ig,netprofit:sg,position_size:ag,position_avg_price:og,equity:lg,long:cg,short:ug,cash:hg,percent_of_equity:pg,fixed:dg,openprofit:fg,openprofit_percent:mg,netprofit_percent:yg,grossprofit:gg,grossprofit_percent:xg,grossloss:_g,grossloss_percent:bg,wintrades:vg,losstrades:wg,eventrades:Sg,avg_trade:Eg,avg_trade_percent:Cg,avg_winning_trade:Ig,avg_winning_trade_percent:Ng,avg_losing_trade:kg,avg_losing_trade_percent:Ag,max_drawdown:Mg,max_drawdown_percent:Tg,max_runup:Pg,max_runup_percent:Dg,max_contracts_held_all:Rg,max_contracts_held_long:Og,max_contracts_held_short:Lg,position_entry_name:Fg,initial_capital:Bg,account_currency:Vg,margin_liquidation_price:Wg,entry:Ug,exit:Hg,close:Gg,close_all:Qg,cancel:t0,cancel_all:n0,convert_to_account:i0,convert_to_symbol:s0,default_entry_qty:a0},l0={long:"long",short:"short",all:"all"},c0={none:"none",cancel:"cancel",reduce:"reduce"},u0={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},bs=class{constructor(e){this.context=e,Object.entries(o0).forEach(([r,i])=>{this[r]=i(e)}),this.direction=()=>l0,this.oca=()=>c0,this.commission=()=>u0;let n=r0(e);this.risk=()=>n}};function h0(t,e){let n=e.trim();if(n==="UTC"||n==="GMT"||n==="Etc/UTC")return 0;let r=n.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(r){let a=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return a*(o*60+l)}let i=rn(t,e),s=new Date(Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second));return Math.round((s.getTime()-t)/6e4)}function p0(t,e){let n=e>=0?"+":"-",r=s=>String(Math.floor(Math.abs(s))).padStart(2,"0"),i=n+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${i}]`}var vs=class{constructor(e){this.context=e}logFormat(e,...n){return e.replace(/{(\\d+)}/g,(r,i)=>n[i])}param(e,n=0,r){return y.from(e).get(n)}_formatTimestamp(){let e=this.context.data.openTime.data[this.context.idx],n=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=h0(e,n);return p0(e,r)}warning(e,...n){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}error(e,...n){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}info(e,...n){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}},ws=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}error(e){let n=y.from(e).get(0);throw new zr(typeof n=="string"?n:String(n??""),"runtime.error")}},d0=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f0=["January","February","March","April","May","June","July","August","September","October","November","December"],m0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y0=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],rt=(t,e)=>String(t).padStart(e,"0"),Ss=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}tostring(e,n){if(typeof e!="number"||isNaN(e)||!n)return String(e);if(n==="mintick"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(n==="integer")return String(Math.round(e));if(n==="percent")return(e*100).toFixed(2)+"%";if(n==="price"){let i=this.context.pine?.syminfo?.mintick||.01,s=Math.max(0,-Math.floor(Math.log10(i)));return e.toFixed(s)}if(n==="volume")return String(Math.round(e));let r=n.indexOf(".");if(r>=0){let i=n.substring(r+1).length;return e.toFixed(i)}return n.includes("#")||n.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,n,r=""){return Array(n).fill(e).join(r||"")}replace_all(e,n,r){return String(e).replaceAll(n,r)}replace(e,n,r,i=0){let s=String(e),a=String(n),o=String(r),l=Math.floor(Number(i))||0;if(a==="")return s;let c=0,u=0;for(;;){let 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,n){return String(e).includes(n)}endswith(e,n){return String(e).endsWith(n)}startswith(e,n){return String(e).startsWith(n)}pos(e,n){let r=String(e).indexOf(n);return r===-1?NaN:r}length(e){return String(e).length}match(e,n){return String(e).match(new RegExp(n))}split(e,n){return new Y(String(e).split(n),G.string,this.context)}substring(e,n,r){return String(e).substring(n,r)}format_time(e,n="yyyy-MM-dd\'T\'HH:mm:ssZ",r){if(e==null||typeof e=="number"&&isNaN(e))return"NaN";let i=Number(e),s=r||this.context.pine?.syminfo?.timezone||"UTC",a=rn(i,s),o=Date.UTC(a.year,a.month-1,a.day,a.hour,a.minute,a.second),l=Math.round((o-i)/6e4),c=Date.UTC(a.year,0,1),u=Math.floor((o-c)/864e5)+1,p=a.hour%12===0?12:a.hour%12,h="",d=0;for(;d<n.length;){let f=n[d];if(f==="\'"){if(n[d+1]==="\'"){h+="\'",d+=2;continue}let m=n.indexOf("\'",d+1);if(m===-1){h+=n.substring(d+1);break}h+=n.substring(d+1,m),d=m+1;continue}if(f>="a"&&f<="z"||f>="A"&&f<="Z"){let m=1;for(;n[d+m]===f;)m++;switch(d+=m,f){case"y":h+=m===2?rt(a.year%100,2):m>=4?rt(a.year,4):String(a.year);break;case"M":m>=4?h+=f0[a.month-1]:m===3?h+=d0[a.month-1]:m===2?h+=rt(a.month,2):h+=String(a.month);break;case"d":h+=m===2?rt(a.day,2):String(a.day);break;case"D":h+=m>=3?rt(u,3):m===2?rt(u,2):String(u);break;case"E":h+=m>=4?y0[a.dayOfWeek]:m0[a.dayOfWeek];break;case"a":h+=a.hour<12?"AM":"PM";break;case"h":h+=m===2?rt(p,2):String(p);break;case"H":h+=m===2?rt(a.hour,2):String(a.hour);break;case"m":h+=m===2?rt(a.minute,2):String(a.minute);break;case"s":h+=m===2?rt(a.second,2):String(a.second);break;case"S":{let _=i-Math.floor(i/1e3)*1e3;h+=rt(_,3).substring(0,m);break}case"Z":{let _=l>=0?"+":"-",b=Math.abs(l);h+=`${_}${rt(Math.floor(b/60),2)}${rt(b%60,2)}`;break}default:h+=f.repeat(m)}continue}h+=f,d++}return h}format(e,...n){return e.replace(/\\{(\\d+)(?:,number,([^}]+))?\\}/g,(r,i,s)=>{let a=n[i];return s&&typeof a=="number"&&!isNaN(a)?this.tostring(a,s):String(a)})}},g0=Object.defineProperty,x0=(t,e,n)=>e in t?g0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,_0=(t,e,n)=>x0(t,typeof e!="symbol"?e+"":e,n),Mr={"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 lo(t){if(!t||/^\\d+$/.test(t))return t;if(Mr[t])return Mr[t];let e=t.toLowerCase();if(Mr[e])return Mr[e];if(t.length===1){let r=t.toUpperCase();if(["D","W","M","S"].includes(r))return r}let n=t.slice(-1).toUpperCase();if(["D","W","M","S"].includes(n)){let r=parseInt(t);if(!isNaN(r))return r+n}return t}var Es=class{constructor(e){this.context=e,_0(this,"_normalized",null)}param(e,n=0,r){return y.from(e).get(n)}get normalized(){return this._normalized===null&&(this._normalized=lo(this.context.timeframe)),this._normalized}get unit(){return this.normalized.slice(-1).toUpperCase()}get main_period(){return this.normalized}get period(){return this.normalized}get multiplier(){let e=parseInt(this.normalized);return isNaN(e)?1:e}get isdwm(){return["D","W","M"].includes(this.unit)}get isdaily(){return this.unit==="D"}get isweekly(){return this.unit==="W"}get ismonthly(){return this.unit==="M"}get isseconds(){return this.unit==="S"}get isminutes(){return/^\\d+$/.test(this.normalized)}get isintraday(){return!this.isdwm}change(e){let n=typeof e=="function"?e():e,r=n instanceof y?n.get(0):n,i=os(r||"");if(!i)return!1;let s=y.from(this.context.data.openTime).get(0),a=y.from(this.context.data.openTime).get(1);if(isNaN(s)||isNaN(a))return!1;let o=ls(s,i),l=ls(a,i);return o!==l}from_seconds(e){return e<60?Math.ceil(e/5)*5+"S":e<3600*24?Math.ceil(e/60):e<=3600*24*7*52?e%(3600*24*7)===0?Math.ceil(e/604800)+"W":Math.ceil(e/(3600*24))+"D":"12M"}in_seconds(e){e==null?e=this.normalized:e=lo(e);let n=e.slice(-1).toUpperCase(),r=parseInt(e);return n==="S"?isNaN(r)?1:r:n==="D"?(isNaN(r)?1:r)*60*60*24:n==="W"?(isNaN(r)?1:r)*60*60*24*7:n==="M"?(isNaN(r)?1:r)*60*60*24*30:isNaN(r)?0:r*60}},b0=Object.defineProperty,v0=Object.getOwnPropertyDescriptor,Rt=(t,e,n,r)=>{for(var i=r>1?void 0:r?v0(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&b0(e,n,i),i},w0=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],S0=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],E0={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"},C0=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],I0=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],N0=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],k0=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],co=["color","offset","editable","show_last","title","display","force_overlay"],A0=["price","title","color","linestyle","linewidth","editable","display"],M0=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],T0={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"},P0={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"},D0={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"},R0={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"},O0={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"},uo={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},L0={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},F0={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},Et=class{constructor(e){this.context=e}_resolvePlotKey(e,n){if(e){let r=this.context.plots[e];return!r||!n||r._callsiteId===n?e:e+n}return n||"plot"}extractPlotOptions(e){let n={};for(let r in e)n[r]=y.from(e[r]).get(0);return n}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,n=0,r){return y.from(e).get(n)}plotchar(...e){let n=St(e),r=ye(e,S0,E0),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:s,_plotKey:l,_callsiteId:n});let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){let n=St(e),r=ye(e,w0,T0),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n),c="color"in a;if(!this.context.plots[l]){let d=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:d},title:s,_plotKey:l,_callsiteId:n}}let u=y.from(i).get(0),p=o.color;typeof p=="function"&&(p=p());let 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){let n=St(e),r=ye(e,C0,P0),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n);if(!this.context.plots[l]){let u=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:u},title:s,_plotKey:l,_callsiteId:n}}let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){let n=St(e),r=ye(e,I0,D0),{series:i,title:s,...a}=r,o=y.from(i).get(0),l=this.extractPlotOptions(a),c=this._resolvePlotKey(s,n);if(!this.context.plots[c]){let u=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:u},title:s,_plotKey:c,_callsiteId:n}}return this.context.plots[c].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){let n=St(e),r=ye(e,N0,R0),{open:i,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,n);if(!this.context.plots[p]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"bar",overlay:d},title:l,_plotKey:p,_callsiteId:n}}let h=[y.from(i).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){let n=St(e),r=ye(e,k0,O0),{open:i,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,n);if(!this.context.plots[p]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"candle",overlay:d},title:l,_plotKey:p,_callsiteId:n}}let h=[y.from(i).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){let n=St(e),r=ye(e,co,uo),{title:i,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,n);if(!this.context.plots[o]){let l=a.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...a,style:"background",overlay:l},title:i,_plotKey:o,_callsiteId:n}}this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}})}barcolor(...e){let n=St(e),r=ye(e,co,uo),{title:i,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,n);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...a,style:"barcolor"},title:i,_plotKey:o,_callsiteId:n}),this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}}),this.context.plots[o]}};Rt([M],Et.prototype,"plotchar",1),Rt([M],Et.prototype,"any",1),Rt([M],Et.prototype,"plotshape",1),Rt([M],Et.prototype,"plotarrow",1),Rt([M],Et.prototype,"plotbar",1),Rt([M],Et.prototype,"plotcandle",1),Rt([M],Et.prototype,"bgcolor",1),Rt([M],Et.prototype,"barcolor",1);var Qr=class{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=St(e),r=ye(e,A0,L0),{price:i,title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u}=r,p=[i,{title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return n&&p.push({__callsiteId:n}),this.context.pine.plot.any(...p)}};Rt([M],Qr.prototype,"any",1);var Jr=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=St(e),r=e.length>=6&&typeof e[2]=="number",i=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||i!==null){let s=e[0],a=e[1],o=i?y.from(i.top_value).get(0):e[2],l=i?y.from(i.bottom_value).get(0):e[3],c=i?y.from(i.top_color).get(0):e[4],u=i?y.from(i.bottom_color).get(0):e[5],p=i?i.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,h=s?._plotKey||s?.title,d=a?._plotKey||a?.title,f=p||"fill",m=this.context.plots[f];m&&n&&m._callsiteId!==n&&(f=n),this.context.plots[f]||(this.context.plots[f]={title:p||"Fill",plot1:h,plot2:d,data:[],options:{plot1:h,plot2:d,style:"fill",gradient:!0},_plotKey:f,_callsiteId:n}),this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:u}})}else{let s=ye(e,M0,F0),{plot1:a,plot2:o,color:l,title:c,editable:u,show_last:p,fillgaps:h,display:d}=s,f=c||"fill",m=this.context.plots[f];m&&n&&m._callsiteId!==n&&(f=n);let _=y.from(l).get(0);if(!this.context.plots[f]){let b=a?._plotKey||a?.title,v=o?._plotKey||o?.title;this.context.plots[f]={title:c||"Fill",plot1:b,plot2:v,data:[],options:{plot1:b,plot2:v,color:_,editable:u,show_last:p,fillgaps:h,display:d,style:"fill"},_plotKey:f,_callsiteId:n}}this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}};Rt([M],Jr.prototype,"any",1);var B0=Object.defineProperty,V0=(t,e,n)=>e in t?B0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,W0=(t,e,n)=>V0(t,typeof e!="symbol"?e+"":e,n),Cs=class{constructor(e){this.context=e,W0(this,"point");let n=this.context,r=i=>i==null?i:typeof i=="object"&&Array.isArray(i.data)&&typeof i.get=="function"?i.get(0):typeof i=="function"?i():i;this.point={new(i,s,a){return new qe(r(i),r(s),r(a)??NaN)},from_index(i,s){return new qe(void 0,r(i),r(s))},from_time(i,s){return new qe(r(i),void 0,r(s))},copy(i){return i.copy()},now(i){let s=n.idx,a=n.marketData[s]?.openTime;return new qe(a,s,r(i))}}}param(e,n=0,r){return y.from(e).get(n)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){let e=this.context?.chartStyle;return e==null||e==="standard"}is_heikinashi(){return this.context?.chartStyle==="heikinashi"}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}},$0=Object.defineProperty,j0=(t,e,n)=>e in t?$0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fe=(t,e,n)=>j0(t,typeof e!="symbol"?e+"":e,n),U0=0,rr=class t{constructor(e,n,r="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",d=!1){Fe(this,"id"),Fe(this,"x"),Fe(this,"y"),Fe(this,"text"),Fe(this,"xloc"),Fe(this,"yloc"),Fe(this,"color"),Fe(this,"style"),Fe(this,"textcolor"),Fe(this,"size"),Fe(this,"textalign"),Fe(this,"tooltip"),Fe(this,"text_font_family"),Fe(this,"force_overlay"),Fe(this,"_deleted"),Fe(this,"_helper"),Fe(this,"_createdAtBar",-1),this.id=U0++,this.x=e,this.y=n,this.text=r,this.xloc=i,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=d,this._deleted=!1,this._helper=null}set_x(e){this._helper?this._helper.set_x(this,e):this._deleted||(this.x=e)}set_y(e){this._helper?this._helper.set_y(this,e):this._deleted||(this.y=e)}set_xy(e,n){this._helper?this._helper.set_xy(this,e,n):this._deleted||(this.x=e,this.y=n)}set_text(e){this._helper?this._helper.set_text(this,e):this._deleted||(this.text=e)}set_color(e){this._helper?this._helper.set_color(this,e):this._deleted||(this.color=e)}set_textcolor(e){this._helper?this._helper.set_textcolor(this,e):this._deleted||(this.textcolor=e)}set_size(e){this._helper?this._helper.set_size(this,e):this._deleted||(this.size=e)}set_style(e){this._helper?this._helper.set_style(this,e):this._deleted||(this.style=e)}set_textalign(e){this._helper?this._helper.set_textalign(this,e):this._deleted||(this.textalign=e)}set_tooltip(e){this._helper?this._helper.set_tooltip(this,e):this._deleted||(this.tooltip=e)}set_xloc(e){this._helper?this._helper.set_xloc(this,e):this._deleted||(this.xloc=e)}set_yloc(e){this._helper?this._helper.set_yloc(this,e):this._deleted||(this.yloc=e)}set_point(e){this._helper&&this._helper.set_point(this,e)}set_text_font_family(e){this._deleted||(this.text_font_family=e)}get_x(){return this.x}get_y(){return this.y}get_text(){return this.text}delete(){this._deleted=!0}copy(){return new t(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay)}toPlotData(){return{id:this.id,x:this.x,y:this.y,text:this.text,xloc:this.xloc,yloc:this.yloc,color:this.color,style:this.style,textcolor:this.textcolor,size:this.size,textalign:this.textalign,tooltip:this.tooltip,text_font_family:this.text_font_family,force_overlay:this.force_overlay,_deleted:this._deleted}}},hl=Object.defineProperty,z0=Object.getOwnPropertyDescriptor,q0=(t,e,n)=>e in t?hl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ve=(t,e,n,r)=>{for(var i=r>1?void 0:r?z0(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&hl(e,n,i),i},H0=(t,e,n)=>q0(t,typeof e!="symbol"?e+"":e,n),K0=[["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"]],Y0={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"},Ae=class{constructor(e){this.context=e,H0(this,"_labels",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._labels=this._labels.filter(s=>!s._deleted);let n=this._labels.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],i.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:i,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof at)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){let n=e.get(0);return typeof n=="number"&&isNaN(n)?null:n}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,n,r="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",d=!1){let f=new rr(e,n,this._resolve(r),this._resolve(i),this._resolve(s),this._resolve(a),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(p),this._resolve(h),d);return f._helper=this,f._createdAtBar=this.context.idx,this._labels.push(f),this._enforceMaxCount(),f}_enforceMaxCount(){let e=this.context.indicator?.max_labels_count??50,n=this._labels.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._labels){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ye(e,K0,Y0),r,i,s=n.xloc;if(n.point instanceof qe){let a=n.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"),i=a.price}else r=this._resolve(n.x),i=this._resolve(n.y);return this._createLabel(r,i,n.text,s,n.yloc,n.color,n.style,n.textcolor,n.size,n.textalign,n.tooltip,n.text_font_family,n.force_overlay)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof at||typeof n=="number"&&isNaN(n))return null;if(n instanceof rr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof rr)return r}return null}return this.new(...e)}set_x(e,n){e&&!e._deleted&&(e.x=n)}set_y(e,n){e&&!e._deleted&&(e.y=n)}set_xy(e,n,r){e&&!e._deleted&&(e.x=n,e.y=r)}set_text(e,n){e&&!e._deleted&&(e.text=n)}set_color(e,n){e&&!e._deleted&&(e.color=n)}set_textcolor(e,n){e&&!e._deleted&&(e.textcolor=n)}set_size(e,n){e&&!e._deleted&&(e.size=n)}set_style(e,n){e&&!e._deleted&&(e.style=n)}set_textalign(e,n){e&&!e._deleted&&(e.textalign=n)}set_tooltip(e,n){e&&!e._deleted&&(e.tooltip=n)}set_xloc(e,n){e&&!e._deleted&&(e.xloc=n)}set_yloc(e,n){e&&!e._deleted&&(e.yloc=n)}set_point(e,n){if(e&&!e._deleted&&n){let r=n.index!==void 0&&!(typeof n.index=="number"&&isNaN(n.index)),i=n.time!==void 0&&!(typeof n.time=="number"&&isNaN(n.time));r?(e.x=n.index,e.xloc="bi"):i&&(e.x=n.time,e.xloc="bt"),e.y=n.price}}get_x(e){return e?e.x:NaN}get_y(e){return e?e.y:NaN}get_text(e){return e?e.text:""}copy(e){if(!e)return;let n=e.copy();return n._helper=this,n._createdAtBar=this.context.idx,this._labels.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(n=>n._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([M],Ae.prototype,"new",1),Ve([M],Ae.prototype,"set_x",1),Ve([M],Ae.prototype,"set_y",1),Ve([M],Ae.prototype,"set_xy",1),Ve([M],Ae.prototype,"set_text",1),Ve([M],Ae.prototype,"set_color",1),Ve([M],Ae.prototype,"set_textcolor",1),Ve([M],Ae.prototype,"set_size",1),Ve([M],Ae.prototype,"set_style",1),Ve([M],Ae.prototype,"set_textalign",1),Ve([M],Ae.prototype,"set_tooltip",1),Ve([M],Ae.prototype,"set_xloc",1),Ve([M],Ae.prototype,"set_yloc",1),Ve([M],Ae.prototype,"set_point",1),Ve([M],Ae.prototype,"copy",1),Ve([M],Ae.prototype,"delete",1);var G0=Object.defineProperty,X0=(t,e,n)=>e in t?G0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ge=(t,e,n)=>X0(t,typeof e!="symbol"?e+"":e,n),Z0=0,ir=class t{constructor(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){Ge(this,"id"),Ge(this,"x1"),Ge(this,"y1"),Ge(this,"x2"),Ge(this,"y2"),Ge(this,"xloc"),Ge(this,"extend"),Ge(this,"color"),Ge(this,"style"),Ge(this,"width"),Ge(this,"force_overlay"),Ge(this,"_deleted"),Ge(this,"_helper"),Ge(this,"_createdAtBar",-1),this.id=Z0++,this.x1=e,this.y1=n,this.x2=r,this.y2=i,this.xloc=s,this.extend=a,this.color=o,this.style=l,this.width=c,this.force_overlay=u,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,n){this._helper?this._helper.set_xy1(this,e,n):this._deleted||(this.x1=e,this.y1=n)}set_xy2(e,n){this._helper?this._helper.set_xy2(this,e,n):this._deleted||(this.x2=e,this.y2=n)}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,n,r){this._helper?this._helper.set_xloc(this,e,n,r):this._deleted||(this.x1=e,this.x2=n,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 t(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}},pl=Object.defineProperty,Q0=Object.getOwnPropertyDescriptor,J0=(t,e,n)=>e in t?pl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,We=(t,e,n,r)=>{for(var i=r>1?void 0:r?Q0(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&pl(e,n,i),i},ex=(t,e,n)=>J0(t,typeof e!="symbol"?e+"":e,n),tx=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],nx={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"},Me=class{constructor(e){this.context=e,ex(this,"_lines",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._lines=this._lines.filter(s=>!s._deleted);let n=this._lines.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],i.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:i,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e){let n=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return n?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof at?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n}_createLine(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){let p=new ir(e,n,r,i,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(),p}_enforceMaxCount(){let e=this.context.indicator?.max_lines_count??50,n=this._lines.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._lines){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ye(e,tx,nx),r,i,s,a,o=n.xloc;if(n.first_point instanceof qe){let l=n.first_point,c=n.second_point,u=this._resolvePoint(l);r=u.x,i=l.price,o=o||u.xloc,c instanceof qe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else r=this._resolve(n.x1),i=this._resolve(n.y1),s=this._resolve(n.x2),a=this._resolve(n.y2);return this._createLine(r,i,s,a,o,n.extend,n.color,n.style,n.width,n.force_overlay)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof at||typeof n=="number"&&isNaN(n))return null;if(n instanceof ir)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof ir)return r}return null}return this.new(...e)}set_x1(e,n){e&&!e._deleted&&(e.x1=this._resolve(n))}set_y1(e,n){e&&!e._deleted&&(e.y1=this._resolve(n))}set_x2(e,n){e&&!e._deleted&&(e.x2=this._resolve(n))}set_y2(e,n){e&&!e._deleted&&(e.y2=this._resolve(n))}set_xy1(e,n,r){e&&!e._deleted&&(e.x1=this._resolve(n),e.y1=this._resolve(r))}set_xy2(e,n,r){e&&!e._deleted&&(e.x2=this._resolve(n),e.y2=this._resolve(r))}set_color(e,n){e&&!e._deleted&&(e.color=this._resolveColor(n))}set_width(e,n){e&&!e._deleted&&(e.width=this._resolve(n)||1)}set_style(e,n){e&&!e._deleted&&(e.style=this._resolve(n))}set_extend(e,n){e&&!e._deleted&&(e.extend=this._resolve(n))}set_xloc(e,n,r,i){e&&!e._deleted&&(e.x1=n,e.x2=r,e.xloc=i)}set_first_point(e,n){if(e&&!e._deleted&&n){let r=this._resolvePoint(n);e.x1=r.x,e.y1=n.price,e.xloc=r.xloc}}set_second_point(e,n){if(e&&!e._deleted&&n){let r=this._resolvePoint(n);e.x2=r.x,e.y2=n.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,n){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;let r=e.x2-e.x1;return r===0?e.y1:e.y1+(n-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;let n=e.copy();return n._helper=this,n._createdAtBar=this.context.idx,this._lines.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0)}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(n=>n._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([M],Me.prototype,"new",1),We([M],Me.prototype,"set_x1",1),We([M],Me.prototype,"set_y1",1),We([M],Me.prototype,"set_x2",1),We([M],Me.prototype,"set_y2",1),We([M],Me.prototype,"set_xy1",1),We([M],Me.prototype,"set_xy2",1),We([M],Me.prototype,"set_color",1),We([M],Me.prototype,"set_width",1),We([M],Me.prototype,"set_style",1),We([M],Me.prototype,"set_extend",1),We([M],Me.prototype,"set_xloc",1),We([M],Me.prototype,"set_first_point",1),We([M],Me.prototype,"set_second_point",1),We([M],Me.prototype,"copy",1),We([M],Me.prototype,"delete",1);var rx=Object.defineProperty,ix=(t,e,n)=>e in t?rx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ve=(t,e,n)=>ix(t,typeof e!="symbol"?e+"":e,n),sx=0,sr=class t{constructor(e,n,r,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",d="auto",f="center",m="center",_="wrap_none",b="default",v="format_none",S=!1){ve(this,"id"),ve(this,"left"),ve(this,"top"),ve(this,"right"),ve(this,"bottom"),ve(this,"xloc"),ve(this,"extend"),ve(this,"border_color"),ve(this,"border_style"),ve(this,"border_width"),ve(this,"bgcolor"),ve(this,"text"),ve(this,"text_color"),ve(this,"text_size"),ve(this,"text_halign"),ve(this,"text_valign"),ve(this,"text_wrap"),ve(this,"text_font_family"),ve(this,"text_formatting"),ve(this,"force_overlay"),ve(this,"_deleted"),ve(this,"_helper"),ve(this,"_createdAtBar",-1),this.id=sx++,this.left=e,this.top=n,this.right=r,this.bottom=i,this.xloc=s,this.extend=a,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=p,this.text_color=h,this.text_size=d,this.text_halign=f,this.text_valign=m,this.text_wrap=_,this.text_font_family=b,this.text_formatting=v,this.force_overlay=S,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,n){this._helper?this._helper.set_lefttop(this,e,n):this._deleted||(this.left=e,this.top=n)}set_rightbottom(e,n){this._helper?this._helper.set_rightbottom(this,e,n):this._deleted||(this.right=e,this.bottom=n)}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,n,r){this._helper?this._helper.set_xloc(this,e,n,r):this._deleted||(this.left=e,this.right=n,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 t(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}},dl=Object.defineProperty,ax=Object.getOwnPropertyDescriptor,ox=(t,e,n)=>e in t?dl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ge=(t,e,n,r)=>{for(var i=r>1?void 0:r?ax(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&dl(e,n,i),i},lx=(t,e,n)=>ox(t,typeof e!="symbol"?e+"":e,n),cx=[["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"]],ux={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"},de=class{constructor(e){this.context=e,lx(this,"_boxes",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._boxes=this._boxes.filter(s=>!s._deleted);let n=this._boxes.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],i.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:i,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e){let n=e.index!==void 0&&!(typeof e.index=="number"&&isNaN(e.index)),r=e.time!==void 0&&!(typeof e.time=="number"&&isNaN(e.time));return n?{x:e.index,xloc:"bi"}:r?{x:e.time,xloc:"bt"}:{x:0,xloc:"bi"}}_resolve(e){return e==null?e:e instanceof at?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,n){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||n}_createBox(e,n,r,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",d="auto",f="center",m="center",_="wrap_none",b="default",v="format_none",S=!1){let w=new sr(e,n,r,i,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(d)||"auto",this._resolve(f)||"center",this._resolve(m)||"center",this._resolve(_)||"wrap_none",this._resolve(b)||"default",this._resolve(v)||"format_none",S);return w._helper=this,w._createdAtBar=this.context.idx,this._boxes.push(w),this._enforceMaxCount(),w}_enforceMaxCount(){let e=this.context.indicator?.max_boxes_count??50,n=this._boxes.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._boxes){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ye(e,cx,ux),r,i,s,a,o=n.xloc;if(n.top_left instanceof qe){let l=n.top_left,c=n.bottom_right,u=this._resolvePoint(l);r=u.x,i=l.price,o=o||u.xloc,c instanceof qe?(s=this._resolvePoint(c).x,a=c.price):(s=0,a=NaN)}else r=this._resolve(n.left),i=this._resolve(n.top),s=this._resolve(n.right),a=this._resolve(n.bottom);return this._createBox(r,i,s,a,o,n.extend,n.border_color,n.border_style,n.border_width,n.bgcolor,n.text,n.text_color,n.text_size,n.text_halign,n.text_valign,n.text_wrap,n.text_font_family,void 0,n.force_overlay)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof at||typeof n=="number"&&isNaN(n))return null;if(n instanceof sr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof sr)return r}return null}return this.new(...e)}set_left(e,n){e&&!e._deleted&&(e.left=this._resolve(n))}set_right(e,n){e&&!e._deleted&&(e.right=this._resolve(n))}set_top(e,n){e&&!e._deleted&&(e.top=this._resolve(n))}set_bottom(e,n){e&&!e._deleted&&(e.bottom=this._resolve(n))}set_lefttop(e,n,r){e&&!e._deleted&&(e.left=this._resolve(n),e.top=this._resolve(r))}set_rightbottom(e,n,r){e&&!e._deleted&&(e.right=this._resolve(n),e.bottom=this._resolve(r))}set_top_left_point(e,n){if(e&&!e._deleted&&n){let r=this._resolvePoint(n);e.left=r.x,e.top=n.price,e.xloc=r.xloc}}set_bottom_right_point(e,n){if(e&&!e._deleted&&n){let r=this._resolvePoint(n);e.right=r.x,e.bottom=n.price,e.xloc=r.xloc}}set_xloc(e,n,r,i){e&&!e._deleted&&(e.left=this._resolve(n),e.right=this._resolve(r),e.xloc=this._resolve(i))}set_bgcolor(e,n){e&&!e._deleted&&(e.bgcolor=this._resolve(n))}set_border_color(e,n){e&&!e._deleted&&(e.border_color=this._resolve(n))}set_border_width(e,n){e&&!e._deleted&&(e.border_width=this._resolve(n)??1)}set_border_style(e,n){e&&!e._deleted&&(e.border_style=this._resolve(n))}set_extend(e,n){e&&!e._deleted&&(e.extend=this._resolve(n))}set_text(e,n){e&&!e._deleted&&(e.text=this._resolve(n)||"")}set_text_color(e,n){e&&!e._deleted&&(e.text_color=this._resolve(n))}set_text_size(e,n){e&&!e._deleted&&(e.text_size=this._resolve(n))}set_text_halign(e,n){e&&!e._deleted&&(e.text_halign=this._resolve(n))}set_text_valign(e,n){e&&!e._deleted&&(e.text_valign=this._resolve(n))}set_text_wrap(e,n){e&&!e._deleted&&(e.text_wrap=this._resolve(n))}set_text_font_family(e,n){e&&!e._deleted&&(e.text_font_family=this._resolve(n))}set_text_formatting(e,n){e&&!e._deleted&&(e.text_formatting=this._resolve(n))}get_left(e){return e?e.left:NaN}get_right(e){return e?e.right:NaN}get_top(e){return e?e.top:NaN}get_bottom(e){return e?e.bottom:NaN}copy(e){if(!e)return;let n=e.copy();return n._helper=this,n._createdAtBar=this.context.idx,this._boxes.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(n=>n._createdAtBar<e),this.syncToPlot()}};ge([M],de.prototype,"new",1),ge([M],de.prototype,"set_left",1),ge([M],de.prototype,"set_right",1),ge([M],de.prototype,"set_top",1),ge([M],de.prototype,"set_bottom",1),ge([M],de.prototype,"set_lefttop",1),ge([M],de.prototype,"set_rightbottom",1),ge([M],de.prototype,"set_top_left_point",1),ge([M],de.prototype,"set_bottom_right_point",1),ge([M],de.prototype,"set_xloc",1),ge([M],de.prototype,"set_bgcolor",1),ge([M],de.prototype,"set_border_color",1),ge([M],de.prototype,"set_border_width",1),ge([M],de.prototype,"set_border_style",1),ge([M],de.prototype,"set_extend",1),ge([M],de.prototype,"set_text",1),ge([M],de.prototype,"set_text_color",1),ge([M],de.prototype,"set_text_size",1),ge([M],de.prototype,"set_text_halign",1),ge([M],de.prototype,"set_text_valign",1),ge([M],de.prototype,"set_text_wrap",1),ge([M],de.prototype,"set_text_font_family",1),ge([M],de.prototype,"set_text_formatting",1),ge([M],de.prototype,"copy",1),ge([M],de.prototype,"delete",1);var hx=Object.defineProperty,px=(t,e,n)=>e in t?hx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dn=(t,e,n)=>px(t,typeof e!="symbol"?e+"":e,n),dx=0,ei=class{constructor(e,n,r){Dn(this,"id"),Dn(this,"line1"),Dn(this,"line2"),Dn(this,"color"),Dn(this,"_deleted"),Dn(this,"_createdAtBar",-1),this.id=dx++,this.line1=e,this.line2=n,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(){let 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,n=!!(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:n,_deleted:this._deleted}}},fl=Object.defineProperty,fx=Object.getOwnPropertyDescriptor,mx=(t,e,n)=>e in t?fl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Gi=(t,e,n,r)=>{for(var i=r>1?void 0:r?fx(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&fl(e,n,i),i},yx=(t,e,n)=>mx(t,typeof e!="symbol"?e+"":e,n),Bn=class{constructor(e){this.context=e,yx(this,"_linefills",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._linefills=this._linefills.filter(s=>!s._deleted);let n=this._linefills.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],i.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:i,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof at?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n}new(e,n,r){let i=this._resolve(e),s=this._resolve(n),a=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolveColor(a);if(i&&s){let c=i.id,u=s.id;for(let p of this._linefills){if(p._deleted)continue;let h=p.line1?.id,d=p.line2?.id;if(h===c&&d===u||h===u&&d===c)return p.color=o,p._createdAtBar=this.context.idx,p}}let l=new ei(i,s,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),l}any(...e){if(e.length===1){let n=e[0];return n==null||n instanceof at||typeof n=="number"&&isNaN(n)?null:n instanceof ei?n:null}return this.new(e[0],e[1],e[2])}set_color(e,n){e&&!e._deleted&&(e.color=this._resolveColor(n))}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(n=>n._createdAtBar<e),this.syncToPlot()}};Gi([M],Bn.prototype,"new",1),Gi([M],Bn.prototype,"set_color",1),Gi([M],Bn.prototype,"delete",1);var gx=Object.defineProperty,xx=(t,e,n)=>e in t?gx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ct=(t,e,n)=>xx(t,typeof e!="symbol"?e+"":e,n),_x=0,ar=class{constructor(e,n=!1,r=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){ct(this,"id"),ct(this,"points"),ct(this,"curved"),ct(this,"closed"),ct(this,"xloc"),ct(this,"line_color"),ct(this,"fill_color"),ct(this,"line_style"),ct(this,"line_width"),ct(this,"force_overlay"),ct(this,"_deleted"),ct(this,"_createdAtBar",-1),this.id=_x++,this.points=e,this.curved=n,this.closed=r,this.xloc=i,this.line_color=s,this.fill_color=a,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}},ml=Object.defineProperty,bx=Object.getOwnPropertyDescriptor,vx=(t,e,n)=>e in t?ml(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ho=(t,e,n,r)=>{for(var i=r>1?void 0:r?bx(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&ml(e,n,i),i},wx=(t,e,n)=>vx(t,typeof e!="symbol"?e+"":e,n),fr=class{constructor(e){this.context=e,wx(this,"_polylines",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._polylines=this._polylines.filter(n=>!n._deleted),this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(n=>n.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof at?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,n){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||n}_extractPoints(e){let n=this._resolve(e),r=n&&n.array?n.array:n;return Array.isArray(r)?r.filter(i=>i instanceof qe):[]}new(...e){let n,r=!1,i=!1,s="bi",a="#2962ff",o="",l="style_solid",c=1,u=!1,p=(b,v)=>Object.prototype.hasOwnProperty.call(b,v),h=b=>{p(b,"curved")&&(r=b.curved),p(b,"closed")&&(i=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)},d=e.length>=1?e[e.length-1]:null,f=e.length>=2&&d&&typeof d=="object"&&!Array.isArray(d)&&!(d instanceof y)&&!(d instanceof qe);if(e.length===1&&d&&typeof d=="object"&&!Array.isArray(d)&&"points"in d)n=d.points,h(d);else{let b=f?e.slice(0,-1):e;n=b[0],b.length>1&&(r=b[1]),b.length>2&&(i=b[2]),b.length>3&&(s=b[3]),b.length>4&&(a=b[4]),b.length>5&&(o=b[5]),b.length>6&&(l=b[6]),b.length>7&&(c=b[7]),b.length>8&&(u=b[8]),f&&h(d)}let m=this._extractPoints(n),_=new ar(m,this._resolve(r)??!1,this._resolve(i)??!1,this._resolve(s)||"bi",this._resolveColor(a,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(u)??!1);return _._createdAtBar=this.context.idx,this._polylines.push(_),this._enforceMaxCount(),_}_enforceMaxCount(){let e=this.context.indicator?.max_polylines_count??50,n=this._polylines.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._polylines){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof at||typeof n=="number"&&isNaN(n))return null;if(n instanceof ar)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof ar)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(n=>n._createdAtBar<e),this.syncToPlot()}};ho([M],fr.prototype,"new",1),ho([M],fr.prototype,"delete",1);var Sx=Object.defineProperty,Ex=(t,e,n)=>e in t?Sx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xe=(t,e,n)=>Ex(t,typeof e!="symbol"?e+"":e,n),Cx=0,ti=class{constructor(e="top_right",n=1,r=1,i="",s="",a=0,o="",l=0,c=!1){Xe(this,"id"),Xe(this,"position"),Xe(this,"columns"),Xe(this,"rows"),Xe(this,"bgcolor"),Xe(this,"frame_color"),Xe(this,"frame_width"),Xe(this,"border_color"),Xe(this,"border_width"),Xe(this,"force_overlay"),Xe(this,"_deleted"),Xe(this,"cells"),Xe(this,"merges"),Xe(this,"_helper"),this.id=Cx++,this.position=e,this.columns=n,this.rows=r,this.bgcolor=i,this.frame_color=s,this.frame_width=a,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let u=0;u<r;u++){this.cells[u]=[];for(let p=0;p<n;p++)this.cells[u][p]=null}}delete(){this._deleted=!0}toPlotData(){let e=this.cells.map(n=>n.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(n=>({...n}))}}setCell(e,n,r){if(n<0||n>=this.rows||e<0||e>=this.columns)return;let i=this.cells[n][e];if(i&&i._merged&&i._merge_parent){let[a,o]=i._merge_parent;if(a===e&&o===n)i._merged=!1,i._merge_parent=void 0;else{this.setCell(a,o,r);return}}let s=i||this._defaultCell();Object.assign(s,r),this.cells[n][e]=s}getCell(e,n){return n<0||n>=this.rows||e<0||e>=this.columns?null:this.cells[n][e]}clearCell(e,n){n<0||n>=this.rows||e<0||e>=this.columns||(this.cells[n][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}}},yl=Object.defineProperty,Ix=Object.getOwnPropertyDescriptor,Nx=(t,e,n)=>e in t?yl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Se=(t,e,n,r)=>{for(var i=r>1?void 0:r?Ix(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&yl(e,n,i),i},kx=(t,e,n)=>Nx(t,typeof e!="symbol"?e+"":e,n),_e=class{constructor(e){this.context=e,kx(this,"_tables",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._tables=this._tables.filter(n=>!n._deleted),this.context.plots.__tables__.data=[{time:e,value:this._tables.map(n=>n.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 n="top_right",r=1,i=1,s="",a="",o=0,l="",c=0,u=!1,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)){let d=p,f=e.slice(0,-1);n=f[0]??d.position??n,r=f[1]??d.columns??r,i=f[2]??d.rows??i,s=d.bgcolor??s,a=d.frame_color??a,o=d.frame_width??o,l=d.border_color??l,c=d.border_width??c,u=d.force_overlay??u}else n=e[0]??n,r=e[1]??r,i=e[2]??i,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;let h=new ti(this._resolve(n)||"top_right",this._resolve(r)||1,this._resolve(i)||1,this._resolve(s)||"",this._resolve(a)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return h._setHelper(this),this._tables.push(h),h}any(...e){if(e.length===1){let n=e[0];return n==null||typeof n=="object"&&"__value"in n||typeof n=="number"&&isNaN(n)?null:n instanceof ti?n:null}return this.new(...e)}cell(...e){let n,r,i,s="",a=0,o=0,l="#000000",c="center",u="center",p="normal",h="",d="",f="default",m=e[e.length-1];if(m&&typeof m=="object"&&!Array.isArray(m)&&("text"in m||"bgcolor"in m||"text_color"in m||"text_size"in m||"text_halign"in m||"tooltip"in m||"column"in m||"row"in m||"height"in m||"width"in m||"text_valign"in m||"text_font_family"in m)){let S=m,w=e.slice(0,-1);n=w[0],r=w.length>1?w[1]:S.column??0,i=w.length>2?w[2]:S.row??0,s=w[3]??S.text??s,a=w[4]??S.width??a,o=w[5]??S.height??o,l=w[6]??S.text_color??l,c=w[7]??S.text_halign??c,u=w[8]??S.text_valign??u,p=w[9]??S.text_size??p,h=w[10]??S.bgcolor??h,d=w[11]??S.tooltip??d,f=w[12]??S.text_font_family??f}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u,p=e[9]??p,h=e[10]??h,d=e[11]??d,f=e[12]??f;let _=this._resolve(n);if(!_||_._deleted)return;let b=this._resolve(r)??0,v=this._resolve(i)??0;_.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(d)),text_font_family:this._resolve(f)||"default"})}delete(e){e&&(e._deleted=!0)}clear(...e){let n,r,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;n=e[0],r=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:r),a=d.end_row??(e.length>5?e[4]:i)}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??r,a=e[4]??i;let l=this._resolve(n);if(!l||l._deleted)return;let c=this._resolve(r)??0,u=this._resolve(i)??0,p=this._resolve(s)??c,h=this._resolve(a)??u;for(let d=u;d<=h;d++)for(let f=c;f<=p;f++)l.clearCell(f,d)}merge_cells(...e){let n,r,i,s,a,o=e[e.length-1];if(o&&typeof o=="object"&&!Array.isArray(o)&&("start_column"in o||"start_row"in o||"end_column"in o)){let d=o;n=e[0],r=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:0),a=d.end_row??(e.length>5?e[4]:0)}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??0,a=e[4]??0;let l=this._resolve(n);if(!l||l._deleted)return;let c=this._resolve(r)??0,u=this._resolve(i)??0,p=this._resolve(s)??0,h=this._resolve(a)??0;for(let d=u;d<=h;d++)for(let f=c;f<=p;f++)d===u&&f===c||l.setCell(f,d,{_merged:!0,_merge_parent:[c,u]});l.merges.push({startCol:c,startRow:u,endCol:p,endRow:h})}cell_set_text(e,n,r,i){this._setCellProp(e,n,r,"text",i,!0)}cell_set_bgcolor(e,n,r,i){this._setCellProp(e,n,r,"bgcolor",i)}cell_set_text_color(e,n,r,i){this._setCellProp(e,n,r,"text_color",i)}cell_set_text_size(e,n,r,i){this._setCellProp(e,n,r,"text_size",i)}cell_set_height(e,n,r,i){this._setCellProp(e,n,r,"height",i)}cell_set_width(e,n,r,i){this._setCellProp(e,n,r,"width",i)}cell_set_tooltip(e,n,r,i){this._setCellProp(e,n,r,"tooltip",i,!0)}cell_set_text_halign(e,n,r,i){this._setCellProp(e,n,r,"text_halign",i)}cell_set_text_valign(e,n,r,i){this._setCellProp(e,n,r,"text_valign",i)}cell_set_text_font_family(e,n,r,i){this._setCellProp(e,n,r,"text_font_family",i)}set_position(e,n){let r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(n)||r.position)}set_bgcolor(e,n){let r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(n)||"")}set_border_color(e,n){let r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(n)||"")}set_border_width(e,n){let r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(n)||0)}set_frame_color(e,n){let r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(n)||"")}set_frame_width(e,n){let r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(n)||0)}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,n,r,i,s,a=!1){let o=this._resolve(e);if(!o||o._deleted)return;let l=this._resolve(n)??0,c=this._resolve(r)??0,u=this._resolve(s);o.setCell(l,c,{[i]:a?this._resolveText(u):u})}_resolveText(e){return e==null||e!==e?"":String(e)}};Se([M],_e.prototype,"new",1),Se([M],_e.prototype,"cell",1),Se([M],_e.prototype,"delete",1),Se([M],_e.prototype,"clear",1),Se([M],_e.prototype,"merge_cells",1),Se([M],_e.prototype,"cell_set_text",1),Se([M],_e.prototype,"cell_set_bgcolor",1),Se([M],_e.prototype,"cell_set_text_color",1),Se([M],_e.prototype,"cell_set_text_size",1),Se([M],_e.prototype,"cell_set_height",1),Se([M],_e.prototype,"cell_set_width",1),Se([M],_e.prototype,"cell_set_tooltip",1),Se([M],_e.prototype,"cell_set_text_halign",1),Se([M],_e.prototype,"cell_set_text_valign",1),Se([M],_e.prototype,"cell_set_text_font_family",1),Se([M],_e.prototype,"set_position",1),Se([M],_e.prototype,"set_bgcolor",1),Se([M],_e.prototype,"set_border_color",1),Se([M],_e.prototype,"set_border_width",1),Se([M],_e.prototype,"set_frame_color",1),Se([M],_e.prototype,"set_frame_width",1);var Is=class{constructor(e){this.context=e}param(e,n=0,r){return typeof e=="string"?e:y.from(e).get(n)}inherit(e,n){let r=this._coerce(e),i=tn(this._coerce(n)),{modifier:s}=dr(r);return s&&s!=="standard"?fs(i,s):i}new(e,n,r,i,s,a){let o=this._coerce(e),l=this._coerce(n);return o?l?`${o}:${l}`:o:l}modify(e,n,r,i,s){return this._coerce(e)}standard(e){return e==null?tn(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):tn(this._coerce(e))}heikinashi(e){return fs(this._coerce(e),"heikinashi")}renko(e,n,r,i,s){return this._coerce(e)}kagi(e,n){return this._coerce(e)}linebreak(e,n){return this._coerce(e)}pointfigure(e,n,r,i,s){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){let n=e.get(0);return n==null?"":String(n)}return typeof e=="number"&&isNaN(e)?"":String(e)}},Ax=Object.defineProperty,Mx=(t,e,n)=>e in t?Ax(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Z=(t,e,n)=>Mx(t,typeof e!="symbol"?e+"":e,n),Ns=class Br{constructor({marketData:e,source:n,tickerId:r,timeframe:i,limit:s,sDate:a,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,"chartStyle","standard"),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=n,this.tickerId=r,this.timeframe=i,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};let u=new Yr(this),p={Type:u.Type.bind(u),na:new at,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new Kr(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new Hr(this,"openTime"),time_close:new Hr(this,"closeTime"),dayofmonth:new Dt(this,Qt.dayofmonth),dayofweek:new Dt(this,Qt.dayofweek),hour:new Dt(this,Qt.hour),minute:new Dt(this,Qt.minute),month:new Dt(this,Qt.month),second:new Dt(this,Qt.second),weekofyear:new Dt(this,Qt.weekofyear),year:new Dt(this,Qt.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 ps(this),ta:new xs(this),math:new ds(this),request:new gs(this),array:new rs(this),map:new is(this),matrix:new ss(this),ticker:new Is(this),strategy:new bs(this),syminfo:null,timeframe:new Es(this),barstate:new as(this),session:new cs(this),get bar_index(){return h.data.bar_index},get last_bar_index(){let N=h.marketData;return Array.isArray(N)&&N.length>0?N.length-1:h.data.close.length-1},get last_bar_time(){let N=h.marketData;return Array.isArray(N)&&N.length>0?N[N.length-1].openTime:h.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){let N=y.from(h.data.closeTime).get(0);if(isNaN(N))return NaN;let j=h.pine?.syminfo?.timezone||"UTC",T=rn(N,j);return Date.UTC(T.year,T.month-1,T.day,0,0,0)},get inputs(){return h.inputs},log:new vs(this),runtime:new ws(this),str:new Ss(this),...p,...Th};let d=p.dayofweek;Object.assign(d,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=d;let f=new Et(this),m=new Qr(this),_=new Jr(this);this.bindContextObject(f,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(f,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(m,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");let b=new Cs(this);this.pine.chart={param:b.param.bind(b),bg_color:b.bg_color.bind(b),fg_color:b.fg_color.bind(b),get is_standard(){return b.is_standard()},get is_heikinashi(){return b.is_heikinashi()},get is_kagi(){return b.is_kagi()},get is_linebreak(){return b.is_linebreak()},get is_pnf(){return b.is_pnf()},get is_range(){return b.is_range()},get is_renko(){return b.is_renko()},point:b.point,get left_visible_bar_time(){if(h.viewportLeft!==void 0)return h.viewportLeft;let N=h.marketData;return Array.isArray(N)&&N.length>0?N[0].openTime:NaN},get right_visible_bar_time(){if(h.viewportRight!==void 0)return h.viewportRight;let N=h.marketData;return Array.isArray(N)&&N.length>0?N[N.length-1].openTime:NaN}};let v=new Ae(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});let S=new Me(this);this.bindContextObject(S,["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:()=>S.all});let w=new de(this);this.bindContextObject(w,["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:()=>w.all});let I=new Bn(this);this.bindContextObject(I,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>I.all});let E=new fr(this);this.bindContextObject(E,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>E.all});let A=new _e(this);this.bindContextObject(A,["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:()=>A.all}),this._drawingHelpers=[v,S,w,I,E,A];let F=new hs(this);this.bindContextObject(F,["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,n){this.warnings.push({message:e,method:n,bar:this.idx})}rollbackDrawings(e){for(let n of this._drawingHelpers)n.rollbackFromBar(e)}bindContextObject(e,n,r=""){r&&!this.pine[r]&&(this.pine[r]={});let i=r?this.pine[r]:this.pine;for(let s of n)typeof e[s]=="function"?i[s]=e[s].bind(e):i[s]=e[s]}init(e,n,r=0){let i;return n instanceof y?i=n.get(0):Array.isArray(n)?Array.isArray(n[0])?i=n[0]:i=n[n.length-1+r]:i=n,e?e instanceof y?(e.data[e.data.length-1]=i,e):Array.isArray(e)?(e[e.length-1]=i,new y(e)):new y([i]):new y([i])}initVar(e,n){if(e)return e;if(typeof n=="function"&&(n=n()),n instanceof en){let i=n.__def__;for(let s in i)typeof n[s]=="function"&&(n[s]=n[s]())}let r;return n instanceof y?r=n.get(0):Array.isArray(n)?Array.isArray(n[0])?r=n[0]:r=this.precision(n[n.length-1]):r=this.precision(n),new y([r])}precision(e,n=10){let r=n===10?Br.PRECISION_EPSILON:10**n;return typeof e=="number"?Math.round(e*r)/r:e}param(e,n,r){return typeof e=="string"?e:e instanceof y?n?new y(e.data,e.offset+n):e:!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,n||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],n||0)))}get(e,n){if(typeof n=="number"&&!Number.isInteger(n)&&(n=Math.trunc(n)),e instanceof y)return e.get(n);if(Array.isArray(e)){let r=e.length-1-n;return r<0||r>=e.length?NaN:e[r]}return e}set(e,n){if(e instanceof y){e.set(0,typeof n=="number"?this.precision(n):n);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=n:e.push(n);return}}iter(e){return e==null?[]:Array.isArray(e.array)?e.array:e.map instanceof Map?e.map:e}entries(e){return e==null?[].entries():Array.isArray(e.array)?e.array.entries():e.map instanceof Map?e.map.entries():Array.isArray(e)||typeof e.entries=="function"?e.entries():[].entries()}pushId(e){let n=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",r=n?n+"|"+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(){let e=this.peekId();if(!e)return this;let n=this.lctx.get(e);return n||(n={id:e,let:{},const:{},var:{}},this.lctx.set(e,n)),n}call(e,n,...r){this.pushId(n);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,n){let r=`${e}->${n}`;Br._deprecationWarningsShown.has(r)||(Br._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,n):console.warn(`\\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${n} instead. This will be removed in a future version.\\x1B[0m`))}};Z(Ns,"_deprecationWarningsShown",new Set),Z(Ns,"PRECISION_EPSILON",10**10);var $n=Ns,Tx=[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],gl=[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],Px="\\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",xl="\\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",Xi={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"},Zi="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",Dx={5:Zi,"5module":Zi+" export import",6:Zi+" const class extends export import super"},_l=/^in(stanceof)?$/,Rx=new RegExp("["+xl+"]"),Ox=new RegExp("["+xl+Px+"]");function ks(t,e){for(var n=65536,r=0;r<e.length;r+=2){if(n+=e[r],n>t)return!1;if(n+=e[r+1],n>=t)return!0}return!1}function Wt(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Rx.test(String.fromCharCode(t)):e===!1?!1:ks(t,gl)}function sn(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&&Ox.test(String.fromCharCode(t)):e===!1?!1:ks(t,gl)||ks(t,Tx)}var ie=function(t,e){e===void 0&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null};function ut(t,e){return new ie(t,{beforeExpr:!0,binop:e})}var ht={beforeExpr:!0},Ze={startsExpr:!0},oa={};function ne(t,e){return e===void 0&&(e={}),e.keyword=t,oa[t]=new ie(t,e)}var g={num:new ie("num",Ze),regexp:new ie("regexp",Ze),string:new ie("string",Ze),name:new ie("name",Ze),privateId:new ie("privateId",Ze),eof:new ie("eof"),bracketL:new ie("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new ie("]"),braceL:new ie("{",{beforeExpr:!0,startsExpr:!0}),braceR:new ie("}"),parenL:new ie("(",{beforeExpr:!0,startsExpr:!0}),parenR:new ie(")"),comma:new ie(",",ht),semi:new ie(";",ht),colon:new ie(":",ht),dot:new ie("."),question:new ie("?",ht),questionDot:new ie("?."),arrow:new ie("=>",ht),template:new ie("template"),invalidTemplate:new ie("invalidTemplate"),ellipsis:new ie("...",ht),backQuote:new ie("`",Ze),dollarBraceL:new ie("${",{beforeExpr:!0,startsExpr:!0}),eq:new ie("=",{beforeExpr:!0,isAssign:!0}),assign:new ie("_=",{beforeExpr:!0,isAssign:!0}),incDec:new ie("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new ie("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:ut("||",1),logicalAND:ut("&&",2),bitwiseOR:ut("|",3),bitwiseXOR:ut("^",4),bitwiseAND:ut("&",5),equality:ut("==/!=/===/!==",6),relational:ut("</>/<=/>=",7),bitShift:ut("<</>>/>>>",8),plusMin:new ie("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:ut("%",10),star:ut("*",10),slash:ut("/",10),starstar:new ie("**",{beforeExpr:!0}),coalesce:ut("??",1),_break:ne("break"),_case:ne("case",ht),_catch:ne("catch"),_continue:ne("continue"),_debugger:ne("debugger"),_default:ne("default",ht),_do:ne("do",{isLoop:!0,beforeExpr:!0}),_else:ne("else",ht),_finally:ne("finally"),_for:ne("for",{isLoop:!0}),_function:ne("function",Ze),_if:ne("if"),_return:ne("return",ht),_switch:ne("switch"),_throw:ne("throw",ht),_try:ne("try"),_var:ne("var"),_const:ne("const"),_while:ne("while",{isLoop:!0}),_with:ne("with"),_new:ne("new",{beforeExpr:!0,startsExpr:!0}),_this:ne("this",Ze),_super:ne("super",Ze),_class:ne("class",Ze),_extends:ne("extends",ht),_export:ne("export"),_import:ne("import",Ze),_null:ne("null",Ze),_true:ne("true",Ze),_false:ne("false",Ze),_in:ne("in",{beforeExpr:!0,binop:7}),_instanceof:ne("instanceof",{beforeExpr:!0,binop:7}),_typeof:ne("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:ne("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:ne("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},Je=/\\r\\n?|\\n|\\u2028|\\u2029/,Lx=new RegExp(Je.source,"g");function jn(t){return t===10||t===13||t===8232||t===8233}function bl(t,e,n){n===void 0&&(n=t.length);for(var r=e;r<n;r++){var i=t.charCodeAt(r);if(jn(i))return r<n-1&&i===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var vl=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,$e=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,wl=Object.prototype,Fx=wl.hasOwnProperty,Bx=wl.toString,Un=Object.hasOwn||(function(t,e){return Fx.call(t,e)}),po=Array.isArray||(function(t){return Bx.call(t)==="[object Array]"}),fo=Object.create(null);function Jt(t){return fo[t]||(fo[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function Yt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var Vx=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,mr=function(t,e){this.line=t,this.column=e};mr.prototype.offset=function(t){return new mr(this.line,this.column+t)};var Si=function(t,e,n){this.start=e,this.end=n,t.sourceFile!==null&&(this.source=t.sourceFile)};function Sl(t,e){for(var n=1,r=0;;){var i=bl(t,r,e);if(i<0)return new mr(n,e-r);++n,r=i}}var As={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},mo=!1;function Wx(t){var e={};for(var n in As)e[n]=t&&Un(t,n)?t[n]:As[n];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!mo&&typeof console=="object"&&console.warn&&(mo=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=11):e.ecmaVersion>=2015&&(e.ecmaVersion-=2009),e.allowReserved==null&&(e.allowReserved=e.ecmaVersion<5),(!t||t.allowHashBang==null)&&(e.allowHashBang=e.ecmaVersion>=14),po(e.onToken)){var r=e.onToken;e.onToken=function(i){return r.push(i)}}if(po(e.onComment)&&(e.onComment=$x(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function $x(t,e){return function(n,r,i,s,a,o){var l={type:n?"Block":"Line",value:r,start:i,end:s};t.locations&&(l.loc=new Si(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var mn=1,gn=2,la=4,El=8,ca=16,Cl=32,Ei=64,Il=128,xn=256,xr=512,Nl=1024,Ci=mn|gn|xn;function ua(t,e){return gn|(t?la:0)|(e?El:0)}var ni=0,ha=1,Xt=2,kl=3,Al=4,Ml=5,Re=function(t,e,n){this.options=t=Wx(t),this.sourceFile=t.sourceFile,this.keywords=Jt(Dx[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var r="";t.allowReserved!==!0&&(r=Xi[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(r+=" await")),this.reservedWords=Jt(r);var i=(r?r+" ":"")+Xi.strict;this.reservedWordsStrict=Jt(i),this.reservedWordsStrictBind=Jt(i+" "+Xi.strictBind),this.input=String(e),this.containsEsc=!1,n?(this.pos=n,this.lineStart=this.input.lastIndexOf(`\n`,n-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(Je).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=g.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=t.sourceType==="module",this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&t.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?gn:mn),this.regexpState=null,this.privateNameStack=[]},mt={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}};Re.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};mt.inFunction.get=function(){return(this.currentVarScope().flags&gn)>0};mt.inGenerator.get=function(){return(this.currentVarScope().flags&El)>0};mt.inAsync.get=function(){return(this.currentVarScope().flags&la)>0};mt.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(xn|xr))return!1;if(n&gn)return(n&la)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};mt.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&mn)};mt.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&Ei)>0||this.options.allowSuperOutsideMethod};mt.allowDirectSuper.get=function(){return(this.currentThisScope().flags&Il)>0};mt.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};mt.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(xn|xr)||n&gn&&!(n&ca))return!0}return!1};mt.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Nl||!this.inModule&&e&mn)};mt.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&xn)>0};Re.extend=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var n=this,r=0;r<t.length;r++)n=t[r](n);return n};Re.parse=function(t,e){return new this(e,t).parse()};Re.parseExpressionAt=function(t,e,n){var r=new this(n,t,e);return r.nextToken(),r.parseExpression()};Re.tokenizer=function(t,e){return new this(e,t)};Object.defineProperties(Re.prototype,mt);var Ke=Re.prototype,jx=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;Ke.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){$e.lastIndex=t,t+=$e.exec(this.input)[0].length;var e=jx.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){$e.lastIndex=t+e[0].length;var n=$e.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===";"||i==="}"||Je.test(n[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,$e.lastIndex=t,t+=$e.exec(this.input)[0].length,this.input[t]===";"&&t++}};Ke.eat=function(t){return this.type===t?(this.next(),!0):!1};Ke.isContextual=function(t){return this.type===g.name&&this.value===t&&!this.containsEsc};Ke.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};Ke.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};Ke.canInsertSemicolon=function(){return this.type===g.eof||this.type===g.braceR||Je.test(this.input.slice(this.lastTokEnd,this.start))};Ke.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};Ke.semicolon=function(){!this.eat(g.semi)&&!this.insertSemicolon()&&this.unexpected()};Ke.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};Ke.expect=function(t){this.eat(t)||this.unexpected()};Ke.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var Ii=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};Ke.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var n=e?t.parenthesizedAssign:t.parenthesizedBind;n>-1&&this.raiseRecoverable(n,e?"Assigning to rvalue":"Parenthesized pattern")}};Ke.checkExpressionErrors=function(t,e){if(!t)return!1;var n=t.shorthandAssign,r=t.doubleProto;if(!e)return n>=0||r>=0;n>=0&&this.raise(n,"Shorthand property assignments are valid only in destructuring patterns"),r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property")};Ke.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")};Ke.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var $=Re.prototype;$.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==g.eof;){var n=this.parseStatement(null,!0,e);t.body.push(n)}if(this.inModule)for(var r=0,i=Object.keys(this.undefinedExports);r<i.length;r+=1){var s=i[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 pa={kind:"loop"},Ux={kind:"switch"};$.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;$e.lastIndex=this.pos;var e=$e.exec(this.input),n=this.pos+e[0].length,r=this.fullCharCodeAt(n);if(r===91||r===92)return!0;if(t)return!1;if(r===123)return!0;if(Wt(r)){var i=n;do n+=r<=65535?1:2;while(sn(r=this.fullCharCodeAt(n)));if(r===92)return!0;var s=this.input.slice(i,n);if(!_l.test(s))return!0}return!1};$.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;$e.lastIndex=this.pos;var t=$e.exec(this.input),e=this.pos+t[0].length,n;return!Je.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(sn(n=this.fullCharCodeAt(e+8))||n===92))};$.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;$e.lastIndex=this.pos;var n=$e.exec(this.input),r=this.pos+n[0].length;if(Je.test(this.input.slice(this.pos,r)))return!1;if(t){var i=r+5,s;if(this.input.slice(r,i)!=="using"||i===this.input.length||sn(s=this.fullCharCodeAt(i))||s===92)return!1;$e.lastIndex=i;var a=$e.exec(this.input);if(r=i+a[0].length,a&&Je.test(this.input.slice(i,r)))return!1}var o=this.fullCharCodeAt(r);if(!Wt(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(sn(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(_l.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,n){var r=this.type,i=this.startNode(),s;switch(this.isLet(t)&&(r=g._var,s="let"),r){case g._break:case g._continue:return this.parseBreakContinueStatement(i,r.keyword);case g._debugger:return this.parseDebuggerStatement(i);case g._do:return this.parseDoStatement(i);case g._for:return this.parseForStatement(i);case g._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!t);case g._class:return t&&this.unexpected(),this.parseClass(i,!0);case g._if:return this.parseIfStatement(i);case g._return:return this.parseReturnStatement(i);case g._switch:return this.parseSwitchStatement(i);case g._throw:return this.parseThrowStatement(i);case g._try:return this.parseTryStatement(i);case g._const:case g._var:return s=s||this.value,t&&s!=="var"&&this.unexpected(),this.parseVarStatement(i,s);case g._while:return this.parseWhileStatement(i);case g._with:return this.parseWithStatement(i);case g.braceL:return this.parseBlock(!0,i);case g.semi:return this.parseEmptyStatement(i);case g._export:case g._import:if(this.options.ecmaVersion>10&&r===g._import){$e.lastIndex=this.pos;var a=$e.exec(this.input),o=this.pos+a[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"\'import\' and \'export\' may only appear at the top level"),this.inModule||this.raise(this.start,"\'import\' and \'export\' may appear only with \'sourceType: module\'")),r===g._import?this.parseImport(i):this.parseExport(i,n);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!t);var c=this.isAwaitUsing(!1)?"await using":this.isUsing(!1)?"using":null;if(c)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),c==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.next(),this.parseVar(i,!1,c),this.semicolon(),this.finishNode(i,"VariableDeclaration");var u=this.value,p=this.parseExpression();return r===g.name&&p.type==="Identifier"&&this.eat(g.colon)?this.parseLabeledStatement(i,u,p,t):this.parseExpressionStatement(i,p)}};$.parseBreakContinueStatement=function(t,e){var n=e==="break";this.next(),this.eat(g.semi)||this.insertSemicolon()?t.label=null:this.type!==g.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var i=this.labels[r];if((t.label==null||i.name===t.label.name)&&(i.kind!=null&&(n||i.kind==="loop")||t.label&&n))break}return r===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,n?"BreakStatement":"ContinueStatement")};$.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};$.parseDoStatement=function(t){return this.next(),this.labels.push(pa),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(g._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(g.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};$.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(pa),this.enterScope(0),this.expect(g.parenL),this.type===g.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var n=this.isLet();if(this.type===g._var||this.type===g._const||n){var r=this.startNode(),i=n?"let":this.value;return this.next(),this.parseVar(r,!0,i),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 Ii,p=this.start,h=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===g._in||(a=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===g._in&&this.unexpected(e),t.await=!0):a&&this.options.ecmaVersion>=8&&(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))};$.parseForAfterInit=function(t,e,n){return(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===g._in?n>-1&&this.unexpected(n):t.await=n>-1),this.parseForIn(t,e)):(n>-1&&this.unexpected(n),this.parseFor(t,e))};$.parseFunctionStatement=function(t,e,n){return this.next(),this.parseFunction(t,or|(n?0:Ms),!1,e)};$.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(g._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};$.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"\'return\' outside of function"),this.next(),this.eat(g.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};$.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(g.braceL),this.labels.push(Ux),this.enterScope(Nl);for(var e,n=!1;this.type!==g.braceR;)if(this.type===g._case||this.type===g._default){var r=this.type===g._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),r?e.test=this.parseExpression():(n&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),n=!0,e.test=null),this.expect(g.colon)}else e||this.unexpected(),e.consequent.push(this.parseStatement(null));return this.exitScope(),e&&this.finishNode(e,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")};$.parseThrowStatement=function(t){return this.next(),Je.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 zx=[];$.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?Cl:0),this.checkLValPattern(t,e?Al:Xt),this.expect(g.parenR),t};$.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===g._catch){var e=this.startNode();this.next(),this.eat(g.parenL)?e.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),e.param=null,this.enterScope(0)),e.body=this.parseBlock(!1),this.exitScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(g._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};$.parseVarStatement=function(t,e,n){return this.next(),this.parseVar(t,!1,e,n),this.semicolon(),this.finishNode(t,"VariableDeclaration")};$.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(pa),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,n,r){for(var i=0,s=this.labels;i<s.length;i+=1){var a=s[i];a.name===e&&this.raise(n.start,"Label \'"+e+"\' is already declared")}for(var o=this.type.isLoop?"loop":this.type===g._switch?"switch":null,l=this.labels.length-1;l>=0;l--){var c=this.labels[l];if(c.statementStart===t.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:e,kind:o,statementStart:this.start}),t.body=this.parseStatement(r?r.indexOf("label")===-1?r+"label":r:"label"),this.labels.pop(),t.label=n,this.finishNode(t,"LabeledStatement")};$.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};$.parseBlock=function(t,e,n){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(g.braceL),t&&this.enterScope(0);this.type!==g.braceR;){var r=this.parseStatement(null);e.body.push(r)}return n&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};$.parseFor=function(t,e){return t.init=e,this.expect(g.semi),t.test=this.type===g.semi?null:this.parseExpression(),this.expect(g.semi),t.update=this.type===g.parenR?null:this.parseExpression(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};$.parseForIn=function(t,e){var n=this.type===g._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!n||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(n?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=n?this.parseExpression():this.parseMaybeAssign(),this.expect(g.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,n?"ForInStatement":"ForOfStatement")};$.parseVar=function(t,e,n,r){for(t.declarations=[],t.kind=n;;){var i=this.startNode();if(this.parseVarId(i,n),this.eat(g.eq)?i.init=this.parseMaybeAssign(e):!r&&n==="const"&&!(this.type===g._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!r&&(n==="using"||n==="await using")&&this.options.ecmaVersion>=17&&this.type!==g._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+n+" declaration"):!r&&i.id.type!=="Identifier"&&!(e&&(this.type===g._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):i.init=null,t.declarations.push(this.finishNode(i,"VariableDeclarator")),!this.eat(g.comma))break}return t};$.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?ha:Xt,!1)};var or=1,Ms=2,Tl=4;$.parseFunction=function(t,e,n,r,i){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===g.star&&e&Ms&&this.unexpected(),t.generator=this.eat(g.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&or&&(t.id=e&Tl&&this.type!==g.name?null:this.parseIdent(),t.id&&!(e&Ms)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?ha:Xt:kl));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(ua(t.async,t.generator)),e&or||(t.id=this.type===g.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,n,!1,i),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(t,e&or?"FunctionDeclaration":"FunctionExpression")};$.parseFunctionParams=function(t){this.expect(g.parenL),t.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};$.parseClass=function(t,e){this.next();var n=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var r=this.enterClassBody(),i=this.startNode(),s=!1;for(i.body=[],this.expect(g.braceL);this.type!==g.braceR;){var a=this.parseClassElement(t.superClass!==null);a&&(i.body.push(a),a.type==="MethodDefinition"&&a.kind==="constructor"?(s&&this.raiseRecoverable(a.start,"Duplicate constructor in the same class"),s=!0):a.key&&a.key.type==="PrivateIdentifier"&&qx(r,a)&&this.raiseRecoverable(a.key.start,"Identifier \'#"+a.key.name+"\' has already been declared"))}return this.strict=n,this.next(),t.body=this.finishNode(i,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};$.parseClassElement=function(t){if(this.eat(g.semi))return null;var e=this.options.ecmaVersion,n=this.startNode(),r="",i=!1,s=!1,a="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(g.braceL))return this.parseClassStaticBlock(n),n;this.isClassElementNameStart()||this.type===g.star?o=!0:r="static"}if(n.static=o,!r&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===g.star)&&!this.canInsertSemicolon()?s=!0:r="async"),!r&&(e>=9||!s)&&this.eat(g.star)&&(i=!0),!r&&!s&&!i){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?a=l:r=l)}if(r?(n.computed=!1,n.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),n.key.name=r,this.finishNode(n.key,"Identifier")):this.parseClassElementName(n),e<13||this.type===g.parenL||a!=="method"||i||s){var c=!n.static&&ri(n,"constructor"),u=c&&t;c&&a!=="method"&&this.raise(n.key.start,"Constructor can\'t have get/set modifier"),n.kind=c?"constructor":a,this.parseClassMethod(n,i,s,u)}else this.parseClassField(n);return n};$.isClassElementNameStart=function(){return this.type===g.name||this.type===g.privateId||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword};$.parseClassElementName=function(t){this.type===g.privateId?(this.value==="constructor"&&this.raise(this.start,"Classes can\'t have an element named \'#constructor\'"),t.computed=!1,t.key=this.parsePrivateIdent()):this.parsePropertyName(t)};$.parseClassMethod=function(t,e,n,r){var i=t.key;t.kind==="constructor"?(e&&this.raise(i.start,"Constructor can\'t be a generator"),n&&this.raise(i.start,"Constructor can\'t be an async method")):t.static&&ri(t,"prototype")&&this.raise(i.start,"Classes may not have a static property named prototype");var s=t.value=this.parseMethod(e,n,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")};$.parseClassField=function(t){return ri(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&ri(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(g.eq)?(this.enterScope(xr|Ei),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(xn|Ei);this.type!==g.braceR;){var n=this.parseStatement(null);t.body.push(n)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};$.parseClassId=function(t,e){this.type===g.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,Xt,!1)):(e===!0&&this.unexpected(),t.id=null)};$.parseClassSuper=function(t){t.superClass=this.eat(g._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,n=t.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,i=r===0?null:this.privateNameStack[r-1],s=0;s<n.length;++s){var a=n[s];Un(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function qx(t,e){var n=e.key.name,r=t[n],i="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(i=(e.static?"s":"i")+e.kind),r==="iget"&&i==="iset"||r==="iset"&&i==="iget"||r==="sget"&&i==="sset"||r==="sset"&&i==="sget"?(t[n]="true",!1):r?!0:(t[n]=i,!1)}function ri(t,e){var n=t.computed,r=t.key;return!n&&(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!==g.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(g.star))return this.parseExportAllDeclaration(t,e);if(this.eat(g._default))return this.checkExport(e,"default",this.lastTokStart),t.declaration=this.parseExportDefaultDeclaration(),this.finishNode(t,"ExportDefaultDeclaration");if(this.shouldParseExportStatement())t.declaration=this.parseExportDeclaration(t),t.declaration.type==="VariableDeclaration"?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id,t.declaration.id.start),t.specifiers=[],t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[]);else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))this.type!==g.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var n=0,r=t.specifiers;n<r.length;n+=1){var i=r[n];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type==="Literal"&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[])}this.semicolon()}return this.finishNode(t,"ExportNamedDeclaration")};$.parseExportDeclaration=function(t){return this.parseStatement(null)};$.parseExportDefaultDeclaration=function(){var t;if(this.type===g._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,or|Tl,!1,t)}else if(this.type===g._class){var n=this.startNode();return this.parseClass(n,"nullableID")}else{var r=this.parseMaybeAssign();return this.semicolon(),r}};$.checkExport=function(t,e,n){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),Un(t,e)&&this.raiseRecoverable(n,"Duplicate export \'"+e+"\'"),t[e]=!0)};$.checkPatternExport=function(t,e){var n=e.type;if(n==="Identifier")this.checkExport(t,e,e.start);else if(n==="ObjectPattern")for(var r=0,i=e.properties;r<i.length;r+=1){var s=i[r];this.checkPatternExport(t,s)}else if(n==="ArrayPattern")for(var a=0,o=e.elements;a<o.length;a+=1){var l=o[a];l&&this.checkPatternExport(t,l)}else n==="Property"?this.checkPatternExport(t,e.value):n==="AssignmentPattern"?this.checkPatternExport(t,e.left):n==="RestElement"&&this.checkPatternExport(t,e.argument)};$.checkVariableExport=function(t,e){if(t)for(var n=0,r=e;n<r.length;n+=1){var i=r[n];this.checkPatternExport(t,i.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=[],n=!0;for(this.expect(g.braceL);!this.eat(g.braceR);){if(n)n=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;e.push(this.parseExportSpecifier(t))}return e};$.parseImport=function(t){return this.next(),this.type===g.string?(t.specifiers=zx,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===g.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};$.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,Xt),this.finishNode(t,"ImportSpecifier")};$.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,Xt),this.finishNode(t,"ImportDefaultSpecifier")};$.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,Xt),this.finishNode(t,"ImportNamespaceSpecifier")};$.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===g.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(g.comma)))return t;if(this.type===g.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(g.braceL);!this.eat(g.braceR);){if(e)e=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;t.push(this.parseImportSpecifier())}return t};$.parseWithClause=function(){var t=[];if(!this.eat(g._with))return t;this.expect(g.braceL);for(var e={},n=!0;!this.eat(g.braceR);){if(n)n=!1;else if(this.expect(g.comma),this.afterTrailingComma(g.braceR))break;var r=this.parseImportAttribute(),i=r.key.type==="Identifier"?r.key.name:r.key.value;Un(e,i)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key \'"+i+"\'"),e[i]=!0,t.push(r)}return t};$.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(g.colon),this.type!==g.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};$.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===g.string){var t=this.parseLiteral(this.value);return Vx.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 yt=Re.prototype;yt.toAssignable=function(t,e,n){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",n&&this.checkPatternErrors(n,!0);for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[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",n&&this.checkPatternErrors(n,!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,n);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 n&&this.checkPatternErrors(n,!0);return t};yt.toAssignableList=function(t,e){for(var n=t.length,r=0;r<n;r++){var i=t[r];i&&this.toAssignable(i,e)}if(n){var s=t[n-1];this.options.ecmaVersion===6&&e&&s&&s.type==="RestElement"&&s.argument.type!=="Identifier"&&this.unexpected(s.argument.start)}return t};yt.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};yt.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==g.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};yt.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case g.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(g.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case g.braceL:return this.parseObj(!0)}return this.parseIdent()};yt.parseBindingList=function(t,e,n,r){for(var i=[],s=!0;!this.eat(t);)if(s?s=!1:this.expect(g.comma),e&&this.type===g.comma)i.push(null);else{if(n&&this.afterTrailingComma(t))break;if(this.type===g.ellipsis){var a=this.parseRestBinding();this.parseBindingListItem(a),i.push(a),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else i.push(this.parseAssignableListItem(r))}return i};yt.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};yt.parseBindingListItem=function(t){return t};yt.parseMaybeDefault=function(t,e,n){if(n=n||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(g.eq))return n;var r=this.startNodeAt(t,e);return r.left=n,r.right=this.parseMaybeAssign(),this.finishNode(r,"AssignmentPattern")};yt.checkLValSimple=function(t,e,n){e===void 0&&(e=ni);var r=e!==ni;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===Xt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),n&&(Un(n,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),n[t.name]=!0),e!==Ml&&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,n);default:this.raise(t.start,(r?"Binding":"Assigning to")+" rvalue")}};yt.checkLValPattern=function(t,e,n){switch(e===void 0&&(e=ni),t.type){case"ObjectPattern":for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];this.checkLValInnerPattern(s,e,n)}break;case"ArrayPattern":for(var a=0,o=t.elements;a<o.length;a+=1){var l=o[a];l&&this.checkLValInnerPattern(l,e,n)}break;default:this.checkLValSimple(t,e,n)}};yt.checkLValInnerPattern=function(t,e,n){switch(e===void 0&&(e=ni),t.type){case"Property":this.checkLValInnerPattern(t.value,e,n);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,n);break;case"RestElement":this.checkLValPattern(t.argument,e,n);break;default:this.checkLValPattern(t,e,n)}};var bt=function(t,e,n,r,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!n,this.override=r,this.generator=!!i},be={b_stat:new bt("{",!1),b_expr:new bt("{",!0),b_tmpl:new bt("${",!1),p_stat:new bt("(",!1),p_expr:new bt("(",!0),q_tmpl:new bt("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new bt("function",!1),f_expr:new bt("function",!0),f_expr_gen:new bt("function",!0,!1,null,!0),f_gen:new bt("function",!1,!1,null,!0)},zn=Re.prototype;zn.initialContext=function(){return[be.b_stat]};zn.curContext=function(){return this.context[this.context.length-1]};zn.braceIsBlock=function(t){var e=this.curContext();return e===be.f_expr||e===be.f_stat?!0:t===g.colon&&(e===be.b_stat||e===be.b_expr)?!e.isExpr:t===g._return||t===g.name&&this.exprAllowed?Je.test(this.input.slice(this.lastTokEnd,this.start)):t===g._else||t===g.semi||t===g.eof||t===g.parenR||t===g.arrow?!0:t===g.braceL?e===be.b_stat:t===g._var||t===g._const||t===g.name?!1:!this.exprAllowed};zn.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};zn.updateContext=function(t){var e,n=this.type;n.keyword&&t===g.dot?this.exprAllowed=!1:(e=n.updateContext)?e.call(this,t):this.exprAllowed=n.beforeExpr};zn.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};g.parenR.updateContext=g.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===be.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};g.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?be.b_stat:be.b_expr),this.exprAllowed=!0};g.dollarBraceL.updateContext=function(){this.context.push(be.b_tmpl),this.exprAllowed=!0};g.parenL.updateContext=function(t){var e=t===g._if||t===g._for||t===g._with||t===g._while;this.context.push(e?be.p_stat:be.p_expr),this.exprAllowed=!0};g.incDec.updateContext=function(){};g._function.updateContext=g._class.updateContext=function(t){t.beforeExpr&&t!==g._else&&!(t===g.semi&&this.curContext()!==be.p_stat)&&!(t===g._return&&Je.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===g.colon||t===g.braceL)&&this.curContext()===be.b_stat)?this.context.push(be.f_expr):this.context.push(be.f_stat),this.exprAllowed=!1};g.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};g.backQuote.updateContext=function(){this.curContext()===be.q_tmpl?this.context.pop():this.context.push(be.q_tmpl),this.exprAllowed=!1};g.star.updateContext=function(t){if(t===g._function){var e=this.context.length-1;this.context[e]===be.f_expr?this.context[e]=be.f_expr_gen:this.context[e]=be.f_gen}this.exprAllowed=!0};g.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==g.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var X=Re.prototype;X.checkPropClash=function(t,e,n){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var r=t.key,i;switch(r.type){case"Identifier":i=r.name;break;case"Literal":i=String(r.value);break;default:return}var s=t.kind;if(this.options.ecmaVersion>=6){i==="__proto__"&&s==="init"&&(e.proto&&(n?n.doubleProto<0&&(n.doubleProto=r.start):this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0);return}i="$"+i;var a=e[i];if(a){var o;s==="init"?o=this.strict&&a.init||a.get||a.set:o=a.init||a[s],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else a=e[i]={init:!1,get:!1,set:!1};a[s]=!0}};X.parseExpression=function(t,e){var n=this.start,r=this.startLoc,i=this.parseMaybeAssign(t,e);if(this.type===g.comma){var s=this.startNodeAt(n,r);for(s.expressions=[i];this.eat(g.comma);)s.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(s,"SequenceExpression")}return i};X.parseMaybeAssign=function(t,e,n){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var r=!1,i=-1,s=-1,a=-1;e?(i=e.parenthesizedAssign,s=e.trailingComma,a=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new Ii,r=!0);var o=this.start,l=this.startLoc;(this.type===g.parenL||this.type===g.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(n&&(c=n.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===g.eq&&(c=this.toAssignable(c,!1,e)),r||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===g.eq?this.checkLValPattern(c):this.checkLValSimple(c),u.left=c,this.next(),u.right=this.parseMaybeAssign(t),a>-1&&(e.doubleProto=a),this.finishNode(u,"AssignmentExpression")}else r&&this.checkExpressionErrors(e,!0);return i>-1&&(e.parenthesizedAssign=i),s>-1&&(e.trailingComma=s),c};X.parseMaybeConditional=function(t,e){var n=this.start,r=this.startLoc,i=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return i;if(this.eat(g.question)){var s=this.startNodeAt(n,r);return s.test=i,s.consequent=this.parseMaybeAssign(),this.expect(g.colon),s.alternate=this.parseMaybeAssign(t),this.finishNode(s,"ConditionalExpression")}return i};X.parseExprOps=function(t,e){var n=this.start,r=this.startLoc,i=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||i.start===n&&i.type==="ArrowFunctionExpression"?i:this.parseExprOp(i,n,r,-1,t)};X.parseExprOp=function(t,e,n,r,i){var s=this.type.binop;if(s!=null&&(!i||this.type!==g._in)&&s>r){var a=this.type===g.logicalOR||this.type===g.logicalAND,o=this.type===g.coalesce;o&&(s=g.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,p=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),c,u,s,i),h=this.buildBinary(e,n,t,p,l,a||o);return(a&&this.type===g.coalesce||o&&(this.type===g.logicalOR||this.type===g.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(h,e,n,r,i)}return t};X.buildBinary=function(t,e,n,r,i,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=n,a.operator=i,a.right=r,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")};X.parseMaybeUnary=function(t,e,n,r){var i=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===g.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"&&Pl(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Ts(o.argument)?this.raiseRecoverable(o.start,"Private fields can not be deleted"):e=!0,a=this.finishNode(o,l?"UpdateExpression":"UnaryExpression")}else if(!e&&this.type===g.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),a=this.parsePrivateIdent(),this.type!==g._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(i,s);c.operator=this.value,c.prefix=!1,c.argument=a,this.checkLValSimple(a),this.next(),a=this.finishNode(c,"UpdateExpression")}}if(!n&&this.eat(g.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(i,s,a,this.parseMaybeUnary(null,!1,!1,r),"**",!1);else return a};function Pl(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&Pl(t.expression)}function Ts(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&Ts(t.expression)||t.type==="ParenthesizedExpression"&&Ts(t.expression)}X.parseExprSubscripts=function(t,e){var n=this.start,r=this.startLoc,i=this.parseExprAtom(t,e);if(i.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return i;var s=this.parseSubscripts(i,n,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};X.parseSubscripts=function(t,e,n,r,i){for(var s=this.options.ecmaVersion>=8&&t.type==="Identifier"&&t.name==="async"&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&t.end-t.start===5&&this.potentialArrowAt===t.start,a=!1;;){var o=this.parseSubscript(t,e,n,r,s,a,i);if(o.optional&&(a=!0),o===t||o.type==="ArrowFunctionExpression"){if(a){var l=this.startNodeAt(e,n);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};X.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(g.arrow)};X.parseSubscriptAsyncArrow=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!0,r)};X.parseSubscript=function(t,e,n,r,i,s,a){var o=this.options.ecmaVersion>=11,l=o&&this.eat(g.questionDot);r&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(g.bracketL);if(c||l&&this.type!==g.parenL&&this.type!==g.backQuote||this.eat(g.dot)){var u=this.startNodeAt(e,n);u.object=t,c?(u.property=this.parseExpression(),this.expect(g.bracketR)):this.type===g.privateId&&t.type!=="Super"?u.property=this.parsePrivateIdent():u.property=this.parseIdent(this.options.allowReserved!=="never"),u.computed=!!c,o&&(u.optional=l),t=this.finishNode(u,"MemberExpression")}else if(!r&&this.eat(g.parenL)){var p=new Ii,h=this.yieldPos,d=this.awaitPos,f=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1,p);if(i&&!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=d,this.awaitIdentPos=f,this.parseSubscriptAsyncArrow(e,n,m,a);this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=d||this.awaitPos,this.awaitIdentPos=f||this.awaitIdentPos;var _=this.startNodeAt(e,n);_.callee=t,_.arguments=m,o&&(_.optional=l),t=this.finishNode(_,"CallExpression")}else if(this.type===g.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,n);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};X.parseExprAtom=function(t,e,n){this.type===g.slash&&this.readRegexp();var r,i=this.potentialArrowAt===this.start;switch(this.type){case g._super:return this.allowSuper||this.raise(this.start,"\'super\' keyword outside a method"),r=this.startNode(),this.next(),this.type===g.parenL&&!this.allowDirectSuper&&this.raise(r.start,"super() call outside constructor of a subclass"),this.type!==g.dot&&this.type!==g.bracketL&&this.type!==g.parenL&&this.unexpected(),this.finishNode(r,"Super");case g._this:return r=this.startNode(),this.next(),this.finishNode(r,"ThisExpression");case g.name:var s=this.start,a=this.startLoc,o=this.containsEsc,l=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!o&&l.name==="async"&&!this.canInsertSemicolon()&&this.eat(g._function))return this.overrideContext(be.f_expr),this.parseFunction(this.startNodeAt(s,a),0,!1,!0,e);if(i&&!this.canInsertSemicolon()){if(this.eat(g.arrow))return this.parseArrowExpression(this.startNodeAt(s,a),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===g.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(g.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,a),[l],!0,e)}return l;case g.regexp:var c=this.value;return r=this.parseLiteral(c.value),r.regex={pattern:c.pattern,flags:c.flags},r;case g.num:case g.string:return this.parseLiteral(this.value);case g._null:case g._true:case g._false:return r=this.startNode(),r.value=this.type===g._null?null:this.type===g._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,"Literal");case g.parenL:var u=this.start,p=this.parseParenAndDistinguishExpression(i,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),p;case g.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(g.bracketR,!0,!0,t),this.finishNode(r,"ArrayExpression");case g.braceL:return this.overrideContext(be.b_expr),this.parseObj(!1,t);case g._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case g._class:return this.parseClass(this.startNode(),!1);case g._new:return this.parseNew();case g.backQuote:return this.parseTemplate();case g._import:return this.options.ecmaVersion>=11?this.parseExprImport(n):this.unexpected();default:return this.parseExprAtomDefault()}};X.parseExprAtomDefault=function(){this.unexpected()};X.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===g.parenL&&!t)return this.parseDynamicImport(e);if(this.type===g.dot){var n=this.startNodeAt(e.start,e.loc&&e.loc.start);return n.name="import",e.meta=this.finishNode(n,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};X.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(g.parenR)?t.options=null:(this.expect(g.comma),this.afterTrailingComma(g.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(g.parenR)||(this.expect(g.comma),this.afterTrailingComma(g.parenR)||this.unexpected())));else if(!this.eat(g.parenR)){var e=this.start;this.eat(g.comma)&&this.eat(g.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};X.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")};X.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")};X.parseParenExpression=function(){this.expect(g.parenL);var t=this.parseExpression();return this.expect(g.parenR),t};X.shouldParseArrow=function(t){return!this.canInsertSemicolon()};X.parseParenAndDistinguishExpression=function(t,e){var n=this.start,r=this.startLoc,i,s=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var a=this.start,o=this.startLoc,l=[],c=!0,u=!1,p=new Ii,h=this.yieldPos,d=this.awaitPos,f;for(this.yieldPos=0,this.awaitPos=0;this.type!==g.parenR;)if(c?c=!1:this.expect(g.comma),s&&this.afterTrailingComma(g.parenR,!0)){u=!0;break}else if(this.type===g.ellipsis){f=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else l.push(this.parseMaybeAssign(!1,p,this.parseParenItem));var m=this.lastTokEnd,_=this.lastTokEndLoc;if(this.expect(g.parenR),t&&this.shouldParseArrow(l)&&this.eat(g.arrow))return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=h,this.awaitPos=d,this.parseParenArrowList(n,r,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),f&&this.unexpected(f),this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=d||this.awaitPos,l.length>1?(i=this.startNodeAt(a,o),i.expressions=l,this.finishNodeAt(i,"SequenceExpression",m,_)):i=l[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var b=this.startNodeAt(n,r);return b.expression=i,this.finishNode(b,"ParenthesizedExpression")}else return i};X.parseParenItem=function(t){return t};X.parseParenArrowList=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!1,r)};var Hx=[];X.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword new");var t=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===g.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var n=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\'"),n&&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,i=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,i,!0,!1),this.eat(g.parenL)?t.arguments=this.parseExprList(g.parenR,this.options.ecmaVersion>=8,!1):t.arguments=Hx,this.finishNode(t,"NewExpression")};X.parseTemplateElement=function(t){var e=t.isTagged,n=this.startNode();return this.type===g.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),n.value={raw:this.value.replace(/\\r\\n?/g,`\n`),cooked:null}):n.value={raw:this.input.slice(this.start,this.end).replace(/\\r\\n?/g,`\n`),cooked:this.value},this.next(),n.tail=this.type===g.backQuote,this.finishNode(n,"TemplateElement")};X.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var n=this.startNode();this.next(),n.expressions=[];var r=this.parseTemplateElement({isTagged:e});for(n.quasis=[r];!r.tail;)this.type===g.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(g.dollarBraceL),n.expressions.push(this.parseExpression()),this.expect(g.braceR),n.quasis.push(r=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(n,"TemplateLiteral")};X.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===g.name||this.type===g.num||this.type===g.string||this.type===g.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===g.star)&&!Je.test(this.input.slice(this.lastTokEnd,this.start))};X.parseObj=function(t,e){var n=this.startNode(),r=!0,i={};for(n.properties=[],this.next();!this.eat(g.braceR);){if(r)r=!1;else if(this.expect(g.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(g.braceR))break;var s=this.parseProperty(t,e);t||this.checkPropClash(s,i,e),n.properties.push(s)}return this.finishNode(n,t?"ObjectPattern":"ObjectExpression")};X.parseProperty=function(t,e){var n=this.startNode(),r,i,s,a;if(this.options.ecmaVersion>=9&&this.eat(g.ellipsis))return t?(n.argument=this.parseIdent(!1),this.type===g.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(n,"RestElement")):(n.argument=this.parseMaybeAssign(!1,e),this.type===g.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(n,"SpreadElement"));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(t||e)&&(s=this.start,a=this.startLoc),t||(r=this.eat(g.star)));var o=this.containsEsc;return this.parsePropertyName(n),!t&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(n)?(i=!0,r=this.options.ecmaVersion>=9&&this.eat(g.star),this.parsePropertyName(n)):i=!1,this.parsePropertyValue(n,t,r,i,s,a,e,o),this.finishNode(n,"Property")};X.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var n=t.kind==="get"?0:1;if(t.value.params.length!==n){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")};X.parsePropertyValue=function(t,e,n,r,i,s,a,o){(n||r)&&this.type===g.colon&&this.unexpected(),this.eat(g.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init"):this.options.ecmaVersion>=6&&this.type===g.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(n,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!==g.comma&&this.type!==g.braceR&&this.type!==g.eq?((n||r)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((n||r)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=i),e?t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key)):this.type===g.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};X.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(g.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(g.bracketR),t.key;t.computed=!1}return t.key=this.type===g.num||this.type===g.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};X.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};X.parseMethod=function(t,e,n){var r=this.startNode(),i=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(ua(e,r.generator)|Ei|(n?Il:0)),this.expect(g.parenL),r.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(r,"FunctionExpression")};X.parseArrowExpression=function(t,e,n,r){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(ua(n,!1)|ca),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!n),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,r),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(t,"ArrowFunctionExpression")};X.parseFunctionBody=function(t,e,n,r){var i=e&&this.type!==g.braceL,s=this.strict,a=!1;if(i)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&&!n&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,Ml),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};X.isSimpleParamList=function(t){for(var e=0,n=t;e<n.length;e+=1){var r=n[e];if(r.type!=="Identifier")return!1}return!0};X.checkParams=function(t,e){for(var n=Object.create(null),r=0,i=t.params;r<i.length;r+=1){var s=i[r];this.checkLValInnerPattern(s,ha,e?null:n)}};X.parseExprList=function(t,e,n,r){for(var i=[],s=!0;!this.eat(t);){if(s)s=!1;else if(this.expect(g.comma),e&&this.afterTrailingComma(t))break;var a=void 0;n&&this.type===g.comma?a=null:this.type===g.ellipsis?(a=this.parseSpread(r),r&&this.type===g.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):a=this.parseMaybeAssign(!1,r),i.push(a)}return i};X.checkUnreserved=function(t){var e=t.start,n=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&Ci)&&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,n).indexOf("\\\\")!==-1)){var i=this.strict?this.reservedWordsStrict:this.reservedWords;i.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"))}};X.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};X.parseIdentNode=function(){var t=this.startNode();return this.type===g.name?t.name=this.value:this.type.keyword?(t.name=this.type.keyword,(t.name==="class"||t.name==="function")&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=g.name):this.unexpected(),t};X.parsePrivateIdent=function(){var t=this.startNode();return this.type===g.privateId?t.name=this.value:this.unexpected(),this.next(),this.finishNode(t,"PrivateIdentifier"),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(t.start,"Private field \'#"+t.name+"\' must be declared in an enclosing class"):this.privateNameStack[this.privateNameStack.length-1].used.push(t)),t};X.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===g.semi||this.canInsertSemicolon()||this.type!==g.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(g.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};X.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 ii=Re.prototype;ii.raise=function(t,e){var n=Sl(this.input,t);e+=" ("+n.line+":"+n.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var r=new SyntaxError(e);throw r.pos=t,r.loc=n,r.raisedAt=this.pos,r};ii.raiseRecoverable=ii.raise;ii.curPosition=function(){if(this.options.locations)return new mr(this.curLine,this.pos-this.lineStart)};var ln=Re.prototype,Kx=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};ln.enterScope=function(t){this.scopeStack.push(new Kx(t))};ln.exitScope=function(){this.scopeStack.pop()};ln.treatFunctionsAsVarInScope=function(t){return t.flags&gn||!this.inModule&&t.flags&mn};ln.declareName=function(t,e,n){var r=!1;if(e===Xt){var i=this.currentScope();r=i.lexical.indexOf(t)>-1||i.functions.indexOf(t)>-1||i.var.indexOf(t)>-1,i.lexical.push(t),this.inModule&&i.flags&mn&&delete this.undefinedExports[t]}else if(e===Al){var s=this.currentScope();s.lexical.push(t)}else if(e===kl){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&Cl&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&mn&&delete this.undefinedExports[t],l.flags&Ci)break}r&&this.raiseRecoverable(n,"Identifier \'"+t+"\' has already been declared")};ln.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};ln.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};ln.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(Ci|xr|xn))return e}};ln.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(Ci|xr|xn)&&!(e.flags&ca))return e}};var Ni=function(t,e,n){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new Si(t,n)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},_r=Re.prototype;_r.startNode=function(){return new Ni(this,this.start,this.startLoc)};_r.startNodeAt=function(t,e){return new Ni(this,t,e)};function Dl(t,e,n,r){return t.type=e,t.end=n,this.options.locations&&(t.loc.end=r),this.options.ranges&&(t.range[1]=n),t}_r.finishNode=function(t,e){return Dl.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};_r.finishNodeAt=function(t,e,n,r){return Dl.call(this,t,e,n,r)};_r.copyNode=function(t){var e=new Ni(this,t.start,this.startLoc);for(var n in t)e[n]=t[n];return e};var Yx="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",Rl="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",Ol=Rl+" Extended_Pictographic",Ll=Ol,Fl=Ll+" EBase EComp EMod EPres ExtPict",Bl=Fl,Gx=Bl,Xx={9:Rl,10:Ol,11:Ll,12:Fl,13:Bl,14:Gx},Zx="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Qx={9:"",10:"",11:"",12:"",13:"",14:Zx},yo="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",Vl="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",Wl=Vl+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",$l=Wl+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",jl=$l+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",Ul=jl+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",Jx=Ul+" "+Yx,e_={9:Vl,10:Wl,11:$l,12:jl,13:Ul,14:Jx},zl={};function t_(t){var e=zl[t]={binary:Jt(Xx[t]+" "+yo),binaryOfStrings:Jt(Qx[t]),nonBinary:{General_Category:Jt(yo),Script:Jt(e_[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(Tr=0,Qi=[9,10,11,12,13,14];Tr<Qi.length;Tr+=1)go=Qi[Tr],t_(go);var go,Tr,Qi,W=Re.prototype,si=function(t,e){this.parent=t,this.base=e||this};si.prototype.separatedFrom=function(t){for(var e=this;e;e=e.parent)for(var n=t;n;n=n.parent)if(e.base===n.base&&e!==n)return!0;return!1};si.prototype.sibling=function(){return new si(this.parent,this.base)};var $t=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":"")+(t.options.ecmaVersion>=13?"d":"")+(t.options.ecmaVersion>=15?"v":""),this.unicodeProperties=zl[t.options.ecmaVersion>=14?14:t.options.ecmaVersion],this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};$t.prototype.reset=function(t,e,n){var r=n.indexOf("v")!==-1,i=n.indexOf("u")!==-1;this.start=t|0,this.source=e+"",this.flags=n,r&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)};$t.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};$t.prototype.at=function(t,e){e===void 0&&(e=!1);var n=this.source,r=n.length;if(t>=r)return-1;var i=n.charCodeAt(t);if(!(e||this.switchU)||i<=55295||i>=57344||t+1>=r)return i;var s=n.charCodeAt(t+1);return s>=56320&&s<=57343?(i<<10)+s-56613888:i};$t.prototype.nextIndex=function(t,e){e===void 0&&(e=!1);var n=this.source,r=n.length;if(t>=r)return r;var i=n.charCodeAt(t),s;return!(e||this.switchU)||i<=55295||i>=57344||t+1>=r||(s=n.charCodeAt(t+1))<56320||s>57343?t+1:t+2};$t.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};$t.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};$t.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};$t.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};$t.prototype.eatChars=function(t,e){e===void 0&&(e=!1);for(var n=this.pos,r=0,i=t;r<i.length;r+=1){var s=i[r],a=this.at(n,e);if(a===-1||a!==s)return!1;n=this.nextIndex(n,e)}return this.pos=n,!0};W.validateRegExpFlags=function(t){for(var e=t.validFlags,n=t.flags,r=!1,i=!1,s=0;s<n.length;s++){var a=n.charAt(s);e.indexOf(a)===-1&&this.raise(t.start,"Invalid regular expression flag"),n.indexOf(a,s+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),a==="u"&&(r=!0),a==="v"&&(i=!0)}this.options.ecmaVersion>=15&&r&&i&&this.raise(t.start,"Invalid regular expression flag")};function n_(t){for(var e in t)return!0;return!1}W.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&n_(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};W.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,n=t.backReferenceNames;e<n.length;e+=1){var r=n[e];t.groupNames[r]||t.raise("Invalid named capture referenced")}};W.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new si(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")};W.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};W.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};W.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 n=!1;if(this.options.ecmaVersion>=9&&(n=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!n,!0}return t.pos=e,!1};W.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};W.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};W.regexp_eatBracedQuantifier=function(t,e){var n=t.pos;if(t.eat(123)){var r=0,i=-1;if(this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(i=t.lastIntValue),t.eat(125)))return i!==-1&&i<r&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=n}return!1};W.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)};W.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};W.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var n=this.regexp_eatModifiers(t),r=t.eat(45);if(n||r){for(var i=0;i<n.length;i++){var s=n.charAt(i);n.indexOf(s,i+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(r){var a=this.regexp_eatModifiers(t);!n&&!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||n.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};W.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};W.regexp_eatModifiers=function(t){for(var e="",n=0;(n=t.current())!==-1&&r_(n);)e+=Yt(n),t.advance();return e};function r_(t){return t===105||t===109||t===115}W.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)};W.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};W.regexp_eatSyntaxCharacter=function(t){var e=t.current();return ql(e)?(t.lastIntValue=e,t.advance(),!0):!1};function ql(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}W.regexp_eatPatternCharacters=function(t){for(var e=t.pos,n=0;(n=t.current())!==-1&&!ql(n);)t.advance();return t.pos!==e};W.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};W.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,n=t.groupNames[t.lastStringValue];if(n)if(e)for(var r=0,i=n;r<i.length;r+=1){var s=i[r];s.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(n||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};W.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};W.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=Yt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=Yt(t.lastIntValue);return!0}return!1};W.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,n=this.options.ecmaVersion>=11,r=t.current(n);return t.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,n)&&(r=t.lastIntValue),i_(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function i_(t){return Wt(t,!0)||t===36||t===95}W.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,n=this.options.ecmaVersion>=11,r=t.current(n);return t.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,n)&&(r=t.lastIntValue),s_(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function s_(t){return sn(t,!0)||t===36||t===95||t===8204||t===8205}W.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)};W.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var n=t.lastIntValue;if(t.switchU)return n>t.maxBackReference&&(t.maxBackReference=n),!0;if(n<=t.numCapturingParens)return!0;t.pos=e}return!1};W.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};W.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)};W.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};W.regexp_eatZero=function(t){return t.current()===48&&!ki(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};W.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};W.regexp_eatControlLetter=function(t){var e=t.current();return Hl(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function Hl(t){return t>=65&&t<=90||t>=97&&t<=122}W.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var n=t.pos,r=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(r&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var a=t.lastIntValue;if(a>=56320&&a<=57343)return t.lastIntValue=(i-55296)*1024+(a-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(r&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&a_(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=n}return!1};function a_(t){return t>=0&&t<=1114111}W.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};W.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 Kl=0,Gt=1,dt=2;W.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(o_(e))return t.lastIntValue=-1,t.advance(),Gt;var n=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((n=e===80)||e===112)){t.lastIntValue=-1,t.advance();var r;if(t.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return n&&r===dt&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return Kl};function o_(t){return t===100||t===68||t===115||t===83||t===119||t===87}W.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var n=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,n,r),Gt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return Kl};W.regexp_validateUnicodePropertyNameAndValue=function(t,e,n){Un(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(n)||t.raise("Invalid property value")};W.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return Gt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return dt;t.raise("Invalid property name")};W.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";Yl(e=t.current());)t.lastStringValue+=Yt(e),t.advance();return t.lastStringValue!==""};function Yl(t){return Hl(t)||t===95}W.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";l_(e=t.current());)t.lastStringValue+=Yt(e),t.advance();return t.lastStringValue!==""};function l_(t){return Yl(t)||ki(t)}W.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};W.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),n=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&n===dt&&t.raise("Negated character class may contain strings"),!0}return!1};W.regexp_classContents=function(t){return t.current()===93?Gt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),Gt)};W.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var n=t.lastIntValue;t.switchU&&(e===-1||n===-1)&&t.raise("Invalid character class"),e!==-1&&n!==-1&&e>n&&t.raise("Range out of order in character class")}}};W.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var n=t.current();(n===99||Zl(n))&&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};W.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)};W.regexp_classSetExpression=function(t){var e=Gt,n;if(!this.regexp_eatClassSetRange(t))if(n=this.regexp_eatClassSetOperand(t)){n===dt&&(e=dt);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(n=this.regexp_eatClassSetOperand(t))){n!==dt&&(e=Gt);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(n=this.regexp_eatClassSetOperand(t),!n)return e;n===dt&&(e=dt)}};W.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var n=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;return n!==-1&&r!==-1&&n>r&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};W.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?Gt:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};W.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var n=t.eat(94),r=this.regexp_classContents(t);if(t.eat(93))return n&&r===dt&&t.raise("Negated character class may contain strings"),r;t.pos=e}if(t.eat(92)){var i=this.regexp_eatCharacterClassEscape(t);if(i)return i;t.pos=e}return null};W.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var n=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return n}else t.raise("Invalid escape");t.pos=e}return null};W.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===dt&&(e=dt);return e};W.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?Gt:dt};W.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 n=t.current();return n<0||n===t.lookahead()&&c_(n)||u_(n)?!1:(t.advance(),t.lastIntValue=n,!0)};function c_(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 u_(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}W.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return h_(e)?(t.lastIntValue=e,t.advance(),!0):!1};function h_(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}W.regexp_eatClassControlLetter=function(t){var e=t.current();return ki(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};W.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};W.regexp_eatDecimalDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;ki(n=t.current());)t.lastIntValue=10*t.lastIntValue+(n-48),t.advance();return t.pos!==e};function ki(t){return t>=48&&t<=57}W.regexp_eatHexDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;Gl(n=t.current());)t.lastIntValue=16*t.lastIntValue+Xl(n),t.advance();return t.pos!==e};function Gl(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function Xl(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}W.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var n=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+n*8+t.lastIntValue:t.lastIntValue=e*8+n}else t.lastIntValue=e;return!0}return!1};W.regexp_eatOctalDigit=function(t){var e=t.current();return Zl(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function Zl(t){return t>=48&&t<=55}W.regexp_eatFixedHexDigits=function(t,e){var n=t.pos;t.lastIntValue=0;for(var r=0;r<e;++r){var i=t.current();if(!Gl(i))return t.pos=n,!1;t.lastIntValue=16*t.lastIntValue+Xl(i),t.advance()}return!0};var da=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Si(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},ee=Re.prototype;ee.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 da(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};ee.getToken=function(){return this.next(),new da(this)};typeof Symbol<"u"&&(ee[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===g.eof,value:e}}}});ee.nextToken=function(){var t=this.curContext();if((!t||!t.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(g.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};ee.readToken=function(t){return Wt(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};ee.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var n=this.input.charCodeAt(t+1);return n<=56319||n>=57344?e:(e<<10)+n-56613888};ee.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};ee.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,n=this.input.indexOf("*/",this.pos+=2);if(n===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=n+2,this.options.locations)for(var r=void 0,i=e;(r=bl(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,n),e,this.pos,t,this.curPosition())};ee.skipLineComment=function(t){for(var e=this.pos,n=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!jn(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,n,this.curPosition())};ee.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&&vl.test(String.fromCharCode(t)))++this.pos;else break e}}};ee.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var n=this.type;this.type=t,this.value=e,this.updateContext(n)};ee.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1);if(t>=48&&t<=57)return this.readNumber(!0);var e=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&t===46&&e===46?(this.pos+=3,this.finishToken(g.ellipsis)):(++this.pos,this.finishToken(g.dot))};ee.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(g.assign,2):this.finishOp(g.slash,1)};ee.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),n=1,r=t===42?g.star:g.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++n,r=g.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(g.assign,n+1):this.finishOp(r,n)};ee.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var n=this.input.charCodeAt(this.pos+2);if(n===61)return this.finishOp(g.assign,3)}return this.finishOp(t===124?g.logicalOR:g.logicalAND,2)}return e===61?this.finishOp(g.assign,2):this.finishOp(t===124?g.bitwiseOR:g.bitwiseAND,1)};ee.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(g.assign,2):this.finishOp(g.bitwiseXOR,1)};ee.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||Je.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(g.incDec,2):e===61?this.finishOp(g.assign,2):this.finishOp(g.plusMin,1)};ee.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),n=1;return e===t?(n=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+n)===61?this.finishOp(g.assign,n+1):this.finishOp(g.bitShift,n)):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&&(n=2),this.finishOp(g.relational,n))};ee.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(g.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(g.arrow)):this.finishOp(t===61?g.eq:g.prefix,1)};ee.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var n=this.input.charCodeAt(this.pos+2);if(n<48||n>57)return this.finishOp(g.questionDot,2)}if(e===63){if(t>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(g.assign,3)}return this.finishOp(g.coalesce,2)}}return this.finishOp(g.question,1)};ee.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),Wt(e,!0)||e===92))return this.finishToken(g.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+Yt(e)+"\'")};ee.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(g.parenL);case 41:return++this.pos,this.finishToken(g.parenR);case 59:return++this.pos,this.finishToken(g.semi);case 44:return++this.pos,this.finishToken(g.comma);case 91:return++this.pos,this.finishToken(g.bracketL);case 93:return++this.pos,this.finishToken(g.bracketR);case 123:return++this.pos,this.finishToken(g.braceL);case 125:return++this.pos,this.finishToken(g.braceR);case 58:return++this.pos,this.finishToken(g.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(g.backQuote);case 48:var e=this.input.charCodeAt(this.pos+1);if(e===120||e===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(e===111||e===79)return this.readRadixNumber(8);if(e===98||e===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(t);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(t);case 124:case 38:return this.readToken_pipe_amp(t);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(t);case 60:case 62:return this.readToken_lt_gt(t);case 61:case 33:return this.readToken_eq_excl(t);case 63:return this.readToken_question();case 126:return this.finishOp(g.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character \'"+Yt(t)+"\'")};ee.finishOp=function(t,e){var n=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,n)};ee.readRegexp=function(){for(var t,e,n=this.pos;;){this.pos>=this.input.length&&this.raise(n,"Unterminated regular expression");var r=this.input.charAt(this.pos);if(Je.test(r)&&this.raise(n,"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 i=this.input.slice(n,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new $t(this));o.reset(n,i,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(i,a)}catch{}return this.finishToken(g.regexp,{pattern:i,flags:a,value:l})};ee.readInt=function(t,e,n){for(var r=this.options.ecmaVersion>=12&&e===void 0,i=n&&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){i&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed in legacy octal numeric literals"),o===95&&this.raiseRecoverable(this.pos,"Numeric separator must be exactly one underscore"),l===0&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed at the first of digits"),o=u;continue}if(u>=97?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 p_(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function Ql(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}ee.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var n=this.readInt(t);return n==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(n=Ql(this.input.slice(e,this.pos)),++this.pos):Wt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,n)};ee.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var n=this.pos-e>=2&&this.input.charCodeAt(e)===48;n&&this.strict&&this.raise(e,"Invalid number");var r=this.input.charCodeAt(this.pos);if(!n&&!t&&this.options.ecmaVersion>=11&&r===110){var i=Ql(this.input.slice(e,this.pos));return++this.pos,Wt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.num,i)}n&&/[89]/.test(this.input.slice(e,this.pos))&&(n=!1),r===46&&!n&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!n&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),Wt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=p_(this.input.slice(e,this.pos),n);return this.finishToken(g.num,s)};ee.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var n=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(n,"Code point out of bounds")}else e=this.readHexChar(4);return e};ee.readString=function(t){for(var e="",n=++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(n,this.pos),e+=this.readEscapedChar(!1),n=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)):(jn(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(n,this.pos++),this.finishToken(g.string,e)};var Jl={};ee.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===Jl)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};ee.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw Jl;this.raise(t,e)};ee.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var n=this.input.charCodeAt(this.pos);if(n===96||n===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===g.template||this.type===g.invalidTemplate)?n===36?(this.pos+=2,this.finishToken(g.dollarBraceL)):(++this.pos,this.finishToken(g.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(g.template,t));if(n===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(jn(n)){switch(t+=this.input.slice(e,this.pos),++this.pos,n){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`\n`;break;default:t+=String.fromCharCode(n);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};ee.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\\\":++this.pos;break;case"$":if(this.input[this.pos+1]!=="{")break;case"`":return this.finishToken(g.invalidTemplate,this.input.slice(this.start,this.pos));case"\\r":this.input[this.pos+1]===`\n`&&++this.pos;case`\n`:case"\\u2028":case"\\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};ee.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`\n`;case 114:return"\\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return Yt(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 n=this.pos-1;this.invalidStringToken(n,"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],i=parseInt(r,8);return i>255&&(r=r.slice(0,-1),i=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(i)}return jn(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};ee.readHexChar=function(t){var e=this.pos,n=this.readInt(16,t);return n===null&&this.invalidStringToken(e,"Bad character escape sequence"),n};ee.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,n=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(sn(i,r))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,t+=this.input.slice(n,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?Wt:sn)(a,r)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=Yt(a),n=this.pos}else break;e=!1}return t+this.input.slice(n,this.pos)};ee.readWord=function(){var t=this.readWord1(),e=g.name;return this.keywords.test(t)&&(e=oa[t]),this.finishToken(e,t)};var d_="8.16.0";Re.acorn={Parser:Re,version:d_,defaultOptions:As,Position:mr,SourceLocation:Si,getLineInfo:Sl,Node:Ni,TokenType:ie,tokTypes:g,keywordTypes:oa,TokContext:bt,tokContexts:be,isIdentifierChar:sn,isIdentifierStart:Wt,Token:da,isNewLine:jn,lineBreak:Je,lineBreakG:Lx,nonASCIIwhitespace:vl};function fa(t,e){return Re.parse(t,e)}var{stringify:f_}=JSON;if(!String.prototype.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!String.prototype.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var Pr={"||":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},Ct=17,m_={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:Ct,ClassExpression:Ct,FunctionExpression:Ct,ObjectExpression:Ct,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function Rn(t,e){let{generator:n}=t;if(t.write("("),e!=null&&e.length>0){n[e[0].type](e[0],t);let{length:r}=e;for(let i=1;i<r;i++){let s=e[i];t.write(", "),n[s.type](s,t)}}t.write(")")}function ec(t,e,n,r){let i=t.expressionsPrecedence[e.type];if(i===Ct)return!0;let s=t.expressionsPrecedence[n.type];return i!==s?!r&&i===15&&s===14&&n.operator==="**"||i<s:i!==13&&i!==14?!1:e.operator==="**"&&n.operator==="**"?!r:i===13&&s===13&&(e.operator==="??"||n.operator==="??")?!0:r?Pr[e.operator]<=Pr[n.operator]:Pr[e.operator]<Pr[n.operator]}function Dr(t,e,n,r){let{generator:i}=t;ec(t,e,n,r)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function y_(t,e,n,r){let i=e.split(`\n`),s=i.length-1;if(t.write(i[0].trim()),s>0){t.write(r);for(let a=1;a<s;a++)t.write(n+i[a].trim()+r);t.write(n+i[s].trim())}}function ze(t,e,n,r){let{length:i}=e;for(let s=0;s<i;s++){let a=e[s];t.write(n),a.type[0]==="L"?t.write("// "+a.value.trim()+`\n`,a):(t.write("/*"),y_(t,a.value,n,r),t.write("*/"+r))}}function g_(t){let e=t;for(;e!=null;){let{type:n}=e;if(n[0]==="C"&&n[1]==="a")return!0;if(n[0]==="M"&&n[1]==="e"&&n[2]==="m")e=e.object;else return!1}}function Ji(t,e){let{generator:n}=t,{declarations:r}=e;t.write(e.kind+" ");let{length:i}=r;if(i>0){n.VariableDeclarator(r[0],t);for(let s=1;s<i;s++)t.write(", "),n.VariableDeclarator(r[s],t)}}var xo,_o,bo,vo,wo,So,ma={Program(t,e){let n=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:i}=e;i&&t.comments!=null&&ze(e,t.comments,n,r);let s=t.body,{length:a}=s;for(let o=0;o<a;o++){let l=s[o];i&&l.comments!=null&&ze(e,l.comments,n,r),e.write(n),this[l.type](l,e),e.write(r)}i&&t.trailingComments!=null&&ze(e,t.trailingComments,n,r)},BlockStatement:So=function(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e,s=n+e.indent;e.write("{");let a=t.body;if(a!=null&&a.length>0){e.write(r),i&&t.comments!=null&&ze(e,t.comments,s,r);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&ze(e,c.comments,s,r),e.write(s),this[c.type](c,e),e.write(r)}e.write(n)}else i&&t.comments!=null&&(e.write(r),ze(e,t.comments,s,r),e.write(n));i&&t.trailingComments!=null&&ze(e,t.trailingComments,s,r),e.write("}"),e.indentLevel--},ClassBody:So,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){let n=e.expressionsPrecedence[t.expression.type];n===Ct||n===3&&t.expression.left.type[0]==="O"?(e.write("("),this[t.expression.type](t.expression,e),e.write(")")):this[t.expression.type](t.expression,e),e.write(";")},IfStatement(t,e){e.write("if ("),this[t.test.type](t.test,e),e.write(") "),this[t.consequent.type](t.consequent,e),t.alternate!=null&&(e.write(" else "),this[t.alternate.type](t.alternate,e))},LabeledStatement(t,e){this[t.label.type](t.label,e),e.write(": "),this[t.body.type](t.body,e)},BreakStatement(t,e){e.write("break"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},ContinueStatement(t,e){e.write("continue"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},WithStatement(t,e){e.write("with ("),this[t.object.type](t.object,e),e.write(") "),this[t.body.type](t.body,e)},SwitchStatement(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e;e.indentLevel++;let s=n+e.indent,a=s+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+r);let{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){let u=o[c];i&&u.comments!=null&&ze(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);let{consequent:p}=u,{length:h}=p;for(let d=0;d<h;d++){let f=p[d];i&&f.comments!=null&&ze(e,f.comments,a,r),e.write(a),this[f.type](f,e),e.write(r)}}e.indentLevel-=2,e.write(n+"}")},ReturnStatement(t,e){e.write("return"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e)),e.write(";")},ThrowStatement(t,e){e.write("throw "),this[t.argument.type](t.argument,e),e.write(";")},TryStatement(t,e){if(e.write("try "),this[t.block.type](t.block,e),t.handler){let{handler:n}=t;n.param==null?e.write(" catch "):(e.write(" catch ("),this[n.param.type](n.param,e),e.write(") ")),this[n.body.type](n.body,e)}t.finalizer&&(e.write(" finally "),this[t.finalizer.type](t.finalizer,e))},WhileStatement(t,e){e.write("while ("),this[t.test.type](t.test,e),e.write(") "),this[t.body.type](t.body,e)},DoWhileStatement(t,e){e.write("do "),this[t.body.type](t.body,e),e.write(" while ("),this[t.test.type](t.test,e),e.write(");")},ForStatement(t,e){if(e.write("for ("),t.init!=null){let{init:n}=t;n.type[0]==="V"?Ji(e,n):this[n.type](n,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:xo=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:n}=t;n.type[0]==="V"?Ji(e,n):this[n.type](n,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:xo,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:_o=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),Rn(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:_o,VariableDeclaration(t,e){Ji(e,t),e.write(";")},VariableDeclarator(t,e){this[t.id.type](t.id,e),t.init!=null&&(e.write(" = "),this[t.init.type](t.init,e))},ClassDeclaration(t,e){if(e.write("class "+(t.id?`${t.id.name} `:""),t),t.superClass){e.write("extends ");let{superClass:n}=t,{type:r}=n,i=e.expressionsPrecedence[r];(r[0]!=="C"||r[1]!=="l"||r[5]!=="E")&&(i===Ct||i<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](n,e),e.write(")")):this[n.type](n,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");let{specifiers:n,attributes:r}=t,{length:i}=n,s=0;if(i>0){for(;s<i;){s>0&&e.write(", ");let a=n[s],o=a.type[6];if(o==="D")e.write(a.local.name,a),s++;else if(o==="N")e.write("* as "+a.local.name,a),s++;else break}if(s<i){for(e.write("{");;){let a=n[s],{name:o}=a.imported;if(e.write(o,a),o!==a.local.name&&e.write(" as "+a.local.name),++s<i)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),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("{");let{specifiers:n}=t,{length:r}=n;if(r>0)for(let i=0;;){let s=n[i],{name:a}=s.local;if(e.write(a,s),a!==s.exported.name&&e.write(" as "+s.exported.name),++i<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 i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")}},ExportAllDeclaration(t,e){if(t.exported!=null?e.write("export * as "+t.exported.name+" from "):e.write("export * from "),this.Literal(t.source,e),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let n=0;n<t.attributes.length;n++)this.ImportAttribute(t.attributes[n],e),n<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");let n=t.kind[0];(n==="g"||n==="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),Rn(e,t.value.params),e.write(" "),this[t.value.body.type](t.value.body,e)},ClassExpression(t,e){this.ClassDeclaration(t,e)},ArrowFunctionExpression(t,e){e.write(t.async?"async ":"",t);let{params:n}=t;n!=null&&(n.length===1&&n[0].type[0]==="I"?e.write(n[0].name,n[0]):Rn(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:bo=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:bo,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),Dr(e,t.argument,t)},TemplateLiteral(t,e){let{quasis:n,expressions:r}=t;e.write("`");let{length:i}=r;for(let a=0;a<i;a++){let o=r[a],l=n[a];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}let s=n[n.length-1];e.write(s.value.raw,s),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Dr(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:wo=function(t,e){if(e.write("["),t.elements.length>0){let{elements:n}=t,{length:r}=n;for(let i=0;;){let s=n[i];if(s!=null&&this[s.type](s,e),++i<r)e.write(", ");else{s==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:wo,ObjectExpression(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e,s=n+e.indent;if(e.write("{"),t.properties.length>0){e.write(r),i&&t.comments!=null&&ze(e,t.comments,s,r);let a=","+r,{properties:o}=t,{length:l}=o;for(let c=0;;){let u=o[c];if(i&&u.comments!=null&&ze(e,u.comments,s,r),e.write(s),this[u.type](u,e),++c<l)e.write(a);else break}e.write(r),i&&t.trailingComments!=null&&ze(e,t.trailingComments,s,r),e.write(n+"}")}else i?t.comments!=null?(e.write(r),ze(e,t.comments,s,r),t.trailingComments!=null&&ze(e,t.trailingComments,s,r),e.write(n+"}")):t.trailingComments!=null?(e.write(r),ze(e,t.trailingComments,s,r),e.write(n+"}")):e.write("}"):e.write("}");e.indentLevel--},Property(t,e){t.method||t.kind[0]!=="i"?this.MethodDefinition(t,e):(t.shorthand||(t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),e.write(": ")),this[t.value.type](t.value,e))},PropertyDefinition(t,e){if(t.static&&e.write("static "),t.computed&&e.write("["),this[t.key.type](t.key,e),t.computed&&e.write("]"),t.value==null){t.key.type[0]!=="F"&&e.write(";");return}e.write(" = "),this[t.value.type](t.value,e),e.write(";")},ObjectPattern(t,e){if(e.write("{"),t.properties.length>0){let{properties:n}=t,{length:r}=n;for(let i=0;this[n[i].type](n[i],e),++i<r;)e.write(", ")}e.write("}")},SequenceExpression(t,e){Rn(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:n,argument:r,argument:{type:i}}=t;e.write(n);let s=ec(e,r,t);!s&&(n.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&r.prefix&&r.operator[0]===n&&(n==="+"||n==="-"))&&e.write(" "),s?(e.write(n.length>1?" (":"("),this[i](r,e),e.write(")")):this[i](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:vo=function(t,e){let n=t.operator==="in";n&&e.write("("),Dr(e,t.left,t,!1),e.write(" "+t.operator+" "),Dr(e,t.right,t,!0),n&&e.write(")")},LogicalExpression:vo,ConditionalExpression(t,e){let{test:n}=t,r=e.expressionsPrecedence[n.type];r===Ct||r<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[n.type](n,e),e.write(")")):this[n.type](n,e),e.write(" ? "),this[t.consequent.type](t.consequent,e),e.write(" : "),this[t.alternate.type](t.alternate,e)},NewExpression(t,e){e.write("new ");let n=e.expressionsPrecedence[t.callee.type];n===Ct||n<e.expressionsPrecedence.CallExpression||g_(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),Rn(e,t.arguments)},CallExpression(t,e){let n=e.expressionsPrecedence[t.callee.type];n===Ct||n<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("?."),Rn(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let n=e.expressionsPrecedence[t.object.type];n===Ct||n<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(f_(t.value),t)},RegExpLiteral(t,e){let{regex:n}=t;e.write(`/${n.pattern}/${n.flags}`,t)}},x_={},__=ma,Ps=class{constructor(e){let n=e??x_;this.output="",n.output!=null?(this.output=n.output,this.write=this.writeToStream):this.output="",this.generator=n.generator!=null?n.generator:ma,this.expressionsPrecedence=n.expressionsPrecedence!=null?n.expressionsPrecedence:m_,this.indent=n.indent!=null?n.indent:" ",this.lineEnd=n.lineEnd!=null?n.lineEnd:`\n`,this.indentLevel=n.startingIndentLevel!=null?n.startingIndentLevel:0,this.writeComments=n.comments?n.comments:!1,n.sourceMap!=null&&(this.write=n.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=n.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`\n`).length-1,this.mapping={original:null,generated:this,name:void 0,source:n.sourceMap.file||n.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,n){this.output+=e,this.map(e,n)}writeToStreamAndMap(e,n){this.output.write(e),this.map(e,n)}map(e,n){if(n!=null){let{type:s}=n;if(s[0]==="L"&&s[2]==="n"){this.column=0,this.line++;return}if(n.loc!=null){let{mapping:a}=this;a.original=n.loc.start,a.name=n.name,this.sourceMap.addMapping(a)}if(s[0]==="T"&&s[8]==="E"||s[0]==="L"&&s[1]==="i"&&typeof n.value=="string"){let{length:a}=e,{column:o,line:l}=this;for(let c=0;c<a;c++)e[c]===`\n`?(o=0,l++):o++;this.column=o,this.line=l;return}}let{length:r}=e,{lineEnd:i}=this;r>0&&(this.lineEndSize>0&&(i.length===1?e[r-1]===i:e.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}};function ya(t,e){let n=new Ps(e);return n.generator[t.type](t,n),n.output}var b_=Object.defineProperty,v_=(t,e,n)=>e in t?b_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ce=(t,e,n)=>v_(t,typeof e!="symbol"?e+"":e,n),w_=new Set(["Infinity","NaN","undefined","null","true","false"]),S_=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"]),Ds=class{constructor(){ce(this,"scopes",[]),ce(this,"scopeTypes",[]),ce(this,"scopeCounts",new Map),ce(this,"contextBoundVars",new Set),ce(this,"arrayPatternElements",new Set),ce(this,"rootParams",new Set),ce(this,"localSeriesVars",new Set),ce(this,"varKinds",new Map),ce(this,"loopVars",new Set),ce(this,"loopVarNames",new Map),ce(this,"paramIdCounter",0),ce(this,"cacheIdCounter",0),ce(this,"tempVarCounter",0),ce(this,"taCallIdCounter",0),ce(this,"userCallIdCounter",0),ce(this,"plotCallIdCounter",0),ce(this,"alertCallIdCounter",0),ce(this,"loopGuardCounter",0),ce(this,"hoistingStack",[]),ce(this,"suppressHoisting",!1),ce(this,"reservedNames",new Set),ce(this,"userFunctions",new Set),ce(this,"userMethods",new Set),ce(this,"regularUserFunctions",new Set),ce(this,"udtTypeNames",new Map),ce(this,"udtInstances",new Map),ce(this,"functionReturnTypes",new Map),ce(this,"functionReturnTupleTypes",new Map),ce(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,n={}){this.udtTypeNames.set(e,n)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,n){this.udtInstances.set(e,n)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,n){let r=this.functionReturnTypes.get(e);if(r&&r!==n){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,n)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,n){let r=this.functionReturnTupleTypes.get(e);if(r&&(r.length!==n.length||r.some((i,s)=>i!==n[s]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,n)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,n){this.functionParamUdtTypes.set(e,n)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}addContextBoundVar(e,n=!1){this.contextBoundVars.add(e),n&&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 w_.has(e)||S_.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,n){this.loopVars.add(e),this.loopVarNames.set(e,n)}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,n){if(this.isContextBound(e))return e;let r=this.scopes[this.scopes.length-1],i=this.scopeTypes[this.scopeTypes.length-1],s=this.scopeCounts.get(i)||1,a=`${i}${s}_${e}`;return r.set(e,a),this.varKinds.set(a,n),a}getVariable(e){if(this.loopVars.has(e)){let n=this.loopVarNames.get(e);if(n)return[n,"let"]}if(this.isContextBound(e))return[e,"let"];for(let n=this.scopes.length-1;n>=0;n--){let r=this.scopes[n];if(r.has(e)){let i=r.get(e),s=this.varKinds.get(i)||"let";return[i,s]}}return[e,"let"]}isVariableInFunctionScope(e){for(let n=this.scopes.length-1;n>=0;n--)if(this.scopes[n].has(e)){for(let r=0;r<=n;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){let n=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[n].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 n=this.scopes.length-1;n>=0;n--)if(this.scopes[n].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;let n=this.scopes[this.scopes.length-1];return n&&n.set(e,e),e}};function It(t,e,n,r,i){n||(n=P),(function s(a,o,l){var c=l||a.type;nc(n,c,a,o,s),e[c]&&e[c](a,o)})(t,r,i)}function tc(t,e,n,r,i){var s=[];n||(n=P),(function a(o,l,c){var u=c||o.type,p=o!==s[s.length-1];p&&s.push(o),nc(n,u,o,l,a),e[u]&&e[u](o,l||s,s),p&&s.pop()})(t,r,i)}function Pe(t,e,n,r,i){var s=n?E_(n,r||void 0):r;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function E_(t,e){var n=Object.create(e||P);for(var r in t)n[r]=t[r];return n}function ga(t,e,n){n(t,e)}function _n(t,e,n){}function nc(t,e,n,r,i){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](n,r,i)}var P={};P.Program=P.BlockStatement=P.StaticBlock=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e,"Statement")}};P.Statement=ga;P.EmptyStatement=_n;P.ExpressionStatement=P.ParenthesizedExpression=P.ChainExpression=function(t,e,n){return n(t.expression,e,"Expression")};P.IfStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Statement"),t.alternate&&n(t.alternate,e,"Statement")};P.LabeledStatement=function(t,e,n){return n(t.body,e,"Statement")};P.BreakStatement=P.ContinueStatement=_n;P.WithStatement=function(t,e,n){n(t.object,e,"Expression"),n(t.body,e,"Statement")};P.SwitchStatement=function(t,e,n){n(t.discriminant,e,"Expression");for(var r=0,i=t.cases;r<i.length;r+=1){var s=i[r];n(s,e)}};P.SwitchCase=function(t,e,n){t.test&&n(t.test,e,"Expression");for(var r=0,i=t.consequent;r<i.length;r+=1){var s=i[r];n(s,e,"Statement")}};P.ReturnStatement=P.YieldExpression=P.AwaitExpression=function(t,e,n){t.argument&&n(t.argument,e,"Expression")};P.ThrowStatement=P.SpreadElement=function(t,e,n){return n(t.argument,e,"Expression")};P.TryStatement=function(t,e,n){n(t.block,e,"Statement"),t.handler&&n(t.handler,e),t.finalizer&&n(t.finalizer,e,"Statement")};P.CatchClause=function(t,e,n){t.param&&n(t.param,e,"Pattern"),n(t.body,e,"Statement")};P.WhileStatement=P.DoWhileStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.body,e,"Statement")};P.ForStatement=function(t,e,n){t.init&&n(t.init,e,"ForInit"),t.test&&n(t.test,e,"Expression"),t.update&&n(t.update,e,"Expression"),n(t.body,e,"Statement")};P.ForInStatement=P.ForOfStatement=function(t,e,n){n(t.left,e,"ForInit"),n(t.right,e,"Expression"),n(t.body,e,"Statement")};P.ForInit=function(t,e,n){t.type==="VariableDeclaration"?n(t,e):n(t,e,"Expression")};P.DebuggerStatement=_n;P.FunctionDeclaration=function(t,e,n){return n(t,e,"Function")};P.VariableDeclaration=function(t,e,n){for(var r=0,i=t.declarations;r<i.length;r+=1){var s=i[r];n(s,e)}};P.VariableDeclarator=function(t,e,n){n(t.id,e,"Pattern"),t.init&&n(t.init,e,"Expression")};P.Function=function(t,e,n){t.id&&n(t.id,e,"Pattern");for(var r=0,i=t.params;r<i.length;r+=1){var s=i[r];n(s,e,"Pattern")}n(t.body,e,t.expression?"Expression":"Statement")};P.Pattern=function(t,e,n){t.type==="Identifier"?n(t,e,"VariablePattern"):t.type==="MemberExpression"?n(t,e,"MemberPattern"):n(t,e)};P.VariablePattern=_n;P.MemberPattern=ga;P.RestElement=function(t,e,n){return n(t.argument,e,"Pattern")};P.ArrayPattern=function(t,e,n){for(var r=0,i=t.elements;r<i.length;r+=1){var s=i[r];s&&n(s,e,"Pattern")}};P.ObjectPattern=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];s.type==="Property"?(s.computed&&n(s.key,e,"Expression"),n(s.value,e,"Pattern")):s.type==="RestElement"&&n(s.argument,e,"Pattern")}};P.Expression=ga;P.ThisExpression=P.Super=P.MetaProperty=_n;P.ArrayExpression=function(t,e,n){for(var r=0,i=t.elements;r<i.length;r+=1){var s=i[r];s&&n(s,e,"Expression")}};P.ObjectExpression=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];n(s,e)}};P.FunctionExpression=P.ArrowFunctionExpression=P.FunctionDeclaration;P.SequenceExpression=function(t,e,n){for(var r=0,i=t.expressions;r<i.length;r+=1){var s=i[r];n(s,e,"Expression")}};P.TemplateLiteral=function(t,e,n){for(var r=0,i=t.quasis;r<i.length;r+=1){var s=i[r];n(s,e)}for(var a=0,o=t.expressions;a<o.length;a+=1){var l=o[a];n(l,e,"Expression")}};P.TemplateElement=_n;P.UnaryExpression=P.UpdateExpression=function(t,e,n){n(t.argument,e,"Expression")};P.BinaryExpression=P.LogicalExpression=function(t,e,n){n(t.left,e,"Expression"),n(t.right,e,"Expression")};P.AssignmentExpression=P.AssignmentPattern=function(t,e,n){n(t.left,e,"Pattern"),n(t.right,e,"Expression")};P.ConditionalExpression=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Expression"),n(t.alternate,e,"Expression")};P.NewExpression=P.CallExpression=function(t,e,n){if(n(t.callee,e,"Expression"),t.arguments)for(var r=0,i=t.arguments;r<i.length;r+=1){var s=i[r];n(s,e,"Expression")}};P.MemberExpression=function(t,e,n){n(t.object,e,"Expression"),t.computed&&n(t.property,e,"Expression")};P.ExportNamedDeclaration=P.ExportDefaultDeclaration=function(t,e,n){if(t.declaration&&n(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&n(t.source,e,"Expression"),t.attributes)for(var r=0,i=t.attributes;r<i.length;r+=1){var s=i[r];n(s,e)}};P.ExportAllDeclaration=function(t,e,n){if(t.exported&&n(t.exported,e),n(t.source,e,"Expression"),t.attributes)for(var r=0,i=t.attributes;r<i.length;r+=1){var s=i[r];n(s,e)}};P.ImportAttribute=function(t,e,n){n(t.value,e,"Expression")};P.ImportDeclaration=function(t,e,n){for(var r=0,i=t.specifiers;r<i.length;r+=1){var s=i[r];n(s,e)}if(n(t.source,e,"Expression"),t.attributes)for(var a=0,o=t.attributes;a<o.length;a+=1){var l=o[a];n(l,e)}};P.ImportExpression=function(t,e,n){n(t.source,e,"Expression"),t.options&&n(t.options,e,"Expression")};P.ImportSpecifier=P.ImportDefaultSpecifier=P.ImportNamespaceSpecifier=P.Identifier=P.PrivateIdentifier=P.Literal=_n;P.TaggedTemplateExpression=function(t,e,n){n(t.tag,e,"Expression"),n(t.quasi,e,"Expression")};P.ClassDeclaration=P.ClassExpression=function(t,e,n){return n(t,e,"Class")};P.Class=function(t,e,n){t.id&&n(t.id,e,"Pattern"),t.superClass&&n(t.superClass,e,"Expression"),n(t.body,e)};P.ClassBody=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e)}};P.MethodDefinition=P.PropertyDefinition=P.Property=function(t,e,n){t.computed&&n(t.key,e,"Expression"),t.value&&n(t.value,e,"Expression")};var we="$",C={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,n=!1){return{type:"MemberExpression",object:t,property:e,computed:n}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){let n=this.createContextIdentifier(),r=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(n,r,!1),i,!1)},createLocalContextVariableReference(t,e){let n=this.createLocalContextIdentifier(),r=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(n,r,!1),i,!1)},createDynamicContextVariableReference(t,e){let n=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(n,r,!1),e,!0)},createContextVariableAccess0(t,e){let n=this.createContextVariableReference(t,e);return this.createGetCall(n,0)},createDynamicContextVariableAccess0(t,e){let n=this.createDynamicContextVariableReference(t,e);return this.createGetCall(n,0)},createArrayAccess(t,e){let n=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,n,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,n="="){return{type:"AssignmentExpression",operator:n,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,n){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),i=[t,e];return n&&i.push(n),this.createCallExpression(r,i)},createInitVarCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(n,r)},createGetCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(n,[t,r])},createSetCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(n,[t,e])},createMathEqCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(i,[t,e])},createMathNeqCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(i,[t,e])},createMathCompareCall(t,e,n){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),i=this.createMemberExpression(r,this.createIdentifier("math"),!1),s=this.createMemberExpression(i,this.createIdentifier(t),!1);return this.createCallExpression(s,[e,n])},createMathIntDivCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__idiv"),!1);return this.createCallExpression(i,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},an=["ta","math","request","array","input","color","ticker","strategy"],Nt=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],C_=["request.security","request.security_lower_tf"],I_=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Eo=["plot","hline","fill","strategy.exit"],N_=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],k_=new Set([...an,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","session","timeframe","strategy","log","str","position","font","order","currency","dayofweek","adjustment","barmerge"]),Co=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"]),rc=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],xa=[...an,"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","runtime","Type","bool","int","float","string","timeframe","syminfo","barstate","session","bar_index","last_bar_index","last_bar_time","timenow","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"],A_=["na","nz","plot","plotchar","color","hline","fill"];function M_(t){let e=null,n=we;if(t.type==="Program"&&t.body.length>0){let d=t.body[0];if(d.type==="ExpressionStatement"&&(d.expression.type==="ArrowFunctionExpression"||d.expression.type==="FunctionExpression")){let f=d.expression;f.body.type==="BlockStatement"&&(e=f.body.body,f.params.length>0&&f.params[0].type==="Identifier"&&(n=f.params[0].name))}}if(!e)return;let r=new Set,i=new Set,s=d=>{d.type==="Identifier"?r.add(d.name):d.type==="ObjectPattern"?d.properties.forEach(f=>s(f.value)):d.type==="ArrayPattern"&&d.elements.forEach(f=>{f&&s(f)})};Pe(t,{},{VariableDeclarator(d,f,m){s(d.id),d.init&&m(d.init,f)},FunctionDeclaration(d,f,m){s(d.id);for(let _ of d.params)_&&_.type==="AssignmentPattern"&&_.right&&m(_.right,f);m(d.body,f)},Identifier(d,f,m){i.add(d.name)},MemberExpression(d,f,m){m(d.object,f),d.computed&&m(d.property,f)},Property(d,f,m){d.computed&&m(d.key,f),m(d.value,f)}}),e.forEach(d=>{d.type==="VariableDeclaration"?d.declarations.forEach(f=>s(f.id)):d.type==="FunctionDeclaration"&&s(d.id)});let a=rc,o=xa,l=a.filter(d=>!r.has(d)),c=o.filter(d=>!r.has(d)),u=l.filter(d=>i.has(d)),p=c.filter(d=>i.has(d)),h=[];u.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},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(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"pine"},computed:!1}}]}),h.length>0&&e.unshift(...h)}function T_(t){let e=null,n=we;if(t.type==="Program"&&t.body.length>0){let o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){let l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(n=l.params[0].name))}}if(!e)return;let r=new Set(rc),i=new Set(xa),s=new Set(A_),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===n&&l.init.property.type==="Identifier"){let c=l.init.property.name,u=null;if(c==="data"?u=r:c==="pine"?u=i: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"){let h=p.key.name,d=p.value.name;u.has(h)&&h!==d&&(a.set(d,h),p.value.name=h,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&an.includes(c)){let p=c,h=l.id.name;p!==h&&(a.set(h,p),l.id.name=p)}}})}),a.size>0&&Pe(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 P_(t){try{let e=fa(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){let n=e.body[0];if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(n.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:n.async||!1,functionNode:n}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function D_(t){return t.async=!0,ya(t)}function R_(t){t=t.trim();let{isWrapped:e,isAsync:n,functionNode:r}=P_(t);return e&&r?n?t:D_(r):`async (context) => {\n${t}\n}`}function O_(t){Pe(t,null,{VariableDeclaration(e,n,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(i=>{if(i.init&&i.init.type==="ArrowFunctionExpression"&&i.init.start!==0){let s={type:"FunctionDeclaration",id:i.id,params:i.init.params,body:i.init.body.type==="BlockStatement"?i.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:i.init.body}]},async:i.init.async,generator:!1};Object.assign(e,s)}}),e.body&&e.body.body&&e.body.body.forEach(i=>r(i,n))}})}function L_(t,e){It(t,{VariableDeclaration(r){for(let i of r.declarations)if(!(i.id?.type!=="Identifier"||!i.init)&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"&&i.init.callee.name==="Type"&&i.init.arguments?.length===1&&i.init.arguments[0]?.type==="ObjectExpression"){let s={};for(let a of i.init.arguments[0].properties)a.type!=="Property"||a.key?.type!=="Identifier"||(a.value?.type==="ArrayExpression"&&a.value.elements?.[0]?.type==="Literal"?s[a.key.name]=String(a.value.elements[0].value):a.value?.type==="Literal"&&(s[a.key.name]=String(a.value.value)));e.addUdtTypeName(i.id.name,s)}}});let n=!0;for(;n;)n=!1,It(t,{FunctionDeclaration(r){if(!r.id?.name)return;let i=r.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=F_(r.body);if(s.length===0)return;if(s.every(l=>l.type==="ArrayExpression")){let l=s[0].elements.length;if(l>0&&s.every(c=>c.elements.length===l)){let c=[],u=!0;for(let p=0;p<l;p++){let h=s.map(f=>lr(f.elements[p],e)),d=h[0];if(!h.every(f=>f===d)){u=!1;break}c.push(d)}if(u&&c.some(p=>!!p)){e.setFunctionReturnTupleType(i,c),n=!0;return}}}let a=s.map(l=>lr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),n=!0)}});It(t,{VariableDeclaration(r){for(let i of r.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=lr(i.init,e);s&&e.markVariableAsUdtInstance(i.id.name,s);continue}if(i.id?.type==="ArrayPattern"&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"){let s=e.getFunctionReturnTupleType(i.init.callee.name);if(!s)continue;i.id.elements?.forEach((a,o)=>{if(!a||a.type!=="Identifier")return;let l=s[o];l&&e.markVariableAsUdtInstance(a.name,l)})}}},ExpressionStatement(r){let i=r.expression;if(i?.type==="Literal"&&typeof i.value=="string"&&i.value.startsWith("__pineUdtVar:")){let s=i.value.match(/^__pineUdtVar:([A-Za-z_$][\\w$]*)=([A-Za-z_$][\\w$]*)$/);if(s){let[,a,o]=s;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(a,o)}}}}),It(t,{ExpressionStatement(r){let i=r.expression;if(!i||i.type!=="AssignmentExpression"||i.operator!=="=")return;let s=i.left;if(s?.type!=="MemberExpression"||s.computed||s.property?.type!=="Identifier"||s.property.name!=="__pineParamTypes__"||s.object?.type!=="Identifier"||i.right?.type!=="ObjectExpression")return;let a=s.object.name,o=a.startsWith("$M_")?a.slice(3):a,l={};for(let c of i.right.properties){if(c.type!=="Property")continue;let u;if(c.key?.type==="Identifier"?u=c.key.name:c.key?.type==="Literal"&&typeof c.key.value=="string"&&(u=c.key.value),!u||c.value?.type!=="Literal"||typeof c.value.value!="string")continue;let p=c.value.value.split(/\\s+/).pop();e.isUdtTypeName(p)&&(l[u]=p)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l)}})}function F_(t){let e=[];if(!t)return e;function n(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(let i of Object.keys(r)){if(i==="type")continue;let s=r[i];Array.isArray(s)?s.forEach(n):s&&typeof s=="object"&&s.type&&n(s)}}}return n(t),e}function lr(t,e){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&(t.callee.property.name==="new"||t.callee.property.name==="copy")&&e.isUdtTypeName(t.callee.object.name))return t.callee.object.name;if(t.type==="CallExpression"&&t.callee?.type==="Identifier"){let n=e.getFunctionReturnType(t.callee.name);if(n)return n}if(t.type==="ConditionalExpression"){let n=lr(t.consequent,e),r=lr(t.alternate,e);if(n&&n===r)return n}}}function B_(t,e){It(t,{VariableDeclaration(n){n.declarations.forEach(r=>{let i=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===we||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===we||r.init.object.object.name==="context2");(i||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 V_(t,e,n=!1){t.params.forEach(r=>{r.type==="Identifier"&&n&&e.addContextBoundVar(r.name,n)})}function W_(t,e){let n;return tc(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){let i=r.expression;if(i&&i.type==="AssignmentExpression"&&i.operator==="="&&i.left?.type==="MemberExpression"&&i.left.property?.name==="__pineMethod__"&&i.left.object?.type==="Identifier"&&i.right?.value===!0){let s=i.left.object.name,a=s.startsWith("$M_")?s.slice(3):s;e.addUserMethod(a),e.addUserFunction(a)}},ArrowFunctionExpression(r){let i=r.start===0;i&&r.params&&r.params.length>0&&(n=r.params[0].name,r.params[0].name=we),V_(r,e,i)},VariableDeclaration(r,i){let s=i.length>1?i[i.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;let 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")&&It(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)});let p=o.id.elements.map((h,d)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:d},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...p]})}})},ForStatement(r){}}),n}var $_=Object.defineProperty,j_=(t,e,n)=>e in t?$_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,U_=(t,e,n)=>j_(t,typeof e!="symbol"?e+"":e,n),z_=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),q_=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function H_(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function K_(t){return t?t.type==="Identifier"?t.name:t.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.property?.type==="Identifier"?`${t.object.name}.${t.property.name}`:null:null}function Y_(t){let e=new Set;return(function n(r){if(!(!r||typeof r!="object")){r.type==="AssignmentExpression"&&r.left?.type==="Identifier"?e.add(r.left.name):r.type==="UpdateExpression"&&r.argument?.type==="Identifier"&&e.add(r.argument.name);for(let i in r){if(i==="type"||i==="start"||i==="end"||i==="loc"||i==="raw")continue;let s=r[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&n(a);else s&&typeof s=="object"&&n(s)}}})(t),e}function Rs(t,e){return t!=="notint"&&e!=="notint"?"int":"notint"}var Os=class{constructor(){U_(this,"stack",[new Map])}push(){this.stack.push(new Map)}pop(){this.stack.length>1&&this.stack.pop()}set(e,n){this.stack[this.stack.length-1].set(e,n)}get(e){for(let n=this.stack.length-1;n>=0;n--){let r=this.stack[n].get(e);if(r!==void 0)return r}}assign(e,n){for(let r=this.stack.length-1;r>=0;r--)if(this.stack[r].has(e)){this.stack[r].set(e,Rs(this.stack[r].get(e),n));return}this.stack[this.stack.length-1].set(e,Rs(n,n))}};function G_(t,e){let n=new Os,r=Y_(t);function i(a){if(!a||typeof a!="object")return"notint";switch(a.type){case"Literal":return typeof a.value=="number"&&H_(a)?"constint":"notint";case"Identifier":return z_.has(a.name)?"int":n.get(a.name)??"notint";case"UnaryExpression":return a.operator==="-"||a.operator==="+"?i(a.argument):(i(a.argument),"notint");case"BinaryExpression":{let o=i(a.left),l=i(a.right);if(a.operator==="/"){if(o==="constint"&&l==="constint"){let c=C.createMathIntDivCall(a.left,a.right);return Object.assign(a,c),"constint"}return"notint"}return a.operator==="+"||a.operator==="-"||a.operator==="*"||a.operator==="%"?o==="constint"&&l==="constint"?"constint":o!=="notint"&&l!=="notint"?"int":"notint":"notint"}case"ConditionalExpression":{i(a.test);let o=i(a.consequent),l=i(a.alternate);return Rs(o,l)}case"LogicalExpression":return i(a.left),i(a.right),"notint";case"CallExpression":{a.callee?.type==="MemberExpression"&&i(a.callee.object);for(let l of a.arguments||[])i(l);let o=K_(a.callee);return o&&q_.has(o)?"int":"notint"}case"MemberExpression":return i(a.object),a.computed&&i(a.property),"notint";case"VariableDeclaration":{for(let o of a.declarations||[]){let l=o.init?i(o.init):"notint";o.id?.type==="Identifier"&&(l==="constint"&&(a.kind==="var"||r.has(o.id.name))&&(l="int"),n.set(o.id.name,l))}return"notint"}case"AssignmentExpression":{let o=i(a.right);return a.left?.type==="Identifier"?n.assign(a.left.name,o):i(a.left),o}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{n.push();for(let o of a.params||[]){let l=o.type==="AssignmentPattern"?o.left:o;l?.type==="Identifier"&&n.set(l.name,"notint")}return i(a.body),n.pop(),"notint"}default:return s(a),"notint"}}function s(a){for(let o in a){if(o==="type"||o==="start"||o==="end"||o==="loc"||o==="raw")continue;let l=a[o];if(Array.isArray(l))for(let c of l)c&&typeof c.type=="string"&&i(c);else l&&typeof l.type=="string"&&i(l)}}i(t)}var ai={type:"Identifier",name:"undefined"};function cr(t,e){let n={type:"Identifier",name:`\'${e}\'`};if(!t.isInsideFunctionScope())return n;let[r]=t.getVariable("$$");return r?{type:"BinaryExpression",operator:"+",left:C.createMemberExpression(C.createLocalContextIdentifier(),C.createIdentifier("id")),right:n}:n}function De(t,e){let[n,r]=e.getVariable(t);if((n.match(/^fn\\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){let[i]=e.getVariable("$$");if(i)return C.createLocalContextVariableReference(r,n)}return C.createContextVariableReference(r,n)}function Ls(t,e){let n=De(t,e);return C.createGetCall(n,0)}function bn(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){let n=C.createIdentifier(t.object.name);n._skipTransformation=!0;let r=C.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){let n=De(t.object.name,e),r=C.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){let n=C.createIdentifier(t.property.name);n._skipTransformation=!0,t.property=C.createGetCall(n,0)}else t.property=De(t.property.name,e),t.property=C.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){let n=C.createIdentifier(t.object.name);n._skipTransformation=!0;let r=C.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=De(t.object.name,e)),t.property.type==="MemberExpression"){let n=t.property;n._indexTransformed||(bn(n,e),n._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=Vt(t.property,e))}function He(t,e){let n=C.createGetCall(C.createIdentifier(t.name),0);t.start!==void 0&&(n.start=t.start),t.end!==void 0&&(n.end=t.end),n._indexTransformed=!0,Object.assign(t,n)}function Te(t,e){if(!t._skipTransformation&&t.name!==we){if(Nt.includes(t.name)&&e.isContextBound(t.name)){let h=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,d=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!h&&!d){let f={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=C.createGetCall(f,0);Object.assign(t,m),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("\'")&&t.name.endsWith("\'")||t.name.startsWith(\'"\')&&t.name.endsWith(\'"\')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let n=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){let h=t.parent.callee;if(h.type==="MemberExpression"&&h.object&&h.object.name===we&&["get","set","init","param","call"].includes(h.property.name)){let d=t.parent.arguments.indexOf(t);h.property.name==="call"?d>=2&&(n=!0):d===0&&(n=!0)}else{let d=h.type==="MemberExpression"&&h.object&&h.object.type==="Identifier"&&an.includes(h.object.name);h.type==="MemberExpression"&&!d?n=!1:n=!0}}let r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),i=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;let s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,a=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(r||i||n||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===we&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;let h=De(t.name,e);Object.assign(t,h);return}let l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){let h=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),d=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,f=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!h&&!d&&!f)return}if(e.isLocalSeriesVar(t.name)){if(!a){let h=C.createIdentifier(t.name),d=C.createGetCall(h,0);Object.assign(t,d)}return}let[c,u]=e.getVariable(t.name),p;if(l)p=C.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=De(t.name,e)}if(a)Object.assign(t,p);else{let h=C.createGetCall(p,0);Object.assign(t,h)}}}function Ee(t,e,n){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.computed&&t.object&&t.object.type==="CallExpression"&&!t._historyTransformed){t.object._transformed||Ne(t.object,n);let l=n.generateParamId(),c={type:"CallExpression",callee:C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("param")),arguments:[t.object,ai,cr(n,l)],_transformed:!0,_isParamCall:!0},u=C.createGetCall(c,t.property);u._transformed=!0,u._historyTransformed=!0,Object.assign(t,u),delete t.object,delete t.property,delete t.computed;return}if(t.object&&t.object.type==="Identifier"&&an.includes(t.object.name)&&n.isContextBound(t.object.name)&&!t.computed){let l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){let u={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(u.start=t.start),t.end!==void 0&&(u.end=t.end),Object.assign(t,u);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&n.isLocalSeriesVar(t.object.name)){let l=C.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=C.createGetCall(l,0);return}let r=n.getCurrentScopeType()=="if",i=n.getCurrentScopeType()=="els",s=n.getCurrentScopeType()=="for";if(!r&&!i&&!s&&t.object&&t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(bn(t,n),t._indexTransformed=!0);let a=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===we||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&n.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"&&Nt.includes(t.object.name)&&n.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});let l=C.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"&&n.isUdtInstance(l.object.name)){let c=l.object.name,u=n.isLocalSeriesVar(c)?(()=>{let h=C.createIdentifier(c);return h._skipTransformation=!0,h})():De(c,n);l.object=C.createGetCall(u,t.property);let p=t.object;Object.assign(t,p),delete t.computed;return}}}function ur(t,e){if(t.type==="Identifier"){if(Nt.includes(t.name)&&e.isContextBound(t.name)){let s=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:s},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){let[s,a]=e.getVariable(t.name);return C.createContextVariableReference(a,s)}if(e.isContextBound(t.name))return t;let[n,r]=e.getVariable(t.name),i=n!==t.name;return e.isLocalSeriesVar(t.name)&&!i?t:i?De(t.name,e):n===t.name&&!e.isContextBound(t.name)?t:De(t.name,e)}return t}function Vt(t,e,n=""){switch(t.type){case"BinaryExpression":return Vr(t,e,n);case"LogicalExpression":return Wr(t,e,n);case"MemberExpression":{let r=!t.computed&&t.object.type==="Identifier"&&Nt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&Nt.includes(t.object.name)&&e.isContextBound(t.object.name)){let a={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return C.createGetCall(a,t.property)}let i=t.object.type==="Identifier"&&!r?ur(t.object,e):t.object,s=i;if(!t.computed&&t.object.type==="Identifier"&&!r){let[a]=e.getVariable(t.object.name);a!==t.object.name&&!e.isLoopVariable(t.object.name)&&(s=C.createGetCall(i,0))}return{type:"MemberExpression",object:s,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;let r=ur(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:C.createGetCall(r,0)}case"UnaryExpression":return $r(t,e,n);case"ConditionalExpression":{let r=Vt(t.test,e,n),i=Vt(t.consequent,e,n),s=Vt(t.alternate,e,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function Vr(t,e,n){let r=Vt(t.left,e,n),i=Vt(t.right,e,n),s={type:"BinaryExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return Pe(s,e,{CallExpression(a,o){a._transformed||Ne(a,o)},MemberExpression(a){Ee(a,"",e)}}),s}function Wr(t,e,n){let r=Vt(t.left,e,n),i=Vt(t.right,e,n),s={type:"LogicalExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return Pe(s,e,{CallExpression(a,o){a._transformed||Ne(a,o)}}),s}function es(t,e,n){Pe(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(Nt.includes(a.name)&&e.isContextBound(a.name)){if(o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===a&&!o.parent.computed)return;let u={type:"MemberExpression",object:{type:"Identifier",name:a.name},property:{type:"Identifier",name:"__value"},computed:!1},p=C.createGetCall(u,0);Object.assign(a,p),delete a.name;return}a.parent=o.parent,Te(a,e);let c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?bn(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===we&&a.parent.callee.property.name==="get"||He(a)))},MemberExpression(a,o,l){Ee(a,"",e),a.object&&l(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})},ConditionalExpression(a,o,l){let c={...o,parent:a};a.test&&l(a.test,c),a.consequent&&l(a.consequent,c),a.alternate&&l(a.alternate,c)},BinaryExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},LogicalExpression(a,o,l){let c={...o,parent:a};l(a.left,c),l(a.right,c)},UnaryExpression(a,o,l){let c={...o,parent:a};l(a.argument,c)},CallExpression(a,o,l){let c=a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&a.callee.object.type==="Identifier"&&e.isContextBound(a.callee.object.name);Ne(a,e),a.arguments.forEach(u=>l(u,{parent:a,inNamespaceCall:c||o.inNamespaceCall}))}});let r=C.createMemberExpression(C.createIdentifier(n),C.createIdentifier("param")),i=e.generateParamId(),s={type:"CallExpression",callee:r,arguments:[t,ai,cr(e,i)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){let a=i;e.addLocalSeriesVar(a);let o=C.createVariableDeclaration(a,s);return e.addHoistedStatement(o),C.createIdentifier(a)}return s}function $r(t,e,n){let r=Vt(t.argument,e,n),i={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return Pe(i,e,{CallExpression(s,a){s._transformed||Ne(s,a)},MemberExpression(s){Ee(s,"",e)}}),i}function pn(t,e,n){switch(t?.type){case"BinaryExpression":t=Vr(t,n,e);break;case"LogicalExpression":t=Wr(t,n,e);break;case"ConditionalExpression":return es(t,n,e);case"UnaryExpression":t=$r(t,n,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(n.isContextBound(c.name)&&!n.isRootParam(c.name))return c;if(n.isLocalSeriesVar(c.name)){let u=C.createIdentifier(c.name);return C.createGetCall(u,0)}return Ls(c.name,n)}return c.type==="CallExpression"?(Ne(c,n),c):c.type==="BinaryExpression"?Vr(c,n,e):c.type==="LogicalExpression"?Wr(c,n,e):c.type==="ConditionalExpression"?es(c,n,e):c.type==="UnaryExpression"?$r(c,n,e):(c.type==="MemberExpression"&&Ee(c,e,n),c)});break}let r=t.type==="MemberExpression"&&t.computed&&t.property,i=t.type==="MemberExpression"&&!t.computed;if(r){if(t.object&&t.object.type==="MemberExpression"){let f=t.object;for(;f.object&&f.object.type==="MemberExpression";)f=f.object;if(f.object?.type==="Identifier"&&n.isUdtInstance(f.object.name)){let m=f.object.name,_=n.isLocalSeriesVar(m)?(()=>{let b=C.createIdentifier(m);return b._skipTransformation=!0,b})():De(m,n);return f.object=C.createGetCall(_,t.property),t.object}}if(t.object.type==="CallExpression")Ne(t.object,n);else if(t.object.type==="MemberExpression"){Ee(t.object,"",n);let f=t.object;for(;f&&f.type==="MemberExpression"&&f.object;){if(f.object.type==="Identifier"){let m=f.object,[_]=n.getVariable(m.name);_!==m.name&&!n.isContextBound(m.name)&&!n.isRootParam(m.name)&&!n.isLoopVariable(m.name)&&!n.isLocalSeriesVar(m.name)&&!Nt.includes(m.name)&&!an.includes(m.name)&&(f.object=Ls(m.name,n));break}f=f.object}}else t.object.type==="BinaryExpression"?t.object=Vr(t.object,n,e):t.object.type==="LogicalExpression"?t.object=Wr(t.object,n,e):t.object.type==="ConditionalExpression"?t.object=es(t.object,n,e):t.object.type==="UnaryExpression"&&(t.object=$r(t.object,n,e));let c=t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)?t.object:ur(t.object,n),u;t.property.type==="Identifier"&&!n.isContextBound(t.property.name)&&!n.isLoopVariable(t.property.name)?u=C.createGetCall(ur(t.property,n),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=Vt(t.property,n,e):u=t.property;let p=C.createMemberExpression(C.createIdentifier(e),C.createIdentifier("param")),h=n.generateParamId(),d={type:"CallExpression",callee:p,arguments:[c,u,cr(n,h)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let f=h;n.addLocalSeriesVar(f);let m=C.createVariableDeclaration(f,d);return n.addHoistedStatement(m),C.createIdentifier(f)}return d}if(i){if(t.object.type==="Identifier"&&an.includes(t.object.name)&&n.isContextBound(t.object.name)&&!t.computed){let c=t.object.name,u={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&u.arguments.push(n.getNextTACallId());let p=n.generateTempVar();n.addLocalSeriesVar(p);let h=C.createVariableDeclaration(p,u);return n.addOuterHoistedStatement(h),Object.assign(t,C.createIdentifier(p)),t}if(t.object.type==="Identifier"){let c=t.object.name,[u,p]=n.getVariable(c);if(u!==c&&!n.isLoopVariable(c)){let h=De(c,n),d=C.createGetCall(h,0);t.object=d}else if(n.isLocalSeriesVar(c)){let h=C.createIdentifier(c);h._skipTransformation=!0,t.object=C.createGetCall(h,0)}}else t.object.type==="MemberExpression"?pn(t.object,e,n):t.object.type==="CallExpression"&&(t.object._transformed||Ne(t.object,n))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>c.value.name?n.isContextBound(c.value.name)||n.isLocalSeriesVar(c.value.name)||n.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:C.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:De(c.value.name,n),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=pn(c.value,e,n)),c))),t.type==="Identifier"){if(Nt.includes(t.name)&&n.isContextBound(t.name)){let c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(n.isContextBound(t.name)&&!n.isRootParam(t.name)){let c=C.createMemberExpression(C.createIdentifier(e),C.createIdentifier("param")),u=n.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,ai,cr(n,u)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let h=u;n.addLocalSeriesVar(h);let d=C.createVariableDeclaration(h,p);return n.addHoistedStatement(d),C.createIdentifier(h)}return p}}t?.type==="CallExpression"&&Ne(t,n);let s=C.createMemberExpression(C.createIdentifier(e),C.createIdentifier("param")),a=t.type==="Identifier"?ur(t,n):t,o=n.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,ai,cr(n,o)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let c=o;n.addLocalSeriesVar(c);let u=C.createVariableDeclaration(c,l);return n.addHoistedStatement(u),C.createIdentifier(c)}return l}function er(t){if(!t)return!1;if(ic(t))return!0;if(t.type==="MemberExpression")return er(t.object);if(t.type==="ChainExpression")return er(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return er(e.object);if(e?.type==="ChainExpression")return er(e.expression)}return!1}function ic(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function Fs(t,e,n){t&&(t.type==="Identifier"?(t.parent=e,Te(t,n)):t.type==="MemberExpression"?Fs(t.object,t,n):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&Fs(t.callee.object,t.callee,n),t._transformed||Ne(t,n)))}function Ne(t,e,n){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(an.includes(t.callee.name)||Nt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=C.createMemberExpression(t.callee,C.createIdentifier("any")));let 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===we&&["get","init","param"].includes(t.callee.property.name))return;let i=t.callee.object.name,s=[];t.arguments.forEach(h=>{if(h._isParamCall){s.push(h);return}s.push(pn(h,i,e))}),t.arguments=s;let a=t.callee.property.name,o=`${i}.${a}`;if(Eo.includes(i)||Eo.includes(o)){let 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(i==="input"&&t._varId!==void 0&&t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__varId"},value:{type:"Literal",value:t._varId},kind:"init",computed:!1,shorthand:!1}]}),i==="alert"){let 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(i==="ta")if(e.getCurrentScopeType()==="fn"){let h=e.getNextTACallId(),[d]=e.getVariable("$$"),f;d?f=C.createMemberExpression(C.createLocalContextIdentifier(),C.createIdentifier("id")):f=C.createLiteral("");let m={type:"BinaryExpression",operator:"+",left:f,right:h};t.arguments.push(m)}else t.arguments.push(e.getNextTACallId());let l=t.callee.property.name,c=`${i}.${l}`,u=C_.includes(c),p=t._insideAwait===!0;if(u&&!p){let h=Object.assign({},t),d=C.createAwaitExpression(h);Object.assign(t,d)}if(!e.shouldSuppressHoisting()){let h=e.generateTempVar();e.addLocalSeriesVar(h);let d=t._insideAwait===!0,f=Object.assign({},t);d&&(f=C.createAwaitExpression(f));let m=C.createVariableDeclaration(h,f);e.addHoistedStatement(m);let _=C.createIdentifier(h);Object.assign(t,_),t._wasHoisted=!0,t._wasInsideAwait=d;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(i=>i._isParamCall?i:pn(i,we,e)),!e.isContextBound(t.callee.name)){let i=e.getNextUserCallId(),s=C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("call")),a=t.callee.name,o=t.callee;e.isUserMethod(a)&&!e.isRegularUserFunction(a)&&(o=C.createIdentifier(`$M_${a}`),o._skipTransformation=!0);let l=[o,i,...t.arguments];t.callee=s,t.arguments=l}t._transformed=!0}if(!r&&t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.property.name,s=e.isUserFunction(i),a=t.callee.object,o=a.type==="Identifier"&&e.isLocalSeriesVar(a.name),l=a.type==="MemberExpression",c=e.isUserMethod(i),u=!!a.name&&e.isUdtInstance(a.name);if(s&&c&&!e.isContextBound(i)&&!o&&!l&&u){let p=t.callee.object;t.callee.property;let h=t.arguments.map(v=>v._isParamCall?v:pn(v,we,e)),d=p;p.type==="Identifier"?d=pn(p,we,e):p.type==="CallExpression"&&(Ne(p,e),d=pn(p,we,e));let f=C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("call")),m=e.getNextUserCallId(),_=C.createIdentifier(`$M_${i}`);_._skipTransformation=!0;let b=[_,m,d,...h];t.callee=f,t.arguments=b,t._transformed=!0;return}t.callee.object.type==="Identifier"?Te(t.callee.object,e):Fs(t.callee.object,t.callee,e)}if(t.arguments.forEach(i=>{Pe(i,{parent:t},{Identifier(s,a,o){s.parent=a.parent,Te(s,e);let l=s.parent&&s.parent.type==="BinaryExpression";(s.parent&&s.parent.type==="ConditionalExpression"||l)&&(s.type==="MemberExpression"?bn(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===we&&s.parent.callee.property.name==="get"||He(s)))},BinaryExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},LogicalExpression(s,a,o){let l={...a,parent:s};o(s.left,l),o(s.right,l)},UnaryExpression(s,a,o){let l={...a,parent:s};o(s.argument,l)},CallExpression(s,a,o){s.callee&&s.callee.type==="MemberExpression"&&s.callee.object&&(s.callee.object.parent=s.callee,o(s.callee.object,{parent:s.callee})),s._transformed||Ne(s,e)},MemberExpression(s,a,o){Ee(s,"",e),s.object&&o(s.object,{parent:s})}})}),t.callee&&t.callee.type==="MemberExpression"){let i=t.callee.object,s=ic(i),a=i?.type==="MemberExpression"&&er(i);if(s||a){let o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function _a(t){let e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},n={type:"IfStatement",test:{type:"BinaryExpression",operator:">",_skipCompare:!0,left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:n}}function oi(t,e){let n=null;if(t.left.type==="Identifier")n=De(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){let r=t.left.object.name,[i,s]=e.getVariable(r),a=i!==r,o=e.isContextBound(r);(a||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(n=De(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,i=t.left;for(;i.type==="MemberExpression"&&!i.computed;){if(i.object.type==="Identifier"){r=i;break}i=i.object}if(r){let s=r.object.name,[a,o]=e.getVariable(s);if(a!==s&&!e.isLoopVariable(s)){let l=De(s,e),c=C.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(s)){let l=C.createIdentifier(s);l._skipTransformation=!0,r.object=C.createGetCall(l,0)}}}if(Pe(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,i,s){let a=i.parent&&i.parent.type==="MemberExpression"&&!i.parent.computed&&i.parent.object===r;if(Nt.includes(r.name)&&e.isContextBound(r.name)&&!a){let m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},_=C.createGetCall(m,0);Object.assign(r,_),delete r.name;return}r.parent=i.parent,Te(r,e);let 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",d=r.name==="NaN",f=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===we&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?bn(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!d&&!f&&He(r))},MemberExpression(r,i,s){Ee(r,"",e),r.type==="CallExpression"?r.arguments.forEach(a=>s(a,{parent:r,inNamespaceCall:i.inNamespaceCall})):r.object&&s(r.object,{parent:r,inNamespaceCall:i.inNamespaceCall})},CallExpression(r,i,s){let a=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);Ne(r,e),r.type==="CallExpression"&&(r.callee.type==="MemberExpression"&&s(r.callee,{parent:r,inNamespaceCall:a||i.inNamespaceCall}),r.arguments.forEach(o=>s(o,{parent:r,inNamespaceCall:a||i.inNamespaceCall})))}}),n){let r=t.right;if(t.operator!=="="){let s=t.operator.replace("=",""),a=C.createGetCall(n,0);r={type:"BinaryExpression",operator:s,left:a,right:t.right,start:t.start,end:t.end}}let i=C.createSetCall(n,r);t.start&&(i.start=t.start),t.end&&(i.end=t.end),Object.assign(t,i)}}function sc(t,e){t._skipTransformation||t.declarations.forEach(n=>{if(n.init?.type==="CallExpression"&&n.id?.type==="Identifier"){let h=n.init.callee;(h?.type==="MemberExpression"&&h.object?.type==="Identifier"&&h.object.name==="input"||h?.type==="Identifier"&&h.name==="input")&&(n.init._varId=n.id.name)}if(n.init&&n.init.type==="Identifier"&&Nt.includes(n.init.name)&&e.isContextBound(n.init.name)){let h=n.init.name;Object.assign(n.init,{type:"MemberExpression",object:{type:"Identifier",name:h},property:{type:"Identifier",name:"__value"},computed:!1}),delete n.init.name}let r=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===we||n.init.object.name==="context2"),i=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===we||n.init.object.object.name==="context2"),s=n.init&&n.init.type==="ArrowFunctionExpression";if(r){n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),n.init.object.name=we;return}if(i){n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),n.init.object.object.name=we;return}e.addVariable(n.id.name,t.kind);let a=t.kind,o=e.isArrayPatternElement(n.id.name)&&n.init&&n.init.type==="MemberExpression"&&n.init.computed;n.init&&!s&&!o&&(n.init.type==="CallExpression"&&n.init.callee.type==="MemberExpression"&&n.init.callee.object&&n.init.callee.object.type==="Identifier"&&e.isContextBound(n.init.callee.object.name)?Ne(n.init,e):Pe(n.init,{parent:n.init},{Identifier(h,d){h.parent=d.parent,Te(h,e);let f=h.parent&&h.parent.type==="BinaryExpression",m=h.parent&&h.parent.type==="UnaryExpression",_=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===we&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(f||m||_)&&!b&&He(h)},CallExpression(h,d,f){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")&&f(h.callee,{parent:h}),Ne(h,e),h.type==="CallExpression"&&(h.callee.type==="MemberExpression"&&f(h.callee,{parent:h}),h.arguments.forEach(m=>f(m,{parent:h})))},BinaryExpression(h,d,f){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),f(h.left,{parent:h}),f(h.right,{parent:h})},LogicalExpression(h,d,f){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),f(h.left,{parent:h}),f(h.right,{parent:h})},UnaryExpression(h,d,f){h.argument.type==="Identifier"&&(h.argument.parent=h),f(h.argument,{parent:h})},MemberExpression(h,d,f){h.object&&h.object.type==="Identifier"&&(h.object.parent=h),h.property&&h.property.type==="Identifier"&&(h.property.parent=h),Ee(h,"",e),h.type==="CallExpression"?h.arguments.forEach(m=>f(m,{parent:h})):h.object&&f(h.object,{parent:h})},AwaitExpression(h,d,f){h.argument&&(h.argument._insideAwait=!0,f(h.argument,{parent:h}),h.argument.type==="Identifier"&&h.argument._wasInsideAwait&&Object.assign(h,h.argument))},ArrowFunctionExpression(h,d,f){if(h.body)if(h.body.type==="BlockStatement"){let m=[];h.body.body.forEach(_=>{e.enterHoistingScope(),f(_,{parent:h.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(_)}),h.body.body=m}else f(h.body,{parent:h,insideIIFE:!0})},FunctionExpression(h,d,f){if(h.body&&h.body.type==="BlockStatement"){let m=[];h.body.body.forEach(_=>{e.enterHoistingScope(),f(_,{parent:h.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(_)}),h.body.body=m}},SwitchStatement(h,d,f){h.discriminant&&(h.discriminant.parent=h,f(h.discriminant,{parent:h})),h.cases&&h.cases.forEach(m=>{m.parent=h,f(m,{parent:h})})},SwitchCase(h,d,f){if(h.test&&(h.test.parent=h,f(h.test,{parent:h})),h.consequent){let m=[];h.consequent.forEach(_=>{e.enterHoistingScope(),_.parent=h,f(_,{parent:h});let b=e.exitHoistingScope();m.push(...b),m.push(_)}),h.consequent=m}},AssignmentExpression(h,d,f){if(d.insideIIFE){if(h.left.type==="Identifier"){let[m]=e.getVariable(h.left.name);if(m===h.left.name&&!e.isContextBound(h.left.name)){f(h.right,{parent:h});return}}oi(h,e)}}}));let l=De(n.id.name,e),c=!o&&n.init&&n.init.type==="MemberExpression"&&n.init.computed&&n.init.property&&(n.init.property.type==="Literal"||n.init.property.type==="MemberExpression");if(n.init?.property?.type==="MemberExpression"&&(n.init.property._indexTransformed||(bn(n.init.property,e),n.init.property._indexTransformed=!0)),a==="var"){let h=e.getCurrentHoistingScope();if(h){for(let d of h)if(d.type==="VariableDeclaration")for(let f of d.declarations){if(!f.init||f.init.type!=="CallExpression")continue;let m=f.init.callee;if(m?.type!=="MemberExpression")continue;let _,b=m.property?.name;if(m.object?.type==="Identifier"?_=m.object.name:m.object?.type==="MemberExpression"&&m.object.property?.name&&(_=m.object.property.name),_&&b){let v=`${_}.${b}`;N_.includes(v)&&(f.init={type:"ArrowFunctionExpression",params:[],body:f.init,expression:!0,async:!1})}}}}let u;n.init?s||o?u=n.init:a==="var"?u=C.createInitVarCall(l,n.init):u=C.createInitCall(l,c?n.init.object:n.init,c?n.init.property:void 0):u=C.createIdentifier("undefined");let p=C.createExpressionStatement(C.createAssignmentExpression(l,u));if(o){let h=n.init.object.name,d=De(h,e),f=n.init.property.value,m={type:"MemberExpression",object:C.createGetCall(d,0),property:{type:"Literal",value:f},computed:!0};p.expression.right=C.createCallExpression(C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("init")),[l,m])}s&&(e.pushScope("fn"),Pe(n.init.body,e,{IfStatement(h,d,f){d.pushScope("if"),h.test&&ac(h.test,d),f(h.consequent,d),h.alternate&&(d.pushScope("els"),f(h.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(h,d){sc(h,d)},Identifier(h,d){Te(h,d)},AssignmentExpression(h,d){oi(h,d)},SwitchStatement(h,d,f){h.discriminant.parent=h,f(h.discriminant,d),h.cases.forEach(m=>{m.parent=h,f(m,d)})},SwitchCase(h,d,f){h.test&&(h.test.parent=h,f(h.test,d));let m=[];h.consequent.forEach(_=>{d.enterHoistingScope(),f(_,d);let b=d.exitHoistingScope();m.push(...b),m.push(_)}),h.consequent=m},BlockStatement(h,d,f){let m=[];h.body.forEach(_=>{d.enterHoistingScope(),f(_,d);let b=d.exitHoistingScope();m.push(...b),m.push(_)}),h.body=m}}),e.popScope()),Object.assign(t,p)})}function X_(t,e,n){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0],a=s.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s.init}]},s.init&&Pe(s.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),Te(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,He(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),Ee(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(let u of o.arguments)c(u,l)}})}t.test&&Pe(t.test,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Te(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,He(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),Ee(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),t.update&&Pe(t.update,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),Te(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,He(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),Ee(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=_a(r);if(e.addHoistedStatement(i.counterDecl),e.pushScope("for"),n(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0];e.removeLoopVariable(s.id.name)}}function Z_(t,e,n){e.setSuppressHoisting(!0),t.test&&Pe(t.test,e,{Identifier(s,a){s.computed||(Te(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,He(s))))},MemberExpression(s,a,o){Ee(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),Ne(s,a),s.arguments)for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=_a(r);e.addHoistedStatement(i.counterDecl),e.pushScope("whl"),n(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck)}function ac(t,e){Pe(t,e,{MemberExpression(n,r,i){n.object&&n.object.type==="Identifier"&&!e.isContextBound(n.object.name)&&!n.computed&&(n.object.parent=n,i(n.object,r)),Ee(n,"",e)},CallExpression(n,r){Ne(n,r)},BinaryExpression(n,r,i){n.left.type==="Identifier"&&(n.left.parent=n),n.right.type==="Identifier"&&(n.right.parent=n),i(n.left,r),i(n.right,r)},LogicalExpression(n,r,i){n.left.type==="Identifier"&&(n.left.parent=n),n.right.type==="Identifier"&&(n.right.parent=n),i(n.left,r),i(n.right,r)},UnaryExpression(n,r,i){n.argument.type==="Identifier"&&(n.argument.parent=n),i(n.argument,r)},Identifier(n,r){let i=n.parent,s=i&&i.type==="UnaryExpression",a=i&&i.type==="BinaryExpression",o=i&&i.type==="LogicalExpression",l=i&&i.type==="ConditionalExpression";Te(n,r),n.type==="Identifier"&&(s||a||o||l)&&(i&&i.type==="CallExpression"&&i.callee&&i.callee.object&&i.callee.object.name===we&&i.callee.property?.name==="get"||He(n));let c=e.getCurrentScopeType()==="if";e.isContextBound(n.name)&&!e.isRootParam(n.name)&&c&&He(n)}})}function Q_(t,e,n){t.test&&(e.pushScope("if"),ac(t.test,e),e.popScope()),e.pushScope("if"),n(t.consequent,e),e.popScope(),t.alternate&&(e.pushScope("els"),n(t.alternate,e),e.popScope())}function J_(t,e){let n=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)?C.createGetCall(r,0):Ls(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)?C.createGetCall(r,0):(Ee(r,"",e),r):((r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")&&Pe(r,e,{Identifier(i,s){Te(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(He(i),i._arrayAccessed=!0)},MemberExpression(i){Ee(i,"",e)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),Ne(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.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:C.createIdentifier(r.key.name),value:De(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=De(r.value.name,e))),r));else if(t.argument.type==="Identifier")Te(t.argument,e),t.argument.type==="Identifier"&&He(t.argument);else if(t.argument.type==="MemberExpression"){if(t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&!(t.argument.computed&&e.isLocalSeriesVar(t.argument.object.name)))Te(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)&&Ee(t.argument,"",e)}}if(n==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=C.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.computed&&t.argument.object.type==="CallExpression"?Ee(t.argument,"",e):t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)?t.argument.computed?Ee(t.argument,"",e):t.argument._indexTransformed||(bn(t.argument,e),t.argument._indexTransformed=!0):t.argument.computed&&t.argument.object.type==="Identifier"&&e.isLocalSeriesVar(t.argument.object.name)&&Ee(t.argument,"",e):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&Pe(t.argument,e,{Identifier(i,s){Te(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(He(i),i._arrayAccessed=!0)},MemberExpression(i){Ee(i,"",e)},AssignmentExpression(i,s){oi(i,s)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),Ne(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)},ArrowFunctionExpression(i,s,a){if(i.body)if(i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}else a(i.body,s)},FunctionExpression(i,s,a){if(i.body&&i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}},SwitchStatement(i,s,a){i.discriminant.parent=i,a(i.discriminant,s),i.cases.forEach(o=>{o.parent=i,a(o,s)})},SwitchCase(i,s,a){i.test&&(i.test.parent=i,a(i.test,s));let o=[];i.consequent.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.consequent=o},BlockStatement(i,s,a){let o=[];i.body.forEach(l=>{s.enterHoistingScope(),a(l,s);let c=s.exitHoistingScope();o.push(...c),o.push(l)}),i.body=o}});let r=C.createCallExpression(C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("precision")),[t.argument]);t.argument=r}}}function e1(t,e,n){let r=C.createVariableDeclaration("$$",C.createCallExpression(C.createMemberExpression(C.createContextIdentifier(),C.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)});let i=t.id?.name,s=i?.startsWith("$M_")?i.slice(3):i,a=s?e.getFunctionParamUdtTypes(s):void 0,o={};if(a)for(let[l,c]of Object.entries(a))o[l]=e.getVariableUdtType(l),e.markVariableAsUdtInstance(l,c);if(n(t.body,e),t.params.forEach(l=>{l.type==="Identifier"&&e.removeLocalSeriesVar(l.name)}),a)for(let l of Object.keys(a)){e.unmarkVariableAsUdtInstance(l);let c=o[l];c!==void 0&&e.markVariableAsUdtInstance(l,c)}e.popScope()}}function t1(t){let e={...P,LineComment:()=>{}};function n(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}let r=new Map;It(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function i(o){let l=!1,c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return It(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,It(t,{ArrowFunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)},FunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)}},e);let o=[];It(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(let c of o){let u={};for(let p of Object.keys(c))u[p]=c[p];u._asyncWrapped=!0;for(let p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=u,s=!0}let l=new Set;for(let[c,u]of r)i(u.body)&&(u.async||(u.async=!0,s=!0),l.add(c));if(l.size>0){let c=[];It(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){let p=n(u.arguments[0]);p&&l.has(p)&&c.push(u)}}},e);for(let u of c){let p={};for(let h of Object.keys(u))p[h]=u[h];p._asyncWrapped=!0;for(let h of Object.keys(u))delete u[h];u.type="AwaitExpression",u.argument=p,s=!0}}}}var n1={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},r1=new Set(["<","<=",">",">="]);function i1(t,e){if(t._skipCompare)return!0;for(let n=0;n<e.length-1;n++){let r=e[n],i=e[n+1];if(r.type==="ForStatement"&&(i===r.test||i===r.update)||(r.type==="WhileStatement"||r.type==="DoWhileStatement")&&i===r.test)return!0}return!1}function s1(t){let e={...P,LineComment:()=>{}};tc(t,{BinaryExpression(n,r,i){let s=n1[n.operator];if(!s||r1.has(n.operator)&&i1(n,i))return;let a=C.createMathCompareCall(s,n.left,n.right);a._transformed=!0,Object.assign(n,a)}},e)}function a1(t,e,n,r={debug:!1,ln:!1},i=[]){let s=a=>{if(!r.debug||!a.loc||!i.length)return null;let o=a.loc.start.line-1;if(o>=0&&o<i.length){let l=i[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${a.loc.start.line}]`:""} ${l}`}}return null};Pe(t,e,{Program(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let p=o.exitHoistingScope(),h=s(u);h&&c.push(h),c.push(...p),c.push(u)}),a.body=c},BlockStatement(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let 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),J_(a,o)},VariableDeclaration(a,o){sc(a,o)},Identifier(a,o){Te(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)),Ne(a,o)},ArrowFunctionExpression(a,o,l){a.body&&l(a.body,o)},FunctionExpression(a,o,l){a.body&&l(a.body,o)},ForOfStatement(a,o,l){if(a.left&&a.left.type==="VariableDeclaration"){a.left._skipTransformation=!0;let 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"?(Te(a.right,o),a.right.type==="Identifier"&&He(a.right)):l(a.right,o);let p=a.left&&a.left.type==="VariableDeclaration"&&a.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",h={...a.right},d=C.createCallExpression(C.createMemberExpression(C.createIdentifier("$"),C.createIdentifier(p),!1),[h]);Object.assign(a.right,d)}let c=o.getNextLoopGuardName(),u=_a(c);if(o.addHoistedStatement(u.counterDecl),a.body&&l(a.body,o),a.body&&a.body.type==="BlockStatement"&&a.body.body.unshift(u.guardCheck),a.left&&a.left.type==="VariableDeclaration"){let 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"?(Te(a.right,o),a.right.type==="Identifier"&&He(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)),Ee(a,n,o)},AssignmentExpression(a,o,l){if(oi(a,o),a.type==="CallExpression"&&a.arguments){let c=u=>{u&&(u.type==="CallExpression"&&u.callee&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&l(u.callee,o),u.type==="BinaryExpression"&&(c(u.left),c(u.right)))};a.arguments.forEach(u=>c(u))}},FunctionDeclaration(a,o,l){e1(a,o,l)},ForStatement(a,o,l){X_(a,o,l)},WhileStatement(a,o,l){Z_(a,o,l)},IfStatement(a,o,l){Q_(a,o,l)},SwitchStatement(a,o,l){a.discriminant.parent=a,l(a.discriminant,o),a.cases.forEach(c=>{c.parent=a,l(c,o)})},SwitchCase(a,o,l){a.test&&(a.test.parent=a,l(a.test,o));let c=[];a.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);let 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))}})}var x={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"},o1=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),l1=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],Bs=class{constructor(e,n,r,i,s=0,a=null){this.type=e,this.value=n,this.line=r,this.column=i,this.indent=s,this.raw=a}},c1=Object.defineProperty,u1=(t,e,n)=>e in t?c1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Pt=(t,e,n)=>u1(t,typeof e!="symbol"?e+"":e,n),Vs=class{constructor(e){Pt(this,"source"),Pt(this,"pos"),Pt(this,"line"),Pt(this,"column"),Pt(this,"tokens"),Pt(this,"indentStack"),Pt(this,"atLineStart"),Pt(this,"parenDepth"),Pt(this,"bracketDepth"),Pt(this,"braceDepth"),this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){let e=this.peek();if(e==="\\r"){this.advance();continue}if(e===`\n`){this.handleNewline();continue}if(this.atLineStart&&e!==`\n`){this.handleIndentation(),this.atLineStart=!1;continue}if(e===" "||e===" "){this.advance();continue}if(this.pos>=this.source.length)break;if(e==="/"&&this.peek(1)==="/"){this.readComment();continue}if(e===\'"\'||e==="\'"){this.readString();continue}if(e==="#"){this.readColorLiteral();continue}if(this.isDigit(e)){this.readNumber();continue}if(this.isIdentifierStart(e)){this.readIdentifier();continue}if(!this.readOperatorOrPunctuation())throw new Error(`Unexpected character \'${e}\' at ${this.line}:${this.column}`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.addToken(x.DEDENT,"",this.getCurrentIndent());return this.addToken(x.EOF,""),this.tokens}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(x.NEWLINE,`\n`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0,n=0;for(this.pos;this.pos<this.source.length;){let i=this.peek();if(i===" ")n++,this.advance();else if(i===" ")e++,this.advance();else break}if(this.peek()===`\n`||this.peek()==="\\r"||this.peek()==="\\0"||(e+=Math.floor(n/4),this.isContinuationFromPrevToken()))return;let r=this.indentStack[this.indentStack.length-1];if(e>r)this.indentStack.push(e),this.addToken(x.INDENT,"",e);else if(e<r){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>e;)this.indentStack.pop(),this.addToken(x.DEDENT,"",this.indentStack[this.indentStack.length-1]);if(this.indentStack[this.indentStack.length-1]!==e)throw new Error(`Indentation error at ${this.line}:${this.column} - misaligned dedent`)}}isContinuationFromPrevToken(){for(let e=this.tokens.length-1;e>=0;e--){let n=this.tokens[e];if(!(n.type===x.NEWLINE||n.type===x.COMMENT))return n.type===x.OPERATOR?n.value!=="=>":n.type===x.COMMA||n.type===x.COLON||n.type===x.KEYWORD&&(n.value==="and"||n.value==="or")}return!1}readComment(){this.column;let e="";for(this.advance(),this.advance();this.pos<this.source.length&&this.peek()!==`\n`;)e+=this.advance();this.addToken(x.COMMENT,e.trim())}readString(){let e=this.advance(),n=this.column-1,r="";for(;this.pos<this.source.length&&this.peek()!==e;)if(this.peek()==="\\\\"){this.advance();let i=this.advance();switch(i){case"n":r+=`\n`;break;case"t":r+=" ";break;case"r":r+="\\r";break;case"\\\\":r+="\\\\";break;case e:r+=e;break;default:r+=i}}else r+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${n}`);this.advance(),this.addToken(x.STRING,r)}readColorLiteral(){let e=this.column,n="#";for(this.advance();this.pos<this.source.length&&n.length<9;){let r=this.peek();if(r>="0"&&r<="9"||r>="A"&&r<="F"||r>="a"&&r<="f")n+=this.advance();else break}if(n.length!==7&&n.length!==9)throw new Error(`Invalid color literal \'${n}\' at ${this.line}:${e}`);this.addToken(x.STRING,n)}readNumber(){this.column;let e="",n=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(n=!0,e+=this.advance());this.pos<this.source.length;){let r=this.peek();if(this.isDigit(r))e+=this.advance();else if(r==="."&&!n){let i=this.peek(1);if(this.isDigit(i)||!this.isIdentifierStart(i)){if(n=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){let r=this.peek();if(r==="e"||r==="E"){let i=this.peek(1);if(this.isDigit(i))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(i==="+"||i==="-"){let s=this.peek(2);if(this.isDigit(s))for(e+=this.advance(),e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance()}}}this.addToken(x.NUMBER,parseFloat(e),null,e)}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();o1.has(e)?this.addToken(x.KEYWORD,e):e==="true"||e==="false"?this.addToken(x.BOOLEAN,e==="true"):this.addToken(x.IDENTIFIER,e)}readOperatorOrPunctuation(){let e=this.peek(),n=this.peek(1),r=e+n;if(l1.includes(r))return this.advance(),this.advance(),this.addToken(x.OPERATOR,r),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(x.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(x.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(x.RPAREN,e),!0;case"[":return this.bracketDepth++,this.advance(),this.addToken(x.LBRACKET,e),!0;case"]":return this.bracketDepth--,this.advance(),this.addToken(x.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(x.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(x.RBRACE,e),!0;case",":return this.advance(),this.addToken(x.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(x.DOT,e),!0);case":":return this.advance(),this.addToken(x.COLON,e),!0;case";":return this.advance(),this.addToken(x.SEMICOLON,e),!0}return!1}peek(e=0){let n=this.pos+e;return n<this.source.length?this.source[n]:"\\0"}advance(){let e=this.source[this.pos++];return this.column++,e}skipWhitespaceInline(){if(!this.atLineStart)for(;this.pos<this.source.length&&(this.peek()===" "||this.peek()===" ");)this.advance()}isDigit(e){return e>="0"&&e<="9"}isIdentifierStart(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}isIdentifierChar(e){return this.isIdentifierStart(e)||this.isDigit(e)}getCurrentIndent(){return this.indentStack[this.indentStack.length-1]}addToken(e,n,r=null,i=null){let s=new Bs(e,n,this.line,this.column,r!==null?r:this.getCurrentIndent(),i);this.tokens.push(s)}},h1=Object.defineProperty,p1=(t,e,n)=>e in t?h1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,st=(t,e,n)=>p1(t,typeof e!="symbol"?e+"":e,n),ue=class{constructor(e){this.type=e}},Ws=class extends ue{constructor(e){super("Program"),this.body=e}},Qe=class extends ue{constructor(e){super("ExpressionStatement"),this.expression=e}},qt=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(qt||{}),vt=class extends ue{constructor(e,n="let"){super("VariableDeclaration"),this.declarations=e,this.kind=n}},pt=class extends ue{constructor(e,n,r=null){super("VariableDeclarator"),this.id=e,this.init=n,this.varType=r}},li=class extends ue{constructor(e,n,r,i=null){super("FunctionDeclaration"),this.id=e,this.params=n,this.body=r,this.returnType=i}},$s=class extends ue{constructor(e,n){super("TypeDefinition"),this.name=e,this.fields=n}},js=class extends ue{constructor(e,n,r=null){super("IfStatement"),this.test=e,this.consequent=n,this.alternate=r,st(this,"_line")}},ci=class extends ue{constructor(e,n,r,i){super("ForStatement"),this.init=e,this.test=n,this.update=r,this.body=i,st(this,"isForIn")}},Us=class extends ue{constructor(e,n){super("WhileStatement"),this.test=e,this.body=n}},Ot=class extends ue{constructor(e){super("BlockStatement"),this.body=e}},ui=class extends ue{constructor(e){super("ReturnStatement"),this.argument=e}},Ie=class extends ue{constructor(e){super("Identifier"),this.name=e,st(this,"varType"),st(this,"returnType"),st(this,"isMethod")}},Ht=class extends ue{constructor(e,n=null){super("Literal"),this.value=e,this.raw=n}},wt=class extends ue{constructor(e,n,r){super("BinaryExpression"),this.operator=e,this.left=n,this.right=r}},hi=class extends ue{constructor(e,n,r=!0){super("UnaryExpression"),this.operator=e,this.argument=n,this.prefix=r}},dn=class extends ue{constructor(e,n,r){super("AssignmentExpression"),this.operator=e,this.left=n,this.right=r}},pi=class extends ue{constructor(e,n,r=!1){super("UpdateExpression"),this.operator=e,this.argument=n,this.prefix=r}},zs=class extends ue{constructor(e,n){super("CallExpression"),this.callee=e,this.args=n,st(this,"arguments"),this.callee=e,this.arguments=n}},di=class extends ue{constructor(e,n,r=!1){super("MemberExpression"),this.object=e,this.property=n,this.computed=r}},Lt=class extends ue{constructor(e,n,r){super("ConditionalExpression"),this.test=e,this.consequent=n,this.alternate=r,st(this,"needsIIFE"),st(this,"consequentStmts"),st(this,"alternateStmts")}},qs=class extends ue{constructor(e){super("ArrayExpression"),this.elements=e}},fi=class extends ue{constructor(e){super("ObjectExpression"),this.properties=e}},mi=class extends ue{constructor(e,n){super("Property"),this.key=e,this.value=n,st(this,"kind"),st(this,"method"),st(this,"shorthand"),st(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},yi=class extends ue{constructor(e){super("ArrayPattern"),this.elements=e}},gi=class extends ue{constructor(e,n){super("AssignmentPattern"),this.left=e,this.right=n}},Hs=class extends ue{constructor(e,n){super("SwitchExpression"),this.discriminant=e,this.cases=n}},Ks=class extends ue{constructor(e,n,r){super("SwitchCase"),this.test=e,this.consequent=n,this.statements=r,this.statements=r}},d1=Object.defineProperty,f1=(t,e,n)=>e in t?d1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ln=(t,e,n)=>f1(t,typeof e!="symbol"?e+"":e,n),oc=class Ys{constructor(e){Ln(this,"tokens"),Ln(this,"pos"),Ln(this,"functionNames",new Set),Ln(this,"paramScopes",[]),Ln(this,"noLineContinuation",!1),this.tokens=e,this.pos=0}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}isCurrentFunctionParam(e){for(let n of this.paramScopes)if(n.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,n=null){let r=this.peek();return!(r.type!==e||n!==null&&r.value!==n)}expect(e,n=null){let r=this.peek();if(r.type!==e)throw new Error(`Expected ${e} but got ${r.type} at ${r.line}:${r.column}`);if(n!==null&&r.value!==n)throw new Error(`Expected \'${n}\' but got \'${r.value}\' at ${r.line}:${r.column}`);return this.advance()}expectIdentifierOrContextual(){let e=this.peek();if(e.type===x.IDENTIFIER)return this.advance();if(e.type===x.KEYWORD&&Ys.CONTEXTUAL_KEYWORDS.has(e.value))return this.advance();throw new Error(`Expected ${x.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`)}matchEx(e,n=null,r=!1){if(!r)return this.match(e,n);let i=0,s=this.peek(i);if(s.type===x.NEWLINE&&this.noLineContinuation||(s.type===x.NEWLINE&&(i++,s=this.peek(i),s.type===x.INDENT&&(i++,s=this.peek(i))),s.type!==e)||n!==null&&s.value!==n)return!1;for(let a=0;a<i;a++)this.advance();return!0}peekOperatorEx(e){let n=0,r=this.peek(n),i=!1;if(r.type===x.NEWLINE){if(this.noLineContinuation)return null;n++,r=this.peek(n),r.type===x.INDENT&&(i=!0,n++,r=this.peek(n))}if(r.type!==x.OPERATOR||!e.includes(r.value)||i&&(r.value==="+"||r.value==="-"))return null;for(let s=0;s<n;s++)this.advance();return r.value}skipNewlines(e=!1){for(;this.match(x.NEWLINE)||this.match(x.COMMENT);)this.advance();e&&this.match(x.INDENT)&&this.advance()}parse(){let e=[];for(;!this.match(x.EOF);){if(this.skipNewlines(),this.match(x.DEDENT)){this.advance();continue}if(this.match(x.EOF))break;let n=this.parseStatement();n&&e.push(n),this.skipNewlines()}return new Ws(e)}parseStatement(e=!0){this.skipNewlines();let n=this.peek().line;if(this.match(x.COMMENT))return this.advance(),null;let r;if(this.match(x.KEYWORD,"enum"))r=this.parseEnumDefinition();else if(this.match(x.KEYWORD,"type"))r=this.parseTypeDefinition();else if(this.match(x.KEYWORD,"var")||this.match(x.KEYWORD,"varip"))r=this.parseVarDeclaration();else if(this.match(x.KEYWORD,"method"))r=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())r=this.parseFunctionDeclaration();else if(this.match(x.KEYWORD,"if"))r=this.parseIfStatement();else if(this.match(x.KEYWORD,"for"))r=this.parseForStatement();else if(this.match(x.KEYWORD,"while"))r=this.parseWhileStatement();else if(this.match(x.KEYWORD,"break")||this.match(x.KEYWORD,"continue")){let i=this.advance().value;r=new Qe(new Ie(i))}else this.isTupleDestructuring()?r=this.parseTupleDestructuring():this.peek().type===x.IDENTIFIER&&this.isTypedVarDeclaration()&&(r=this.parseTypedVarDeclaration());if(!r){let i=this.parseExpression();if(this.match(x.OPERATOR)){let s=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(s)){this.advance(),this.skipNewlines(!0);let a=this.parseExpression();s==="="&&i.type==="Identifier"?r=new vt([new pt(i,a)],qt.LET):r=new Qe(new dn(s===":="?"=":s,i,a))}else r=new Qe(i)}else r=new Qe(i)}if(r&&(r._line=n,e&&this.match(x.COMMA)&&this.peek().line===n)){let i=[r];for(;this.match(x.COMMA)&&this.peek().line===n;){this.advance(),this.skipNewlines(!0);let s=this.parseStatement(!1);s&&i.push(s)}return new Ot(i)}return r}isFunctionDeclaration(){let e=this.pos;try{let n=0;if(this.peek(n).type===x.IDENTIFIER&&this.peek(n+1).type===x.IDENTIFIER&&n++,this.peek(n).type!==x.IDENTIFIER||(n++,this.peek(n).type!==x.LPAREN))return!1;n++;let r=1;for(;r>0&&this.peek(n).type!==x.EOF;)this.peek(n).type===x.LPAREN&&r++,this.peek(n).type===x.RPAREN&&r--,n++;for(;this.peek(n).type===x.NEWLINE;)n++;return this.peek(n).type===x.OPERATOR&&this.peek(n).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(x.IDENTIFIER).value;for(;this.match(x.DOT)&&this.peek(1).type===x.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(x.OPERATOR,"<")){this.advance();let n=[];for(n.push(this.parseTypeExpression());this.match(x.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseTypeExpression());return this.expect(x.OPERATOR,">"),e+"<"+n.join(", ")+">"}return this.match(x.LBRACKET)&&this.peek(1).type===x.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(x.KEYWORD,"enum");let e=this.expect(x.IDENTIFIER).value;this.skipNewlines(),this.expect(x.INDENT);let n=[];for(;!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){if(this.match(x.COMMENT)){this.advance();continue}let s=this.expectIdentifierOrContextual().value,a=null;this.match(x.OPERATOR,"=")&&(this.advance(),a=this.expect(x.STRING).value),n.push({name:s,title:a}),this.skipNewlines()}this.match(x.DEDENT)&&this.advance();let r=n.map(s=>new mi(new Ie(s.name),new Ht(s.title!==null?s.title:s.name))),i=new fi(r);return new vt([new pt(new Ie(e),i)],qt.CONST)}parseTypeDefinition(){this.expect(x.KEYWORD,"type");let e=this.expect(x.IDENTIFIER).value;this.match(x.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(x.INDENT);let n=[];for(;!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let r=this.parseTypeExpression(),i=this.expectIdentifierOrContextual().value,s=null;this.match(x.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),n.push({type:r,name:i,defaultValue:s}),this.skipNewlines()}return this.match(x.DEDENT)&&this.advance(),new $s(e,n)}parseVarDeclaration(){let e=this.advance().value,n=null,r=null;if(this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.LBRACKET&&this.peek(2).type===x.RBRACKET)n=this.advance().value,this.advance(),n+="[]",this.advance(),r=this.expectIdentifierOrContextual().value;else if(this.peek().type===x.IDENTIFIER&&(this.peek(1).type===x.DOT||this.peek(1).type===x.IDENTIFIER||this.peek(1).type===x.OPERATOR&&this.peek(1).value==="<")){for(n=this.advance().value;this.match(x.DOT)&&this.peek(1).type===x.IDENTIFIER;)this.advance(),n+="."+this.advance().value;if(this.match(x.LBRACKET)&&this.peek(1).type===x.RBRACKET)this.advance(),this.advance(),n+="[]",r=this.expectIdentifierOrContextual().value;else if(this.match(x.OPERATOR,"<")){for(this.advance(),n+="<";!this.match(x.OPERATOR,">");)if(this.match(x.IDENTIFIER))for(n+=this.advance().value;this.match(x.DOT)&&this.peek(1).type===x.IDENTIFIER;)n+=".",this.advance(),n+=this.advance().value;else if(this.match(x.COMMA))n+=this.advance().value,this.skipNewlines();else break;this.match(x.OPERATOR,">")&&(n+=">",this.advance()),r=this.expectIdentifierOrContextual().value}else r=this.expectIdentifierOrContextual().value}else if(this.peek().type===x.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(x.OPERATOR,"="),this.skipNewlines(!0);let i=this.parseExpression(),s=new Ie(r);n&&(s.varType=n);let a=[new pt(s,i,n)];for(;this.match(x.COMMA)&&this.peek(1).type===x.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();let o=this.parseVarDeclaration();a.push(...o.declarations)}return new vt(a,e)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==x.IDENTIFIER)return!1;for(e++;this.peek(e).type===x.DOT&&this.peek(e+1).type===x.IDENTIFIER;)e+=2;if(this.peek(e).type===x.LBRACKET&&this.peek(e+1).type===x.RBRACKET)return e+=2,this.peek(e).type!==x.IDENTIFIER?!1:(e++,this.peek(e).type===x.OPERATOR&&this.peek(e).value==="=");if(this.peek(e).type===x.OPERATOR&&this.peek(e).value==="<"){e++;let n=1;for(;n>0&&this.peek(e).type!==x.EOF;)this.peek(e).type===x.OPERATOR&&this.peek(e).value==="<"?n++:this.peek(e).type===x.OPERATOR&&this.peek(e).value===">"&&n--,e++;return this.peek(e).type!==x.IDENTIFIER?!1:(e++,this.peek(e).type===x.OPERATOR&&this.peek(e).value==="=")}if(this.peek(e).type!==x.IDENTIFIER)return!1;for(e++;this.peek(e).type===x.IDENTIFIER;)e++;return this.peek(e).type===x.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(x.DOT)&&this.peek(1).type===x.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(x.LBRACKET)&&this.peek(1).type===x.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(x.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(x.OPERATOR,">");)if(this.match(x.IDENTIFIER))for(e+=this.advance().value;this.match(x.DOT)&&this.peek(1).type===x.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(x.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(x.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.IDENTIFIER;)e+=" "+this.advance().value;let n=this.expectIdentifierOrContextual().value;this.functionNames.has(n)&&(n=n+"_var"),this.expect(x.OPERATOR,"="),this.skipNewlines(!0);let r=this.parseExpression(),i=new Ie(n);i.varType=e;let s=[new pt(i,r,e)];for(;this.match(x.COMMA)&&this.peek(1).type===x.IDENTIFIER&&this.peek(2).type===x.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let a=this.expectIdentifierOrContextual().value;this.functionNames.has(a)&&(a=a+"_var"),this.expect(x.OPERATOR,"="),this.skipNewlines(!0);let o=this.parseExpression(),l=new Ie(a);l.varType=e,s.push(new pt(l,o,e))}return new vt(s,qt.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.IDENTIFIER&&(e=this.advance().value);let n=this.expect(x.IDENTIFIER).value;this.functionNames.add(n),this.expect(x.LPAREN);let r=[];for(;!this.match(x.RPAREN)&&(this.skipNewlines(),!this.match(x.RPAREN));){let o=null;for(;this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.IDENTIFIER&&this.peek(2).type!==x.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.LBRACKET&&this.peek(2).type===x.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new Ie(l);if(o&&(c.varType=o),this.match(x.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();r.push(new gi(c,u))}else r.push(c);this.match(x.COMMA)&&this.advance()}this.expect(x.RPAREN),this.skipNewlines(),this.expect(x.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of r){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new Ie(n);return e&&(a.returnType=e),new li(a,r,s,e)}parseMethodDeclaration(){this.expect(x.KEYWORD,"method");let e=null;this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.IDENTIFIER&&this.peek(2).type===x.LPAREN&&(e=this.advance().value);let n=this.expectIdentifierOrContextual().value;this.expect(x.LPAREN);let r=[];for(;!this.match(x.RPAREN)&&(this.skipNewlines(),!this.match(x.RPAREN));){let o=null;for(;this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.IDENTIFIER&&this.peek(2).type!==x.LPAREN;)o&&(o+=" "),o=(o||"")+this.advance().value;if(this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.OPERATOR&&this.peek(1).value==="<"){let u=this.parseTypeExpression();o=o?o+" "+u:u}if(this.peek().type===x.IDENTIFIER&&this.peek(1).type===x.LBRACKET&&this.peek(2).type===x.RBRACKET){let u=this.parseTypeExpression();o=o?o+" "+u:u}let l=this.expectIdentifierOrContextual().value,c=new Ie(l);if(o&&(c.varType=o),this.match(x.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();r.push(new gi(c,u))}else r.push(c);this.match(x.COMMA)&&this.advance()}this.expect(x.RPAREN),this.skipNewlines(),this.expect(x.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of r){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new Ie(n);return e&&(a.returnType=e),a.isMethod=!0,new li(a,r,s,e)}parseFunctionBody(){let e=[];if(!this.match(x.INDENT)){let n=this.parseExpression();return new Ot([new ui(n)])}for(this.advance();!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let n=this.parseStatementOrSequence();Array.isArray(n)?e.push(...n):n&&e.push(n)}return this.match(x.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new Ot(e)}_addImplicitReturn(e){let n=e[e.length-1];n.type==="ExpressionStatement"?e[e.length-1]=new ui(n.expression):n.type==="IfStatement"&&this._addImplicitReturnToIf(n)}_addImplicitReturnToIf(e){e.consequent&&e.consequent.type==="BlockStatement"&&e.consequent.body.length>0&&this._addImplicitReturn(e.consequent.body),e.alternate&&(e.alternate.type==="IfStatement"?this._addImplicitReturnToIf(e.alternate):e.alternate.type==="BlockStatement"&&e.alternate.body.length>0&&this._addImplicitReturn(e.alternate.body))}parseStatementOrSequence(){this.pos;let e=this.peek().line;if(this.match(x.KEYWORD,"if")){let r=this.parseIfStatement();return r&&(r._line=e),r}if(this.match(x.KEYWORD,"for"))return this.parseForStatement();if(this.match(x.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(x.KEYWORD,"break")||this.match(x.KEYWORD,"continue")){let r=this.advance().value;return new Qe(new Ie(r))}if(this.match(x.KEYWORD,"var")||this.match(x.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===x.IDENTIFIER&&this.isTypedVarDeclaration()){let r=this.parseTypedVarDeclaration();if(this.match(x.COMMA)&&this.peek(1).type===x.IDENTIFIER){let i=[r];for(;this.match(x.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===x.IDENTIFIER&&this.isTypedVarDeclaration())i.push(this.parseTypedVarDeclaration());else{let s=this.parseExpression();if(this.match(x.OPERATOR)){let a=this.peek().value;if(["=",":="].includes(a)){this.advance(),this.skipNewlines(!0);let o=this.parseExpression();a==="="&&s.type==="Identifier"?i.push(new vt([new pt(s,o)],qt.LET)):i.push(new Qe(new dn(a===":="?"=":a,s,o)))}}break}return i}return r}let n=[];for(;;){let r=this.parseExpression();if(this.match(x.OPERATOR)){let i=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(i)){this.advance(),this.skipNewlines(!0);let s=this.parseExpression();if(i==="="&&r.type==="Identifier"?n.push(new vt([new pt(r,s)],qt.LET)):n.push(new Qe(new dn(i===":="?"=":i,r,s))),this.match(x.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(n.length>0)n.push(new Qe(r));else return new Qe(r);break}}else if(this.match(x.COMMA)){n.push(new Qe(r)),this.advance(),this.skipNewlines();continue}else{if(n.length>0)n.push(new Qe(r));else return new Qe(r);break}}return n.length>1?n:n.length===1?n[0]:null}parseIfStatement(){this.expect(x.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock(),r=null;return this.skipNewlines(),this.match(x.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(x.KEYWORD,"if")?r=this.parseIfStatement():r=this.parseBlock()),new js(e,n,r)}parseForStatement(){this.expect(x.KEYWORD,"for");let e=null,n=!1;if(this.match(x.LBRACKET)){this.advance();let r=[];for(;!this.match(x.RBRACKET);)this.skipNewlines(),r.push(new Ie(this.expectIdentifierOrContextual().value)),this.match(x.COMMA)&&this.advance();this.expect(x.RBRACKET),e=new yi(r),n=!0}else{let r=this.expectIdentifierOrContextual().value;e=new Ie(r)}if(this.match(x.KEYWORD,"in")){this.advance();let r=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new vt([new pt(e,r)],qt.CONST),a=new ci(s,null,null,i);return a.isForIn=!0,a}else{if(n)throw new Error(`Range-based for loops don\'t support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(x.OPERATOR,"=");let r=this.parseExpression();this.expect(x.KEYWORD,"to");let i=this.parseExpression(),s=null;this.match(x.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();let a=this.parseBlock(),o=new vt([new pt(e,r)],qt.LET),l=new wt("<=",r,i),c=new Lt(l,new wt("<=",e,i),new wt(">=",e,i)),u;return s?u=new Lt(l,new dn("+=",e,s),new dn("-=",e,s)):u=new Lt(l,new pi("++",e),new pi("--",e)),new ci(o,c,u,a)}}parseWhileStatement(){this.expect(x.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock();return new Us(e,n)}parseBlock(){if(!this.match(x.INDENT)){let r=this.parseStatement();return new Ot(r?[r]:[])}let e=this.peek().indent;this.advance();let n=[];for(;!this.match(x.EOF);){if(this.skipNewlines(),this.match(x.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(x.EOF))break;let r=this.parseStatement();r&&n.push(r)}return this.match(x.DEDENT)&&this.peek().indent<e&&this.advance(),new Ot(n)}isTupleDestructuring(){if(!this.match(x.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===x.NEWLINE;)e++;if(this.peek(e).type!==x.IDENTIFIER)return!1;for(e++;this.peek(e).type===x.NEWLINE;)e++;if(this.peek(e).type===x.RBRACKET){e++;break}else if(this.peek(e).type===x.COMMA){e++;continue}else return!1}for(;this.peek(e).type===x.NEWLINE;)e++;return this.peek(e).type===x.OPERATOR&&this.peek(e).value==="="}parseTupleDestructuring(){this.expect(x.LBRACKET);let e=[];for(;!this.match(x.RBRACKET);){this.skipNewlines();let r=this.expectIdentifierOrContextual().value;this.functionNames.has(r)&&(r=r+"_var"),e.push(new Ie(r)),this.match(x.COMMA)&&this.advance()}this.expect(x.RBRACKET),this.skipNewlines(),this.expect(x.OPERATOR,"="),this.skipNewlines(!0);let n=this.parseExpression();return new vt([new pt(new yi(e),n)],qt.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.matchEx(x.OPERATOR,"?",!0)){this.advance(),this.skipNewlines(!0);let n=this.parseExpression();this.matchEx(x.COLON,null,!0)?this.advance():this.expect(x.COLON),this.skipNewlines(!0);let r=this.parseExpression();return new Lt(e,n,r)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.matchEx(x.KEYWORD,"or",!0)||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);let n=this.parseLogicalAnd();e=new wt("||",e,n)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.matchEx(x.KEYWORD,"and",!0)||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);let n=this.parseEquality();e=new wt("&&",e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseComparison();e=new wt(n,e,r)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseAdditive();e=new wt(n,e,r)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseMultiplicative();e=new wt(n,e,r)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseUnary();e=new wt(n,e,r)}return e}parseUnary(){if(this.match(x.OPERATOR)){let e=this.peek().value;if(["+","-","!"].includes(e))return this.advance(),this.skipNewlines(),new hi(e,this.parseUnary())}return this.match(x.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new hi("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(x.OPERATOR,"<")){let n=this.pos;this.advance();let r=1,i=!0,s="",a=new Set(["float","int","string","bool","color","line","label","box","linefill","table"]);for(;r>0&&!this.match(x.EOF);)if(this.match(x.OPERATOR,"<"))r++,this.advance();else if(this.match(x.OPERATOR,">"))r--,this.advance();else if(this.match(x.IDENTIFIER)||this.match(x.COMMA)||this.match(x.DOT))r===1&&this.match(x.IDENTIFIER)&&s===""&&(s=this.peek().value),this.advance();else{i=!1,this.pos=n;break}if(i&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&a.has(s)&&(e.property=new Ie("new_"+s)),i&&this.match(x.LPAREN)){e=this.parseCallExpression(e);continue}else{if(i)continue;break}}else if(this.match(x.LPAREN))e=this.parseCallExpression(e);else if(this.match(x.DOT)){this.advance(),this.skipNewlines();let n=this.peek();if(n.type!==x.IDENTIFIER&&n.type!==x.KEYWORD)throw new Error(`Expected property name but got ${n.type} at ${n.line}:${n.column}`);this.advance(),e=new di(e,new Ie(n.value),!1)}else if(this.match(x.LBRACKET)){if(this.isTupleDestructuring())break;this.advance(),this.skipNewlines();let n=this.parseExpression();this.expect(x.RBRACKET),e=new di(e,n,!0)}else break;return e}parseCallExpression(e){this.expect(x.LPAREN);let n=[],r=[];for(;!this.match(x.RPAREN)&&(this.skipNewlines(),!this.match(x.RPAREN));){if((this.peek().type===x.IDENTIFIER||this.peek().type===x.KEYWORD)&&this.peek(1).type===x.OPERATOR&&this.peek(1).value==="="){let i=this.advance().value;this.advance(),this.skipNewlines();let s=this.parseExpression();r.push(new mi(new Ie(i),s))}else n.push(this.parseExpression());this.match(x.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(x.RPAREN),r.length>0&&n.push(new fi(r)),new zs(e,n)}parsePrimary(){let e=this.peek();if(this.match(x.NUMBER)){let n=this.advance();return new Ht(n.value,n.raw)}if(this.match(x.STRING)){let n=this.advance();return new Ht(n.value)}if(this.match(x.BOOLEAN)){let n=this.advance();return new Ht(n.value)}if(this.match(x.IDENTIFIER)||e.type===x.KEYWORD&&Ys.CONTEXTUAL_KEYWORDS.has(e.value)){let n=this.advance().value;return this.functionNames.has(n)&&this.peek().type!==x.LPAREN&&!this.isCurrentFunctionParam(n)&&(n=n+"_var"),new Ie(n)}if(this.match(x.LBRACKET))return this.parseArrayLiteral();if(this.match(x.LPAREN)){this.advance(),this.skipNewlines();let n=this.parseExpression();return this.skipNewlines(),this.expect(x.RPAREN),n}if(this.match(x.KEYWORD,"if"))return this.parseIfExpression();if(this.match(x.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(x.KEYWORD,"for"))return this.parseForExpression();if(this.match(x.KEYWORD,"while"))return this.parseWhileExpression();throw new Error(`Unexpected token ${e.type} \'${e.value}\' at ${e.line}:${e.column}`)}parseArrayLiteral(){this.expect(x.LBRACKET);let e=[];for(;!this.match(x.RBRACKET)&&(this.skipNewlines(),!this.match(x.RBRACKET));)e.push(this.parseExpression()),this.match(x.COMMA)&&this.advance(),this.skipNewlines();return this.expect(x.RBRACKET),new qs(e)}parseIfExpression(){this.expect(x.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines(),this.expect(x.INDENT);let n=[];for(;!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let a=this.parseStatement();a&&n.push(a)}this.advance();let r=[];if(this.match(x.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(x.KEYWORD,"if")){let a=this.parseIfExpression();if(this.needsIIFE(n,r)){let o=new Lt(e,new Ot(n),a);return o.needsIIFE=!0,o.consequentStmts=n,o.alternateExpr=a,o}else return new Lt(e,this.getBlockValue(n),a)}else{for(this.expect(x.INDENT);!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let a=this.parseStatement();a&&r.push(a)}this.advance()}if(this.needsIIFE(n,r)){let a=new Lt(e,new Ot(n),new Ot(r));return a.needsIIFE=!0,a.consequentStmts=n,a.alternateStmts=r,a}let i=this.getBlockValue(n),s=r.length>0?this.getBlockValue(r):new Ht(null);return new Lt(e,i,s)}needsIIFE(e,n){if(e.length>1||n.length>1)return!0;let r=i=>i.some(s=>s.type==="IfStatement"||s.type==="ForStatement"||s.type==="WhileStatement"||s.type==="BlockStatement");return r(e)||r(n)}parseSwitchExpression(){this.expect(x.KEYWORD,"switch");let e=null;!this.match(x.NEWLINE)&&!this.match(x.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(x.INDENT);let n=[];for(;!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let r=null;this.match(x.OPERATOR,"=>")||(r=this.parseExpression()),this.expect(x.OPERATOR,"=>"),this.skipNewlines();let i=[];if(this.match(x.INDENT)){for(this.advance();!this.match(x.DEDENT)&&!this.match(x.EOF)&&(this.skipNewlines(),!this.match(x.DEDENT));){let a=this.parseStatement();a&&i.push(a)}this.advance()}else{this.noLineContinuation=!0;let a=this.parseStatement();this.noLineContinuation=!1,a&&i.push(a)}let s=this.getBlockValue(i);n.push(new Ks(r,s,i)),this.skipNewlines()}return this.advance(),new Hs(e,n)}parseForExpression(){let e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){let e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Ht(null);let n=e[e.length-1];return n.type==="ExpressionStatement"?n.expression:n.type==="VariableDeclaration"&&n.declarations.length>0?n.declarations[0].id:new Ht(null)}};Ln(oc,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));var m1=oc,y1=Object.defineProperty,g1=(t,e,n)=>e in t?y1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zt=(t,e,n)=>g1(t,typeof e!="symbol"?e+"":e,n),x1=new Set(xa),Gs=class{constructor(e={}){zt(this,"indent"),zt(this,"indentStr"),zt(this,"output"),zt(this,"sourceCode"),zt(this,"sourceLines"),zt(this,"lastCommentedLine"),zt(this,"includeSourceComments"),zt(this,"paramRenameCounter"),zt(this,"functionParams"),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`\n`):[],this.lastCommentedLine=-1,this.includeSourceComments=e.includeSourceComments||!1,this.paramRenameCounter=0,this.functionParams=new Map}generate(e){if(this.output=[],this.indent=0,this.lastCommentedLine=-1,this.functionParams=new Map,e.type==="Program")this.preProcessAST(e),this.generateProgram(e);else throw new Error(`Expected Program node, got ${e.type}`);return this.output.join("")}preProcessAST(e){this.collectFunctionParams(e),this.renameConflictingVariables(e)}renameConflictingVariables(e){let n=new Map;this.collectConflictingVarNames(e,n),n.size>0&&this.renameVariableRefsInAST(e,n)}isReservedName(e){return!!e&&(k_.has(e)||Co.has(e))}collectConflictingVarNames(e,n){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(let r of e.declarations)if(r.id?.type==="Identifier"&&this.isReservedName(r.id.name)&&!n.has(r.id.name)&&n.set(r.id.name,`${r.id.name}_$${this.paramRenameCounter++}`),r.id?.type==="ArrayPattern")for(let i of r.id.elements)i?.type==="Identifier"&&this.isReservedName(i.name)&&!n.has(i.name)&&n.set(i.name,`${i.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!n.has(e.left.name)&&n.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&!n.has(e.id.name)&&n.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`);for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.collectConflictingVarNames(s,n);else i&&typeof i=="object"&&i.type&&this.collectConflictingVarNames(i,n)}}}renameVariableRefsInAST(e,n){if(!(!e||typeof e!="object")){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&n.has(e.callee.name)?Co.has(e.callee.name)&&(e.callee.name=n.get(e.callee.name)):this.renameVariableRefsInAST(e.callee,n),e.arguments)for(let r of e.arguments)this.renameVariableRefsInAST(r,n);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&n.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&n.has(e.property.name)){this.renameVariableRefsInAST(e.object,n);return}this.renameVariableRefsInAST(e.object,n),e.computed&&this.renameVariableRefsInAST(e.property,n);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,n);return}if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameVariableRefsInAST(s,n);else i&&typeof i=="object"&&i.type&&this.renameVariableRefsInAST(i,n)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){let n=[];for(let r of e.params)r.type==="Identifier"?n.push(r.name):r.type==="AssignmentPattern"&&r.left?.name&&n.push(r.left.name);this.functionParams.set(e.id.name,n)}if(Array.isArray(e.body))for(let n of e.body)this.collectFunctionParams(n);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,n=null){if(!this.sourceLines.length)return;let r=n||e,i=[];for(let s=e-1;s<r&&s<this.sourceLines.length;s++)if(s>this.lastCommentedLine){let a=this.sourceLines[s].trim();a&&!a.startsWith("//@")&&!a.startsWith("//")&&i.push(this.sourceLines[s])}if(i.length>0){for(let s of i)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(s.trimEnd()),this.write(`\n`);this.lastCommentedLine=Math.max(this.lastCommentedLine,r-1)}}write(e){this.output.push(e)}writeLine(e=""){e?this.output.push(this.indentStr.repeat(this.indent)+e+`\n`):this.output.push(`\n`)}increaseIndent(){this.indent++}decreaseIndent(){this.indent--}generateProgram(e){for(let n=0;n<e.body.length;n++)if(this.generateStatement(e.body[n]),n<e.body.length-1){let r=e.body[n],i=e.body[n+1];(r.type==="FunctionDeclaration"||r.type==="TypeDefinition")&&(i.type==="FunctionDeclaration"||i.type==="TypeDefinition")&&this.writeLine()}}generateStatement(e){switch(this.includeSourceComments&&e._line&&this.sourceLines.length>0&&this.writeSourceComment(e._line),e.type){case"FunctionDeclaration":return this.generateFunctionDeclaration(e);case"VariableDeclaration":return this.generateVariableDeclaration(e);case"ExpressionStatement":return this.generateExpressionStatement(e);case"IfStatement":return this.generateIfStatement(e);case"ForStatement":return this.generateForStatement(e);case"WhileStatement":return this.generateWhileStatement(e);case"ReturnStatement":return this.generateReturnStatement(e);case"BlockStatement":return this.generateBlockStatement(e);case"TypeDefinition":return this.generateTypeDefinition(e);default:throw new Error(`Unknown statement type: ${e.type}`)}}generateTypeDefinition(e){if(this.write(this.indentStr.repeat(this.indent)),this.write(`const ${e.name} = Type({`),e.fields.length>0){this.write(" ");for(let n=0;n<e.fields.length;n++){let r=e.fields[n];r.defaultValue?(this.write(`${r.name}: [\'${r.type}\', `),this.generateExpression(r.defaultValue),this.write("]")):this.write(`${r.name}: \'${r.type}\'`),n<e.fields.length-1&&this.write(", ")}this.write(" ")}this.write(`});\n`)}renameIdentifiersInAST(e,n){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}if(e.type!=="FunctionDeclaration")for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameIdentifiersInAST(s,n);else i&&typeof i=="object"&&i.type&&this.renameIdentifiersInAST(i,n)}}}renameParamRefsInBody(e,n){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&n.has(e.callee.name)||this.renameParamRefsInBody(e.callee,n),e.arguments)for(let r of e.arguments)this.renameParamRefsInBody(r,n);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&n.has(e.object.name))return;this.renameParamRefsInBody(e.object,n),e.computed&&this.renameParamRefsInBody(e.property,n);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,n);return}if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameParamRefsInBody(s,n);else i&&typeof i=="object"&&i.type&&this.renameParamRefsInBody(i,n)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));let n=e.id.isMethod,r=new Map;for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left.name:c.name;if(u&&x1.has(u)){let p=`${u}_$${this.paramRenameCounter++}`;r.set(u,p)}}let i=c=>c.type==="Identifier"&&c.name==="this"||c.type==="AssignmentPattern"&&c.left?.name==="this",s=new Map;if(n&&e.params.length>0&&i(e.params[0])&&s.set("this","self"),r.size>0||s.size>0){for(let c of e.params){let u=c.type==="AssignmentPattern"?c.left:c;if(u?.type==="Identifier"){let 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)}let a=n?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(a),this.write("(");let o=e.params;for(let c=0;c<o.length;c++){let u=o[c];u.type==="Identifier"?this.write(u.name):u.type==="AssignmentPattern"&&(this.write(u.left.name),this.write(" = "),this.generateExpression(u.right)),c<o.length-1&&this.write(", ")}this.write(") "),this.generateBlockStatement(e.body,!1),this.write(`\n`),n&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${a}.__pineMethod__ = true;\n`));let l=[];for(let c=0;c<e.params.length;c++){let u=e.params[c],p=u.type==="AssignmentPattern"?u.left?.name:u.name;if(n&&c===0&&p==="self")continue;let 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));let c=l.map(([u,p])=>`${JSON.stringify(u)}: ${JSON.stringify(p)}`).join(", ");this.write(`${a}.__pineParamTypes__ = {${c}};\n`)}}generateVariableDeclaration(e){let n=e.kind==="var"||e.kind==="varip"?"var":"let";for(let r=0;r<e.declarations.length;r++){let i=e.declarations[r];if(i.init&&i.init.type==="ConditionalExpression"&&i.init.needsIIFE){let o=i.id.type==="Identifier"?i.id.name:null;if(o){this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" "),this.write(o),this.write(`;\n`),this.generateIfStatementWithAssignment(i.init,o);continue}}if(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" "),i.id.type==="Identifier")this.write(i.id.name);else if(i.id.type==="ArrayPattern"){let o=new Set;this.write("[");for(let l=0;l<i.id.elements.length;l++){let c=i.id.elements[l].name;if(o.has(c)){let u=`${c}${this.paramRenameCounter++}`;i.id.elements[l].name=u,c=u}o.add(c),this.write(c),l<i.id.elements.length-1&&this.write(", ")}this.write("]")}i.init&&(this.write(" = "),this.generateExpression(i.init)),this.write(`;\n`);let s=i.id?.varType,a=i.id?.type==="Identifier"?i.id.name:null;a&&typeof s=="string"&&/^[A-Za-z_$][\\w$]*$/.test(s)&&s[0]===s[0].toUpperCase()&&(this.write(this.indentStr.repeat(this.indent)),this.write(`"__pineUdtVar:${a}=${s}";\n`))}}generateExpressionStatement(e){if(e.expression.type==="SwitchExpression"&&e.expression.discriminant===null){this.write(this.indentStr.repeat(this.indent)),this.generateSwitchAsIfElse(e.expression),this.write(`\n`);return}this.write(this.indentStr.repeat(this.indent)),this.generateExpression(e.expression),this.write(`;\n`)}generateIfStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.consequent,!1),e.alternate?(this.write(" else "),e.alternate.type==="IfStatement"?this.generateIfStatement(e.alternate):this.generateBlockStatement(e.alternate,!1)):this.write(`\n`)}generateIfStatementWithAssignment(e,n){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let r=0;r<e.consequentStmts.length;r++){let i=e.consequentStmts[r];r===e.consequentStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternateStmts.length;r++){let i=e.alternateStmts[r];r===e.alternateStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithAssignments(e,n){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let i=e.consequent.body[r];r===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let r=0;r<e.alternate.consequent.body.length;r++){let i=e.alternate.consequent.body[r];r===e.alternate.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate.alternate,n)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternate.body.length;r++){let i=e.alternate.body[r];r===e.alternate.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternatesWithAssignments(e,n){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let i=e.consequent.body[r];r===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate,n)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.body.length;r++){let i=e.body[r];r===e.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){let n=e.init.declarations[0];if(this.write(`${e.init.kind} `),n.id.type==="Identifier")this.write(n.id.name);else if(n.id.type==="ArrayPattern"){let r=new Set;this.write("[");for(let i=0;i<n.id.elements.length;i++){let s=n.id.elements[i].name;if(r.has(s)){let a=`${s}${this.paramRenameCounter++}`;n.id.elements[i].name=a,s=a}r.add(s),this.write(s),i<n.id.elements.length-1&&this.write(", ")}this.write("]")}this.write(" of "),this.generateExpression(n.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){let n=e.init.declarations[0];this.write(`${e.init.kind} ${n.id.name}`),n.init&&(this.write(" = "),this.generateExpression(n.init))}else this.generateExpression(e.init);this.write("; "),e.test&&this.generateExpression(e.test),this.write("; "),e.update&&(e.update.type==="AssignmentExpression"?(this.generateExpression(e.update.left),this.write(` ${e.update.operator} `),this.generateExpression(e.update.right)):this.generateExpression(e.update)),this.write(") "),this.generateBlockStatement(e.body,!1)}generateWhileStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("while ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.body,!1)}generateReturnStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("return"),e.argument&&(this.write(" "),this.generateExpression(e.argument)),this.write(`;\n`)}generateBlockStatement(e,n=!0){this.write(`{\n`),n?this.increaseIndent():this.indent++;for(let r of e.body)this.generateStatement(r);n?this.decreaseIndent():this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n&&this.write(`\n`)}generateExpression(e){switch(e.type){case"Identifier":return this.write(e.name);case"Literal":return this.generateLiteral(e);case"BinaryExpression":case"LogicalExpression":return this.generateBinaryExpression(e);case"UnaryExpression":return this.generateUnaryExpression(e);case"AssignmentExpression":return this.generateAssignmentExpression(e);case"UpdateExpression":return this.generateUpdateExpression(e);case"CallExpression":return this.generateCallExpression(e);case"MemberExpression":return this.generateMemberExpression(e);case"ConditionalExpression":return this.generateConditionalExpression(e);case"ArrayExpression":return this.generateArrayExpression(e);case"ObjectExpression":return this.generateObjectExpression(e);case"SwitchExpression":return this.generateSwitchExpression(e);case"SequenceExpression":return this.generateSequenceExpression(e);case"ForStatement":return this.generateLoopAsExpression(e,"for");case"WhileStatement":return this.generateLoopAsExpression(e,"while");default:throw new Error(`Unknown expression type: ${e.type}`)}}generateLiteral(e){if(typeof e.value=="string"){let n=e.value.replace(/\\\\/g,"\\\\\\\\").replace(/\'/g,"\\\\\'").replace(/\\n/g,"\\\\n").replace(/\\r/g,"\\\\r").replace(/\\t/g,"\\\\t");this.write(`\'${n}\'`)}else if(e.value===null)this.write("null");else{let n=String(e.value);typeof e.raw=="string"&&e.raw.includes(".")&&!/[.eE]/.test(n)?this.write(n+".0"):this.write(n)}}generateBinaryExpression(e){let n=this.getPrecedence(e);this.getPrecedence(e.left)<n?(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(" ");let i=this.getPrecedence(e.right),s=i<n;i===n&&(r==="-"||r==="/"||r==="%")&&(s=!0),s?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let n=e.operator;n==="not"&&(n="!"),this.write(n),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(n==="-"||n==="+")&&(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 n=e.operator;n===":="&&(n="="),this.write(n),this.write(" "),this.generateExpression(e.right)}generateUpdateExpression(e){e.prefix?(this.write(e.operator),this.generateExpression(e.argument)):(this.generateExpression(e.argument),this.write(e.operator))}generateCallExpression(e){this.getPrecedence(e.callee)<19?(this.write("("),this.generateExpression(e.callee),this.write(")")):this.generateExpression(e.callee),this.write("(");let n=e.callee?.type==="Identifier"?e.callee.name:null,r=n?this.functionParams.get(n):null,i=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(i?.type==="ObjectExpression"&&r){let s=e.arguments.slice(0,-1),a=new Map;for(let u of i.properties){let p=u.key?.name||u.key?.value;p&&a.set(p,u.value)}let o=[],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);let c=o.slice(0,l+1);for(let u=0;u<c.length;u++)c[u]===null?this.write("undefined"):this.generateExpression(c[u]),u<c.length-1&&this.write(", ")}else for(let s=0;s<e.arguments.length;s++){let a=e.arguments[s];a.type==="AssignmentExpression"&&a.operator==="="?this.generateExpression(a.right):this.generateExpression(a),s<e.arguments.length-1&&this.write(", ")}this.write(")")}generateMemberExpression(e){this.getPrecedence(e.object)<19?(this.write("("),this.generateExpression(e.object),this.write(")")):this.generateExpression(e.object),e.computed?(this.write("["),this.generateExpression(e.property),this.write("]")):(this.write("."),this.generateExpression(e.property))}generateConditionalExpression(e){if(e.needsIIFE){this.generateIIFEConditional(e);return}this.write("("),this.generateExpression(e.test),this.write(" ? "),this.generateExpression(e.consequent),this.write(" : "),this.generateExpression(e.alternate),this.write(")")}generateIIFEConditional(e){this.write(`(() => {\n`),this.indent++,this.generateIIFEIfBlock(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateIIFEIfBlock(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let n=0;n<e.consequentStmts.length;n++){let r=e.consequentStmts[n];n===e.consequentStmts.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):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 {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternateStmts.length;n++){let r=e.alternateStmts[n];n===e.alternateStmts.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithReturns(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let r=e.consequent.body[n];n===e.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):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.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let n=0;n<e.alternate.consequent.body.length;n++){let r=e.alternate.consequent.body[n];n===e.alternate.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate.alternate)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternate.body.length;n++){let r=e.alternate.body[n];n===e.alternate.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternates(e){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let r=e.consequent.body[n];n===e.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.body.length;n++){let r=e.body[n];n===e.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateNestedIfAsExpression(e){if(e.type==="IfStatement"){if(this.write("("),this.generateExpression(e.test),this.write(" ? "),e.consequent.type==="BlockStatement"&&e.consequent.body.length>0){let n=e.consequent.body[e.consequent.body.length-1];n.type==="ExpressionStatement"?this.generateExpression(n.expression):n.type==="IfStatement"&&this.generateNestedIfAsExpression(n)}if(this.write(" : "),e.alternate)if(e.alternate.type==="IfStatement")this.generateNestedIfAsExpression(e.alternate);else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){let n=e.alternate.body[e.alternate.body.length-1];n.type==="ExpressionStatement"&&this.generateExpression(n.expression)}else this.write("false");else this.write("false");this.write(")")}}generateArrayExpression(e){this.write("[");for(let n=0;n<e.elements.length;n++)this.generateExpression(e.elements[n]),n<e.elements.length-1&&this.write(", ");this.write("]")}generateObjectExpression(e){this.write("{");for(let n=0;n<e.properties.length;n++){let r=e.properties[n];r.key.type==="Identifier"?this.write(r.key.name):this.generateExpression(r.key),this.write(": "),this.generateExpression(r.value),n<e.properties.length-1&&this.write(", ")}this.write("}")}generateSwitchExpression(e){if(e.discriminant===null){this.generateSwitchAsIfElseIIFE(e);return}this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("switch ("),this.generateExpression(e.discriminant),this.write(`) {\n`),this.indent++;for(let n of e.cases){if(this.write(this.indentStr.repeat(this.indent)),n.test?(this.write("case "),this.generateExpression(n.test),this.write(`:\n`)):this.write(`default:\n`),this.indent++,n.statements&&n.statements.length>0){let r=n.statements[n.statements.length-1];if(r.type==="ExpressionStatement"||r.type==="VariableDeclaration"){for(let i=0;i<n.statements.length-1;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),r.type==="ExpressionStatement"?this.generateExpression(r.expression):this.generateExpression(n.consequent),this.write(`;\n`)}else{for(let i=0;i<n.statements.length;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElseIIFE(e){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent));for(let n=0;n<e.cases.length;n++){let r=e.cases[n];if(r.test?(n===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {\n`)):n>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,r.statements&&r.statements.length>0){let i=r.statements[r.statements.length-1];if(i.type==="ExpressionStatement"||i.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 "),i.type==="ExpressionStatement"?this.generateExpression(i.expression):this.generateExpression(r.consequent),this.write(`;\n`)}else{for(let 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;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n>=e.cases.length-1&&this.write(`\n`)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElse(e){for(let n=0;n<e.cases.length;n++){let r=e.cases[n];if(r.test?(n===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {\n`)):n>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,r.statements&&r.statements.length>0)for(let i of r.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(i);else this.write(this.indentStr.repeat(this.indent)),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n<e.cases.length-1||this.write(`\n`)}}generateLoopAsExpression(e,n){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`let __result;\n`);let r=e.body;if(r&&r.body&&r.body.length>0){let i=r.body.length-1,s=r.body[i];s.type==="ExpressionStatement"&&(r.body[i]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:s.expression},_line:s._line})}n==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let n=0;n<e.expressions.length;n++)this.generateExpression(e.expressions[n]),n<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 lc(t){let e=/^\\s*\\/\\/\\s*@version\\s*=\\s*(\\d+)\\s*$/im,n=t.match(e);return n&&n[1]?parseInt(n[1],10):null}function ba(t,e={}){let n=lc(t);if(n===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(n<5)return{success:!1,version:n,error:`Pine Script version ${n} is not supported. Only version 5 and above are supported.`};try{let r=new Vs(t).tokenize(),i=new m1(r).parse(),s={...e,sourceCode:t},a=new Gs(s).generate(i);return{success:!0,version:n,code:a,ast:i,tokens:r}}catch(r){return{success:!1,version:n,error:r.message,stack:r.stack}}}var _1=new Set(["security_lower_tf","security"]),cc=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function b1(t){if(!t||t.type!=="CallExpression")return!1;let e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:_1.has(e.property.name)}function v1(t){let e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function w1(t){let e=[],n=new WeakSet;function r(i,s){if(!i||typeof i!="object"||n.has(i))return;n.add(i);let a=s.concat([i]);b1(i)&&e.push({call:i,path:a});for(let o of Object.keys(i)){if(cc.has(o))continue;let l=i[o];if(Array.isArray(l))for(let c of l)r(c,a);else l&&typeof l=="object"&&r(l,a)}}return r(t,[]),e}function Xs(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function Ft(t,e,n){if(n>=e.length-1)return t;let r=e[n+1];switch(t.type){case"BlockStatement":{let i=t.body.indexOf(r);if(i<0)return t;let s=t.body.slice(0,i);return s.push(Ft(r,e,n+1)),{...t,body:s}}case"IfStatement":return r===t.test?{...t,test:Ft(r,e,n+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:Ft(r,e,n+1),alternate:null}:r===t.alternate?{...t,alternate:Ft(r,e,n+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:Ft(r,e,n+1)}:t;case"SwitchStatement":{let i=t.cases.indexOf(r);if(i>=0){let s=t.cases.slice(0,i);return s.push(Ft(r,e,n+1)),{...t,cases:s}}return t}case"SwitchCase":{let i=t.consequent.indexOf(r);if(i>=0){let s=t.consequent.slice(0,i);return s.push(Ft(r,e,n+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:Ft(r,e,n+1)}:t;default:return t}}function S1(t){if(!t||t.type!=="CallExpression")return null;let e=t.callee;if(!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="$"||e.property?.type!=="Identifier"||e.property.name!=="call")return null;let n=t.arguments?.[0];return n?.type==="Identifier"&&typeof n.name=="string"?n.name:null}function E1(t,e,n){let r=t.body||[];for(let i=0;i<r.length;i++){let s=r[i];if(s!==n&&C1(s,e))return i}return-1}function C1(t,e){let n=!1,r=new WeakSet;function i(s){if(!(n||!s||typeof s!="object")&&!r.has(s)){if(r.add(s),S1(s)===e){n=!0;return}for(let a of Object.keys(s)){if(cc.has(a))continue;let o=s[a];if(Array.isArray(o))for(let l of o)i(l);else o&&typeof o=="object"&&i(o)}}}return i(t),n}function I1(t,e){let n=-1;for(let h=1;h<e.length;h++)if(Xs(e[h])){n=h;break}if(n<0)return null;let r=e[n];for(let h=n+1;h<e.length;h++)if(Xs(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;let i=r.id.name,s=e.slice(n),a=Ft(r,s,0),o=E1(t,i,r);if(o<0)return null;let l=t.body||[],c=l.indexOf(r);if(c<0)return null;let u=[],p=Math.max(o,c);for(let h=0;h<=p;h++){let d=l[h];u.push(d===r?a:d)}return u}function N1(t,e){let n={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},r=`var _r = ${ya(n)}\n; return _r;`;return new Function("",r)()}function k1(t){let e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;let n=t.body[0],r=null;if(n.type==="ExpressionStatement"){let s=n.expression;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&(r=s)}else n.type==="FunctionDeclaration"&&(r=n);if(!r||r.body?.type!=="BlockStatement")return e;let i=w1(r.body);for(let{call:s,path:a}of i){let o=v1(s);if(!o||o in e)continue;let l=a.some(p=>Xs(p)),c=null;if(l)c=I1(r.body,a);else{let p=Ft(r.body,a,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;let u=N1(r,c);e[o]=u}return e}function A1(t){if(typeof t=="function")return{code:t.toString(),version:null};{let e=lc(t);if(e===null)return{code:t,version:null};if(e>=5){let n=ba(t);if(n.success)return{code:n.code,version:e};throw new Error(`Failed to transpile Pine Script version ${e}: ${n.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function M1(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:n}=e,{code:r,version:i}=A1(t),s=r;s=R_(s);let a=n?s.split(`\n`):[],o=fa(s,{ecmaVersion:"latest",sourceType:"module",locations:n});O_(o),T_(o),M_(o);let l=new Ds;B_(o,l),L_(o,l);let c=W_(o,l)||"";if(i!==null&&i<6&&G_(o),a1(o,l,c,e,a),s1(o),t1(o),o.type==="Program"&&o.body.length>0){let m=o.body[0],_=m?.expression||m;_.body?.type==="BlockStatement"&&_.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}let u=__||ma||void 0,p=Object.assign({},u,{LineComment(m,_){_.write("//"+m.value)}}),h=ya(o,{generator:p,comments:n}),d=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:k1(o),f=new Function("",`var _r = ${h}\n; return _r;`)(this);return d&&Object.keys(d).length>0&&(f._ltfSlices=d),f}var Io={"":["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"]},T1={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 P1(t){if(typeof t!="string")return[];let e=ba(t);if(!e.success||!e.ast)return[];let n=D1(e.ast),r=R1(e.ast),i=[],s=new Set;return Kt(e.ast,a=>{let o=O1(a,n,r);if(o){if(o.varId!==void 0){if(s.has(o.varId)){console.warn(`[Indicator] duplicate input variable "${o.varId}" \\u2014 first declaration wins for .input access`);return}s.add(o.varId)}i.push(o)}}),i}function D1(t){let e=new Map;return Kt(t,n=>{if(n.type==="VariableDeclaration")for(let r of n.declarations??[]){let i=r?.id?.name,s=r?.init;if(!i||!s||s.type!=="ObjectExpression"||!(s.properties??[]).every(a=>a.value?.type==="Literal"&&typeof a.value.value=="string")||s.properties.length===0)return;for(let a of s.properties)e.set(`${i}.${a.key.name}`,a.value.value)}}),e}function R1(t){let e=new Map;return Kt(t,n=>{if(n.type==="VariableDeclaration")for(let r of n.declarations??[])r?.id?.type==="Identifier"&&r.init&&!e.has(r.id.name)&&e.set(r.id.name,r.init)}),e}function O1(t,e,n){if(t.type!=="VariableDeclaration")return null;for(let r of t.declarations??[]){let i=r?.init;if(!i||i.type!=="CallExpression")continue;let s=i.callee,a=null;if(s?.type==="MemberExpression"&&s.object?.type==="Identifier"&&s.object.name==="input"&&s.property?.type==="Identifier"?a=s.property.name:s?.type==="Identifier"&&s.name==="input"&&(a=""),a===null||a!==""&&!(a==="int"||a==="float")&&!(a in Io))continue;let o=i.arguments??[],l=o[o.length-1],c=l?.type==="ObjectExpression",u=c?o.slice(0,-1):o.slice(),p=c?l.properties??[]:[],h={};a==="int"||a==="float"?L1(u,p,h):uc(Io[a],u,h);for(let _ of p)_.type!=="Property"||!_.key?.name||(h[_.key.name]=_.value);let d={};for(let _ of Object.keys(h))d[_]=jr(h[_],e,n);let f=a===""?F1(d.defval):T1[a];if(!f)continue;let m={type:f,defval:d.defval};return r.id?.type==="Identifier"&&typeof r.id.name=="string"&&(m.varId=r.id.name),d.title!==void 0&&(m.title=String(d.title)),d.tooltip!==void 0&&(m.tooltip=String(d.tooltip)),d.group!==void 0&&(m.group=String(d.group)),d.inline!==void 0&&(m.inline=String(d.inline)),d.confirm!==void 0&&(m.confirm=!!d.confirm),d.active!==void 0&&(m.active=!!d.active),d.display!==void 0&&(m.display=B1(d.display)),d.options!==void 0&&Array.isArray(d.options)&&(m.options=d.options),typeof d.minval=="number"&&(m.minval=d.minval),typeof d.maxval=="number"&&(m.maxval=d.maxval),typeof d.step=="number"&&(m.step=d.step),m}return null}function L1(t,e,n){let r=new Set(e.map(i=>i.key?.name).filter(Boolean)).has("options")||t[2]?.type==="ArrayExpression"?["defval","title","options","tooltip","inline","group","confirm","display","active"]:["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display","active"];uc(r,t,n)}function uc(t,e,n){for(let r=0;r<e.length&&r<t.length;r++){let i=t[r];n[i]===void 0&&(n[i]=e[r])}}function jr(t,e,n,r=new Set){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":if(ra.has(t.name))return t.name;if(n?.has(t.name)&&!r.has(t.name)){r.add(t.name);let i=jr(n.get(t.name),e,n,r);if(r.delete(t.name),i!==void 0)return i}return t.name;case"MemberExpression":{let i=t.object?.type==="Identifier"?t.object.name:null,s=t.property?.type==="Identifier"?t.property.name:null;if(i&&s){let a=`${i}.${s}`;return e.has(a)?e.get(a):i==="display"?s:a}return}case"CallExpression":{let i=t.callee;if(i?.type==="MemberExpression"&&i.object?.type==="Identifier"&&i.object.name==="color"&&i.property?.type==="Identifier"){let s=i.property.name,a=(t.arguments??[]).map(l=>jr(l,e,n,r)),o=l=>Math.max(0,Math.min(1,l));if(s==="rgb"){let[l,c,u,p]=a;if(typeof l=="number"&&typeof c=="number"&&typeof u=="number"){let h=o(1-(typeof p=="number"?p:0)/100);return us(l,c,u,h)}}else if(s==="new"){let l=al(a[0]),c=a[1];if(l&&typeof c=="number")return us(l[0],l[1],l[2],o(1-c/100))}}return}case"ArrayExpression":return(t.elements??[]).map(i=>jr(i,e,n,r));case"UnaryExpression":return t.operator==="-"&&t.argument?.type==="Literal"&&typeof t.argument.value=="number"?-t.argument.value:void 0;default:return}}function F1(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?ra.has(t)?"source":t.startsWith("#")?"color":"string":null}function B1(t){if(typeof t!="string")return;let e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function Kt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(let n of t.body)Kt(n,e);else t.body&&Kt(t.body,e);if(Array.isArray(t.consequent))for(let n of t.consequent)Kt(n,e);else t.consequent&&Kt(t.consequent,e);if(t.alternate&&Kt(t.alternate,e),Array.isArray(t.declarations))for(let n of t.declarations)Kt(n,e)}}function hc(t,e,n,r,i="key"){let s={},a=new Map;for(let o of t)a.set(o.key,o),s[o.key]=r&&o.key in r?r[o.key]:o.defval;for(let o of t)for(let l of o.aliases??[])!l||a.has(l)||a.set(l,o);return{proxy:new Proxy(s,{get(o,l){if(typeof l=="symbol")return o[l];let c=a.get(l);return c?o[c.key]:o[l]},set(o,l,c){if(typeof l!="string")return!1;let u=a.get(l);if(!u)throw new Error(`[${e}] unknown ${i} "${l}". Known: ${[...a.keys()].join(", ")||"(none)"}`);return V1(u,c,e),o[u.key]=c,n?.(u.key),!0},deleteProperty(o,l){throw new Error(`[${e}] cannot delete "${String(l)}" \\u2014 keys are fixed by the script\'s source.`)},defineProperty(){throw new Error(`[${e}] cannot define new properties \\u2014 keys are fixed by the script\'s source.`)},ownKeys(o){return Reflect.ownKeys(o)},getOwnPropertyDescriptor(o,l){return Reflect.getOwnPropertyDescriptor(o,l)},has(o,l){return typeof l=="string"&&a.has(l)}}),values:s,entryByKey:a}}function V1(t,e,n){let r=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${n}] "${r}" expects an int; got ${On(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${n}] "${r}" expects a number; got ${On(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${n}] "${r}" expects a boolean; got ${On(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(`[${n}] "${r}" expects a string; got ${On(e)}`);break}if(t.options&&!t.options.some(i=>W1(i,e)))throw new RangeError(`[${n}] "${r}" value ${On(e)} is not one of: ${t.options.map(On).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${n}] "${r}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${n}] "${r}" value ${e} is above maxval ${t.maxval}`)}}function W1(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function On(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function $1(t,e){let n=new Map,r=[];for(let a of t){let o=a.varId??a.title;if(!o)continue;let l=a.title&&a.title!==o?[a.title]:void 0;n.set(o,a),r.push({key:o,type:a.type,defval:a.defval,options:a.options,minval:a.minval,maxval:a.maxval,aliases:l})}let{proxy:i,values:s}=hc(r,"Indicator.input",e,void 0,"input key");return{proxy:i,values:s,metaByKey:n}}var pc=[{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}],dc=[...pc.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"}],fc=[...pc.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 j1(t){return t==="strategy"?fc:dc}function U1(t){return typeof t=="string"?z1(t):typeof t=="function"?q1(t):{type:null,args:{}}}function z1(t){let e=ba(t);if(!e.success||!e.ast)return{type:null,args:{}};let n=null;return xi(e.ast,r=>{if(n||r.type!=="ExpressionStatement"&&r.type!=="VariableDeclaration")return;let i=r.type==="ExpressionStatement"?r.expression:r.declarations?.[0]?.init;if(!i||i.type!=="CallExpression")return;let s=i.callee;s?.type==="Identifier"&&(s.name!=="indicator"&&s.name!=="strategy"||(n={type:s.name,args:yc(i.arguments??[],mc(s.name))}))}),n??{type:null,args:{}}}function q1(t){let e;try{e=fa(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let n=null;return xi(e,r=>{if(n||r.type!=="CallExpression")return;let i=r.callee;i?.type==="Identifier"&&(i.name!=="indicator"&&i.name!=="strategy"||(n={type:i.name,args:yc(r.arguments??[],mc(i.name))}))}),n??{type:null,args:{}}}function mc(t){return t==="strategy"?fc:dc}function yc(t,e){let n={},r=t[t.length-1],i=r?.type==="ObjectExpression",s=i?t.slice(0,-1):t.slice();for(let a=0;a<s.length&&a<e.length;a++){let o=e[a].name;n[o]=Zs(s[a])}if(i)for(let a of r.properties??[])a.type!=="Property"||!a.key?.name||(n[a.key.name]=Zs(a.value));return n}function Zs(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(Zs);default:return}}function xi(t,e){if(!(!t||typeof t!="object")){e(t);for(let n of Object.keys(t)){let r=t[n];if(!(n==="loc"||n==="range"||n==="start"||n==="end"))if(Array.isArray(r))for(let i of r)xi(i,e);else r&&typeof r=="object"&&typeof r.type=="string"&&xi(r,e)}}}function H1(t,e,n){let r=new Map,i=[];for(let o of t)r.set(o.name,o),o.mutable&&i.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});let{proxy:s,values:a}=hc(i,"Indicator.prop",n,e);return{proxy:s,values:a,propByName:r}}var K1=Object.defineProperty,Y1=(t,e,n)=>e in t?K1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,it=(t,e,n)=>Y1(t,typeof e!="symbol"?e+"":e,n),yn=class t{constructor(e,n={}){it(this,"source"),it(this,"inputs"),it(this,"_prepared",null),it(this,"_inputMeta",null),it(this,"_inputValues",{}),it(this,"_explicitOverrides",new Set),it(this,"_inputProxy",null),it(this,"_propMeta",null),it(this,"_propValues",{}),it(this,"_propProxy",null),it(this,"_declarationType",null),it(this,"_sourcePropArgs",{}),it(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=n,Object.defineProperty(this,"input",{get:()=>this._getInputProxy(),set:()=>{throw new Error(\'[Indicator] .input cannot be replaced \\u2014 mutate individual keys (e.g. ind.input["My Title"] = 20).\')},enumerable:!0,configurable:!1}),Object.defineProperty(this,"prop",{get:()=>this._getPropProxy(),set:()=>{throw new Error(\'[Indicator] .prop cannot be replaced \\u2014 mutate individual keys (e.g. ind.prop["initial_capital"] = 50000).\')},enumerable:!0,configurable:!1})}static from(e){return e instanceof t?e:new t(e)}prepare(e={}){if(this._prepared)return this._prepared;let n=M1(this.source,{debug:!!e.debug,ln:e.ln}),r=G1(n),i=n._ltfSlices;return this._prepared={fn:n,inputs:this.getRuntimeInputs(),usesVisibleRange:r,ltfSlices:i},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){let e={...this.inputs??{}};if(this._inputMeta)for(let n of this._explicitOverrides)e[n]=this._inputValues[n];return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){let e={};if(this._propMeta)for(let n of this._explicitPropOverrides)e[n]=this._propValues[n];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=P1(this.source);for(let n of this._inputMeta)n.type==="color"&&n.defval!==void 0&&(n.defval=Hd(n.defval));let e=$1(this._inputMeta,n=>this._explicitOverrides.add(n));this._inputValues=e.values,this._inputProxy=e.proxy}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;let e=U1(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=j1(e.type);let n=H1(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=n.values,this._propProxy=n.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function G1(t){let e=t.toString();return I_.some(n=>{let r=n.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${r}\\\\b`).test(e)})}var X1=Object.defineProperty,Z1=(t,e,n)=>e in t?X1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pe=(t,e,n)=>Z1(t,typeof e!="symbol"?e+"":e,n),No={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 Q1(t){return t?No[t]??No[t.toUpperCase()]??864e5:864e5}var on=class{constructor(e,n,r,i,s,a){this.source=e,this.tickerId=n,this.timeframe=r,this.limit=i,this.sDate=s,this.eDate=a,pe(this,"data",[]),pe(this,"open",[]),pe(this,"high",[]),pe(this,"low",[]),pe(this,"close",[]),pe(this,"volume",[]),pe(this,"hl2",[]),pe(this,"hlc3",[]),pe(this,"ohlc4",[]),pe(this,"hlcc4",[]),pe(this,"openTime",[]),pe(this,"closeTime",[]),pe(this,"_readyPromise",null),pe(this,"_ready",!1),pe(this,"_debugSettings",{ln:!1,debug:!1}),pe(this,"_transpiledCode",null),pe(this,"_currentIndicator",null),pe(this,"_isSecondaryContext",!1),pe(this,"_syminfo"),pe(this,"_chartTimezone",null),pe(this,"_maxLoops",5e5),pe(this,"_alertMode","realtime"),pe(this,"_viewportLeft"),pe(this,"_viewportRight"),pe(this,"_usesVisibleRange",!1),pe(this,"_lastRunViewport",{}),pe(this,"_lastResult",null),pe(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,n,r,i,s,a).then(l=>{let c=l;this.data=c;let u=c.map(E=>E.open),p=c.map(E=>E.close),h=c.map(E=>E.high),d=c.map(E=>E.low),f=c.map(E=>E.volume),m=c.map(E=>(E.high+E.low+E.close)/3),_=c.map(E=>(E.high+E.low)/2),b=c.map(E=>(E.high+E.low+E.open+E.close)/4),v=c.map(E=>(E.high+E.low+E.close+E.close)/4),S=c.map(E=>E.openTime),w=Q1(this.timeframe),I=c.map(E=>E.closeTime!=null?E.closeTime:E.openTime+w);this.open=u,this.close=p,this.high=h,this.low=d,this.volume=f,this.hl2=_,this.hlc3=m,this.ohlc4=b,this.hlcc4=v,this.openTime=S,this.closeTime=I,e&&e.getSymbolInfo?e.getSymbolInfo(n).then(E=>{this._syminfo=E,this._ready=!0,o(!0)}).catch(E=>{console.warn("Failed to get symbol info, using default values:",E),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,n){this._viewportLeft=e,this._viewportRight=n}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){let n=e??this._lastPineTSCode;if(!n)throw new Error("pine.update(): pineTSCode is required on the first call.");let r=this._lastResult===null,i=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return r||this._usesVisibleRange&&i?(this._lastPineTSCode=n,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(n),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:n}){this._debugSettings.ln=e,this._debugSettings.debug=n}async loadMarketData(e,n,r,i,s,a){return Array.isArray(e)?e:e.getMarketData(n,r,i,s,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,n,r){let i=yn.from(e);if(this._currentIndicator=i,r&&r>0){let s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(i,n,r,s)}else return this._runComplete(i,n)}stream(e,n={}){let{live:r=!0,interval:i=1e3}=n,s=n.pageSize||this.data.length,a=yn.from(e);this._currentIndicator=a;let o={data:[],error:[],warning:[],alert:[]},l=!1,c=(h,...d)=>{o[h]&&o[h].forEach(f=>f(...d))},u=(h,d)=>{o[h]||(o[h]=[]),o[h].push(d)},p=()=>{l=!0};return(async()=>{try{r&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));let h=!Array.isArray(this.source)&&r,d=this._runPaginated(a,void 0,s,h);for await(let f of d){if(l)break;if(f===null){await new Promise(m=>setTimeout(m,i));continue}if(c("data",f),f.warnings&&f.warnings.length>0){for(let m of f.warnings)c("warning",m);f.warnings.length=0}if(f.alerts&&f.alerts.length>0){for(let m of f.alerts)c("alert",m);f.alerts.length=0}if(h&&!l){let m=f.marketData[f.idx],_=m&&m.closeTime<Date.now(),b=f.idx>=f.marketData.length-1;(!_||b)&&await new Promise(v=>setTimeout(v,i))}}}catch(h){c("error",h)}})(),{on:u,stop:p}}async runPretranspiled(e,n={},r){await this.ready(),r||(r=this.data.length);let i=this._initializeContext(null,n,this._isSecondaryContext);this._transpiledCode=e;let s=e._ltfSlices;return s&&(i._ltfTruncatedBodies=s),await this._executeIterations(i,e,this.data.length-r,this.data.length),i}async _runComplete(e,n){await this.ready(),n||(n=this.data.length);let r=e.prepare(this._debugSettings);this._usesVisibleRange=r.usesVisibleRange;let i=this._initializeContext(e.source??null,r.inputs,this._isSecondaryContext);this._transpiledCode=r.fn,r.ltfSlices&&(i._ltfTruncatedBodies=r.ltfSlices);let s=this.data.length-n,a=this.data.length;return a-s>1?(await this._executeIterations(i,r.fn,s,a-1),i._varSnapshot=this._snapshotVarState(i),await this._executeIterations(i,r.fn,a-1,a)):await this._executeIterations(i,r.fn,s,a),i}async*_runPaginated(e,n,r,i=!1){await this.ready(),n||(n=this.data.length);let s=e.prepare(this._debugSettings);this._usesVisibleRange=s.usesVisibleRange;let a=this._initializeContext(e.source??null,s.inputs,this._isSecondaryContext);this._transpiledCode=s.fn,s.ltfSlices&&(a._ltfTruncatedBodies=s.ltfSlices);let o=this.data.length-n,l=null;for(;;){let c=this.data.length,u=c-o;if(u>0){let m=Math.min(u,r),_=this._getResultLength(a.result),b=o+m;i&&b>=c&&m>1?(await this._executeIterations(a,this._transpiledCode,o,b-1),l=this._snapshotVarState(a),await this._executeIterations(a,this._transpiledCode,b-1,b)):i&&b>=c&&m===1?await this._executeIterations(a,this._transpiledCode,o,b):await this._executeIterations(a,this._transpiledCode,o,b),o+=m,yield this._createPageContext(a,_);continue}if(!i||Array.isArray(this.source))break;let p=Date.now(),{newCandles:h,updatedLastCandle:d}=await this._updateMarketData(),f=Date.now()-p;if(h===0&&!d){yield null;continue}if(h===0&&d&&f<1e3&&await new Promise(m=>setTimeout(m,1e3-f)),a.dataVersion++,a.length=this.data.length,this._restoreVarState(a,l),Array.isArray(a.result))a.result.pop();else if(typeof a.result=="object"&&a.result!==null)for(let m in a.result)Array.isArray(a.result[m])&&a.result[m].pop();a.data.close.data.pop(),a.data.open.data.pop(),a.data.high.data.pop(),a.data.low.data.pop(),a.data.volume.data.pop(),a.data.hl2.data.pop(),a.data.hlc3.data.pop(),a.data.ohlc4.data.pop(),a.data.hlcc4.data.pop(),a.data.openTime.data.pop(),a.data.closeTime&&a.data.closeTime.data.pop(),a.data.bar_index.data.pop(),o=this.data.length-(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){let n=Object.keys(e);if(n.length>0&&Array.isArray(e[n[0]]))return e[n[0]].length}return 0}_createPageContext(e,n){let r=new $n({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(n);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let i in e.result)Array.isArray(e.result[i])?r.result[i]=e.result[i].slice(n):r.result[i]=e.result[i]}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};let n=this.source,r=this.data.length-1,i=this.data[r].openTime;try{let s=await n.getMarketData(this.tickerId,this.timeframe,void 0,i,e);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let l=0;l<s.length;l++){let c=s[l];c.openTime===i?(this._replaceCandle(r,c),a=!0):c.openTime>i&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,n){this.data[e]=n,this.open[e]=n.open,this.close[e]=n.close,this.high[e]=n.high,this.low[e]=n.low,this.volume[e]=n.volume,this.hl2[e]=(n.high+n.low)/2,this.hlc3[e]=(n.high+n.low+n.close)/3,this.ohlc4[e]=(n.high+n.low+n.open+n.close)/4,this.hlcc4[e]=(n.high+n.low+n.close+n.close)/4,this.openTime[e]=n.openTime,this.closeTime[e]=n.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;let{newCandles:n,updatedLastCandle:r}=await this._updateMarketData();if(n===0&&!r)return!1;let i=e._varSnapshot;if(i?this._restoreVarState(e,i):this._removeLastResult(e),Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let o in e.result)Array.isArray(e.result[o])&&e.result[o].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop(),e.dataVersion=(e.dataVersion||0)+1,e.length=this.data.length;let s=this.data.length-(n+1);e.rollbackDrawings(s);let a=this.data.length;return s<a-1?(await this._executeIterations(e,this._transpiledCode,s,a-1),e._varSnapshot=this._snapshotVarState(e),await this._executeIterations(e,this._transpiledCode,a-1,a)):await this._executeIterations(e,this._transpiledCode,s,a),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let i in e.result)Array.isArray(e.result[i])&&e.result[i].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();let n=["const","var","let","params"],r=i=>{for(let s of n)if(i[s])for(let a in i[s]){let o=i[s][a];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(i=>r(i))}_snapshotVarState(e){let n=["const","var","let","params"],r={main:{},lctx:[]},i=s=>{let a={};for(let o of n)if(s[o]){a[o]={};for(let l in s[o]){let c=s[o][l];if(c instanceof y){let u=c.data.length,p=u>0?c.data[u-1]:void 0;a[o][l]={len:u,lastVal:p}}}}return a};if(r.main=i(e),e.lctx){let s=[];e.lctx.forEach(a=>s.push(i(a))),r.lctx=s}return r.strategy=Xy(e.strategy),r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,n){if(!n)return;let r=["const","var","let","params"],i=(s,a)=>{for(let o of r)if(!(!a[o]||!s[o]))for(let l in a[o]){let c=s[o][l],u=a[o][l];c instanceof y&&u&&typeof u.len=="number"&&(c.data.length>u.len&&(c.data.length=u.len),u.len>0&&u.lastVal!==void 0&&(c.data[u.len-1]=u.lastVal))}};if(i(e,n.main),e.lctx&&n.lctx){let s=0;e.lctx.forEach(a=>{n.lctx[s]&&i(a,n.lctx[s]),s++})}Zy(e.strategy,n.strategy)}_initializeContext(e,n={},r=!1){let i=new $n({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:n});i.pine.syminfo=this._syminfo;let s=dr(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo={...this._syminfo,tickerid:fs(String(this._syminfo.tickerid??this.tickerId),"heikinashi")}),this._chartTimezone&&(i.chartTimezone=this._chartTimezone),i.viewportLeft=this._viewportLeft,i.viewportRight=this._viewportRight,i.__maxLoops=this._maxLoops,i._alertMode=this._alertMode,i._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},i.pineTSCode=e,i.isSecondaryContext=r,i.data.close=new y([]),i.data.open=new y([]),i.data.high=new y([]),i.data.low=new y([]),i.data.volume=new y([]),i.data.hl2=new y([]),i.data.hlc3=new y([]),i.data.ohlc4=new y([]),i.data.hlcc4=new y([]),i.data.openTime=new y([]),i.data.closeTime=new y([]),i.length=this.data.length,i}async _executeIterations(e,n,r,i){let s=["const","var","let","params"];for(let a=r;a<i;a++){if(e.idx=a,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[a]),e.data.open.data.push(this.open[a]),e.data.high.data.push(this.high[a]),e.data.low.data.push(this.low[a]),e.data.volume.data.push(this.volume[a]),e.data.hl2.data.push(this.hl2[a]),e.data.hlc3.data.push(this.hlc3[a]),e.data.ohlc4.data.push(this.ohlc4[a]),e.data.hlcc4.data.push(this.hlcc4[a]),e.data.openTime.data.push(this.openTime[a]),e.data.closeTime.data.push(this.closeTime[a]),e.data.bar_index.data.push(a),e.strategy){$y(e),Dy(e),Yi(e,"open");let c=jy(e);c&&Yi(e,"extreme"),Wy(e,"intrabar"),c||Yi(e,"extreme"),Uy(e)}let o=await n(e);if(typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let u;o[c]instanceof y?u=o[c].get(0):Array.isArray(o[c])?u=o[c][o[c].length-1]:u=o[c],e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(let c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();let l=c=>{for(let u of s)if(c[u])for(let p in c[u]){let h=c[u][p];if(h instanceof y){let d=h.get(0);h.data.push(d)}else if(Array.isArray(h)){let d=h[h.length-1];h.push(d)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}e.strategy&&zy(e)}},ko={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},hr={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3};function pr(t,e,n=1){if(e==="month"){let i=new Date(t);return Date.UTC(i.getUTCFullYear(),i.getUTCMonth()+n,1,i.getUTCHours(),i.getUTCMinutes(),i.getUTCSeconds(),i.getUTCMilliseconds())}let r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+n*r[e]}function Bt(t,e,n){let[r,i,s]=t.split("-").map(Number),[a,o]=e.split(":").map(Number),l=Date.UTC(r,i-1,s,a,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:n,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),p=u("year"),h=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),_=Date.UTC(p,h-1,d,f,m,0,0)-l;return l-_}function Ao(t,e,n,r,i=1){if(e==="24x7")return pr(t,r,i);let s=e.split("-")[1];if(!s||s.length!==4)return pr(t,r,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=Mo(t,n);if(r==="second"||r==="minute"||r==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[r],p=Bt(c,l,n);return Math.min(u,p)}if(r==="day")return Bt(c,l,n);if(r==="week"){let u=new Date(t).getUTCDay(),p=u<=5?5-u:5-u+7,h=t+p*864e5,d=Mo(h,n);return Bt(d,l,n)}if(r==="month"){let u=new Date(t),p=u.getUTCFullYear(),h=u.getUTCMonth()+i,d=new Date(Date.UTC(p,h,1)),f=new Date(d.getTime()-864e5);for(;f.getUTCDay()===0||f.getUTCDay()===6;)f.setUTCDate(f.getUTCDate()-1);let m=f.toISOString().split("T")[0];return Bt(m,l,n)}return pr(t,r,i)}function Mo(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function J1(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}var eb=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function tb(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;let n=hr[t];if(!n)return null;let r=eb.filter(i=>i!=="W"&&i!=="M"&&e.has(i)&&hr[i]<n&&n%hr[i]===0);return r.length===0?null:r[r.length-1]}function gc(t,e){if(t==="W"||t==="M")return 1/0;let n=hr[t],r=hr[e];return!n||!r||r===0?1/0:n/r}function nb(t,e,n){if(t.length===0)return[];if(e==="W")return ib(t);if(e==="M")return sb(t);let r=gc(e,n);return rb(t,r)}function rb(t,e){if(t.length===0)return[];let n=[],r=[t[0]],i=ab(t),s=i>0?i*1.5:0;for(let a=1;a<t.length;a++){let o=t[a].openTime-t[a-1].openTime;(s>0&&o>s||r.length>=e)&&(n.push(_i(r)),r=[]),r.push(t[a])}return r.length>0&&n.push(_i(r)),n}function ib(t){let e=[],n=[],r="";for(let i of t){let s=ob(i.openTime);s!==r&&n.length>0&&(e.push(n),n=[]),r=s,n.push(i)}return n.length>0&&e.push(n),e.map(_i)}function sb(t){let e=[],n=[],r="";for(let i of t){let s=new Date(i.openTime),a=`${s.getUTCFullYear()}-${s.getUTCMonth()}`;a!==r&&n.length>0&&(e.push(n),n=[]),r=a,n.push(i)}return n.length>0&&e.push(n),e.map(_i)}function _i(t){let e=t[0],n=t[t.length-1],r=e.high,i=e.low,s=0,a=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){let p=t[u];p.high>r&&(r=p.high),p.low<i&&(i=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:i,close:n.close,volume:s,closeTime:n.closeTime,quoteAssetVolume:a,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function ab(t){if(t.length<2)return 0;let e=Math.min(t.length-1,20),n=1/0;for(let r=0;r<e;r++){let i=t[r+1].openTime-t[r].openTime;i>0&&i<n&&(n=i)}return n===1/0?0:n}function ob(t){let e=new Date(t),n=e.getUTCDay()||7;e.setUTCDate(e.getUTCDate()+4-n);let r=new Date(Date.UTC(e.getUTCFullYear(),0,1)),i=Math.ceil(((e.getTime()-r.getTime())/864e5+1)/7);return`${e.getUTCFullYear()}-W${i}`}var lb=Object.defineProperty,cb=(t,e,n)=>e in t?lb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Rr=(t,e,n)=>cb(t,typeof e!="symbol"?e+"":e,n),Or={"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 ub(t){if(Or[t]!==void 0)return Or[t];let e=t.toLowerCase();return Or[e]!==void 0?Or[e]:/^\\d+$/.test(t)?t:/^\\d+S$/i.test(t)?t.toUpperCase():t}var yr=class{constructor(e){Rr(this,"_configured"),Rr(this,"_requiresApiKey"),Rr(this,"_providerName"),Rr(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){J1(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,n,r,i,s){e=tn(e);let a=ub(n),o=this.getSupportedTimeframes();if(o.has(a))return this._getMarketDataNative(e,a,r,i,s);let l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:tb(a,o);if(!c)return console.error(`${this._providerName}: Timeframe \'${n}\' is not supported and no valid sub-timeframe found for aggregation.`),[];let u=this._computeSubLimit(a,c,r),p=await this._getMarketDataNative(e,c,u,i,s);if(p.length===0)return[];let h=nb(p,a,c);return r&&r>0&&h.length>r?h.slice(h.length-r):h}_computeSubLimit(e,n,r){if(!r)return;let i=gc(e,n);return i===1/0?e==="W"?r*7+14:e==="M"?r*31+31:r*30:Math.ceil(r*i)+Math.ceil(i)}},hb=Object.defineProperty,pb=(t,e,n)=>e in t?hb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,bi=(t,e,n)=>pb(t,typeof e!="symbol"?e+"":e,n),ts="https://api.binance.com/api/v3",To="https://api.binance.us/api/v3",Lr={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"},Qs=class{constructor(e=300*1e3){bi(this,"cache"),bi(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([n,r])=>r!==void 0).map(([n,r])=>`${n}:${r}`).join("|")}get(e){let n=this.generateKey(e),r=this.cache.get(n);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(n),null):r.data:null}set(e,n){let r=this.generateKey(e);this.cache.set(r,{data:n,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){let e=Date.now();for(let[n,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(n)}},Js=class extends yr{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),bi(this,"cacheManager"),bi(this,"activeApiUrl",null),this.cacheManager=new Qs(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${ts}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=ts,this.activeApiUrl}catch{}try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${To}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=To,this.activeApiUrl}catch{}return ts}async _fetchRawChunk(e,n,r,i,s){let a=Lr[n.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${n}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${a}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),i&&(o+=`&startTime=${i}`),s&&(o+=`&endTime=${s}`);let l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,n,r,i){try{let s=Lr[n.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${n}`),[];let a=[],o=r,l=i,c=ko[s];if(!c)return console.error(`Duration not defined for interval: ${s}`),[];for(;o<l;){let u=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,n,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,n,r,i){let s=r,a=[],o=i,l=0,c=Math.ceil(r/1e3)+5;for(;s>0&&l<c;){l++;let u=Math.min(s,1e3),p=await this._fetchRawChunk(e,n,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,n,r,i,s){try{let a=s!==void 0,o={tickerId:e,timeframe:n,limit:r,sDate:i,eDate:s};if(a){let c=this.cacheManager.get(o);if(c)return c}if(!Lr[n.toUpperCase()])return console.error(`Unsupported timeframe: ${n}`),[];if(this.shouldPaginate(n,r,i,s)){if(i&&s){let c=await this.getMarketDataInterval(e,n,i,s),u=r?c.slice(0,r):c;return this.cacheManager.set(o,u),u}else if(r&&r>1e3){let c=await this.getMarketDataBackwards(e,n,r,s);return this.cacheManager.set(o,c),c}}let l=await this._fetchRawChunk(e,n,r,i,s);return this.normalizeCloseTime(l),a&&this.cacheManager.set(o,l),l}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(e,n,r,i){if(n&&n>1e3)return!0;if(r&&i){let s=Lr[e.toUpperCase()],a=ko[s];if(a)return Math.ceil((i-r)/a)>1e3}return!1}async getSymbolInfo(e){e=tn(e);try{let n="crypto",r=await this.getBaseUrl(),i=e,s="";e.endsWith(".P")?(n="futures",i=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):e.includes("_")&&(n="futures",i=e,r="https://dapi.binance.com/dapi/v1",s="Delivery");let a=n==="crypto"?`${r}/exchangeInfo?symbol=${i}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;let c=n==="futures"?l.find(S=>S.symbol===i):l[0];if(!c)return console.error(`Symbol ${i} not found in exchange info`),null;let u=c.filters?.find(S=>S.filterType==="PRICE_FILTER"),p=c.filters?.find(S=>S.filterType==="LOT_SIZE"),h=u?parseFloat(u.tickSize):.01,d=p?parseFloat(p.minQty):0,f=Math.round(1/h),m=c.baseAsset,_=c.quoteAsset,b=s?` ${s}`:"",v=`${m} / ${_}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:v,type:n,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:_,timezone:"Etc/UTC",country:"",mintick:h,pricescale:f,minmove:1,pointvalue:c.contractSize||1,mincontract:d,session:"24x7",volumetype:"base",expiration_date:c.deliveryDate||0,employees:0,industry:"",sector:"",shareholders:0,shares_outstanding_float:0,shares_outstanding_total:0,recommendations_buy:0,recommendations_buy_strong:0,recommendations_date:0,recommendations_hold:0,recommendations_sell:0,recommendations_sell_strong:0,recommendations_total:0,target_price_average:0,target_price_date:0,target_price_estimates:0,target_price_high:0,target_price_low:0,target_price_median:0}}catch(n){return console.error("Error in binance.exchangeInfo:",n),null}}},db=Object.defineProperty,fb=(t,e,n)=>e in t?db(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Jn=(t,e,n)=>fb(t,typeof e!="symbol"?e+"":e,n),mb="https://financialmodelingprep.com",Po=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"]),Do={"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"}},Ro={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"},Oo={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"},yb={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}},ea=class extends yr{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),Jn(this,"_apiKey",null),Jn(this,"_baseUrl",mb),Jn(this,"_profileCache",new Map),Jn(this,"_symbolInfoCache",new Map),Jn(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,n,r,i,s){this.ensureConfigured();try{let a=n.toUpperCase(),o=Do[a]||Do[n];if(!o)return console.error(`FMP: Unsupported timeframe: ${n}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,i,s,r):l=await this._fetchDailyData(e,i,s,r),l.length>0&&!this._mintickCache.has(e)){let c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(a){return console.error("Error in FMPProvider.getMarketData:",a),[]}}async _fetchDailyData(e,n,r,i){let s=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;n&&(s+=`&from=${this._msToDateStr(n)}`),r&&(s+=`&to=${this._msToDateStr(r)}`);let a=await fetch(s);if(!a.ok){let p=await a.text();throw new Error(`FMP HTTP ${a.status}: ${p}`)}let o=await a.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();let l=i&&i>0&&i<o.length?o.slice(o.length-i):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(p=>{let h=this._dateStrToMs(p.date),d=Ao(h,c,u,"day");return{openTime:h,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:d,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,n,r,i,s,a){let o=`${this._baseUrl}${n}?symbol=${e}&apikey=${this._apiKey}`;i&&(o+=`&from=${this._msToDateStr(i)}`),s&&(o+=`&to=${this._msToDateStr(s)}`);let l=await fetch(o);if(!l.ok){let m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${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}`)}let c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();let u=a&&a>0&&a<c.length?c.slice(c.length-a):c,{periodType:p,multiplier:h}=yb[r]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let _=this._dateTimeStrToMs(m.date),b=Ao(_,d,f,p,h);return{openTime:_,open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),e=tn(e),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{let n=await this._fetchProfile(e),r="stock";n?.isEtf?r="etf":n?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");let i=n?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),s=r==="crypto"||r==="forex"?"Etc/UTC":Ro[i]||"America/New_York",a=r==="crypto"?"24x7":r==="forex"?"0000-0000":Oo[i]||"0930-1600",o=n?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):n?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),p=Math.round(c*u),h={ticker:n?.symbol||e,tickerid:`${i}:${n?.symbol||e}`,prefix:i,root:n?.symbol||e,description:n?.companyName||e,type:r,main_tickerid:`${i}:${n?.symbol||e}`,current_contract:"",isin:n?.isin||"",basecurrency:l,currency:o,timezone:s,country:n?.country||"",mintick:c,pricescale:u,minmove:p,pointvalue:1,mincontract:0,session:a,volumetype:"base",expiration_date:0,employees:n&&parseInt(n.fullTimeEmployees)||0,industry:n?.industry||"",sector:n?.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(n){return console.error("Error in FMPProvider.getSymbolInfo:",n),null}}_estimateMintick(e){let n=[];for(let o=0;o<e.length;o++){let l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&n.push(c),u>0&&n.push(u),o>0){let p=Math.abs(l.close-e[o-1].close);p>0&&n.push(p)}}if(n.length===0)return;let r=Math.min(...n),i=Math.floor(Math.log10(r)),s=r/10**i,a=(Math.floor(s+1e-12)<5?1:10)*10**i;return a>=1?.01:a}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);let n=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(n);if(!r.ok)return null;let i=await r.json();if(!Array.isArray(i)||i.length===0)return null;let s=i[0];return this._profileCache.set(e,s),s}async _resolveSessionInfo(e){try{let n=await this._fetchProfile(e);if(n){let r=n.exchange||"",i=this._isCrypto(e),s=i?"Etc/UTC":Ro[r]||"America/New_York";return{session:i?"24x7":Oo[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)&&Po.has(e.slice(0,3))&&Po.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},gb=Object.defineProperty,xb=(t,e,n)=>e in t?gb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,un=(t,e,n)=>xb(t,typeof e!="symbol"?e+"":e,n),_b="https://data.alpaca.markets",bb="https://paper-api.alpaca.markets/v2",vb="https://api.alpaca.markets/v2",ns=1e4,Lo={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"},wb={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"},Sb={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},Eb={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},ta=class extends yr{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),un(this,"_apiKey",null),un(this,"_apiSecret",null),un(this,"_dataUrl",_b),un(this,"_tradingUrl",bb),un(this,"_feed",null),un(this,"_assetCache",new Map),un(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=vb)}_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,n,r,i,s){this.ensureConfigured();try{let a=this._resolveTimeframe(n);if(!a)return console.error(`Alpaca: Unsupported timeframe: ${n}`),[];let o=this._isCrypto(e),l=await this._fetchAllBars(e,a,o,i,s,r);if(l.length===0)return[];let{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(a);if(o)return this._convertBarsCrypto(l,c,u);let p=l[0].t.slice(0,10),h=l[l.length-1].t.slice(0,10),d=this._addDaysToDate(h,40);return await this._ensureCalendar(p,d),this._convertBarsStock(l,c,u)}catch(a){return console.error("Error in AlpacaProvider.getMarketData:",a),[]}}async _fetchAllBars(e,n,r,i,s,a){let o=[],l=null,c=a||1/0,u=Math.min(a||ns,ns);do{let p=this._buildBarsUrl(e,n,r,i,s,u,l),h=await fetch(p,{headers:this._headers()});if(!h.ok){let m=await h.text();throw new Error(`Alpaca HTTP ${h.status}: ${m}`)}let d=await h.json(),f=Object.keys(d.bars||{})[0];if(!f||!d.bars[f]||(o.push(...d.bars[f]),l=d.next_page_token,o.length>=c))break}while(l);return a&&a>0&&o.length>a?o.slice(0,a):o}_buildBarsUrl(e,n,r,i,s,a,o){let l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",n),c.set("sort","asc"),i&&c.set("start",new Date(i).toISOString()),s&&c.set("end",new Date(s).toISOString()),a&&c.set("limit",String(Math.min(a,ns))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=tn(e);try{let n=await this._fetchAsset(e);if(!n)return console.error(`Alpaca: Symbol ${e} not found`),null;let r=n.exchange||"",i=n.class==="crypto",s=i?"Etc/UTC":wb[r]||"America/New_York",a=i?"24x7":Sb[r]||"0930-1600",o="stock";i&&(o="crypto");let l=i&&e.split("/")[1]||"USD",c=i?e.split("/")[0]||e:l,u=n.price_increment?parseFloat(n.price_increment):.01,p=Math.round(1/u);return{ticker:n.symbol,tickerid:`${r}:${n.symbol}`,prefix:r,root:i?e.split("/")[0]:n.symbol,description:n.name||n.symbol,type:o,main_tickerid:`${r}:${n.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:s,country:i?"":"US",mintick:u,pricescale:p,minmove:1,pointvalue:1,mincontract:n.min_order_size?parseFloat(n.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(n){return console.error("Error in AlpacaProvider.getSymbolInfo:",n),null}}_convertBarsCrypto(e,n,r){return e.map((i,s,a)=>{let o=new Date(i.t).getTime(),l=s<a.length-1?new Date(a[s+1].t).getTime():pr(o,n,r);return this._toKline(i,o,l)})}_convertBarsStock(e,n,r){let i="America/New_York";return e.map(s=>{let a=new Date(s.t).getTime(),o=s.t.slice(0,10),l;if(n==="day"){let c=this._calendarCache.get(o),u=c?c.close:"16:00";l=Bt(o,u,i)}else if(n==="minute"||n==="hour"){let c=a+r*{minute:6e4,hour:36e5}[n],u=this._calendarCache.get(o),p=u?u.close:"16:00",h=Bt(o,p,i);l=Math.min(c,h)}else n==="week"?l=this._weeklyCloseFromCalendar(o,i):n==="month"?l=this._monthlyCloseFromCalendar(o,i):l=pr(a,n,r);return this._toKline(s,a,l)})}_toKline(e,n,r){return{openTime:n,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,n){let r=new Date(e+"T00:00:00Z"),i=r.getUTCDay(),s=i<=5?5-i:5-i+7;for(let l=s;l>=0;l--){let c=r.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(u);if(p)return Bt(u,p.close,n)}let a=r.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return Bt(o,"16:00",n)}_monthlyCloseFromCalendar(e,n){let[r,i]=e.split("-").map(Number),s=new Date(Date.UTC(r,i,0)).getUTCDate();for(let o=s;o>=1;o--){let l=`${r}-${String(i).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return Bt(l,c.close,n)}let a=new Date(Date.UTC(r,i,0));for(;a.getUTCDay()===0||a.getUTCDay()===6;)a.setUTCDate(a.getUTCDate()-1);return Bt(a.toISOString().split("T")[0],"16:00",n)}async _ensureCalendar(e,n){if(this._calendarCache.has(e)&&this._calendarCache.has(n))return;let r=`${this._tradingUrl}/calendar?start=${e}&end=${n}`,i=await fetch(r,{headers:this._headers()});if(!i.ok){console.warn(`Alpaca calendar API returned ${i.status}, falling back to defaults`);return}let s=await i.json();for(let a of s)this._calendarCache.set(a.date,a)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);let n=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${n}`,i=await fetch(r,{headers:this._headers()});if(!i.ok)return null;let s=await i.json();return this._assetCache.set(e,s),s}_parseAlpacaTimeframe(e){let n=e.match(/^(\\d+)(Min|Hour|Day|Week|Month)$/);if(n){let r=parseInt(n[1],10),i=Eb[n[2]];if(i)return{periodType:i,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Lo[e.toUpperCase()]||Lo[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,n){let r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+n),r.toISOString().split("T")[0]}},na=class{async getMarketData(){return[]}},Cb=typeof process<"u"&&process.versions&&process.versions.node,vi=null;if(Cb)try{vi=new na}catch{vi=null}var _C={Binance:new Js,FMP:new ea,Alpaca:new ta,...vi?{Mock:vi}:{}};function U(t){return typeof t=="string"?t:void 0}function le(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function xc(t){if(typeof t=="boolean")return t;if(typeof t=="object"&&t!==null&&Array.isArray(t.data)){let e=t;return xc(e.data[e.offset??0])}}function Ib(t){let e=new Map,n=!1;for(let i=0;i<t.length;i+=1){let s=t[i].time;e.has(s)&&(n=!0),e.set(s,i)}if(!n)return t;let r=new Set(e.values());return t.filter((i,s)=>r.has(s))}function va(t){let e=t??{},n=e.fullContext??e;return Object.keys({...n.indicator,...n.strategy?.config}).length>0}function Ai(t){let e=t??{},n=e.fullContext??e,r={...n.indicator,...n.strategy?.config},i={title:U(r.title)??"Indicator",overlay:xc(r.overlay)??!1,precision:le(r.precision),shorttitle:U(r.shorttitle),format:U(r.format)},s=n.plots??{},a=Object.entries(s).map(([l,c])=>{let u=c??{},p=u.options??{};return{key:l,title:U(u.title),style:U(p.style),options:p,data:Array.isArray(u.data)?Ib(u.data):[],plot1:U(u.plot1)??U(p.plot1),plot2:U(u.plot2)??U(p.plot2)}}),o=n.strategy?Nb(n.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function Nb(t){let e=[],n=Array.isArray(t.closedtrades)?t.closedtrades:[],r=Array.isArray(t.opentrades)?t.opentrades:[];for(let i of[...n,...r]){let s=i??{},a=le(s.entry_price),o=le(s.entry_time),l=le(s.size);a===void 0||o===void 0||l===void 0||l===0||e.push({id:U(s.id)??`trade_${e.length}`,entry_id:U(s.entry_id)??"",entry_price:a,entry_time:o,entry_comment:U(s.entry_comment),exit_id:U(s.exit_id),exit_price:le(s.exit_price),exit_time:le(s.exit_time),exit_comment:U(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var kb={line:"line",style_line:"line",style_linebr:"line",style_area:"area",style_areabr:"area",style_stepline:"step",style_steplinebr:"step",style_stepline_diamond:"step",style_histogram:"histogram",style_columns:"columns",style_circles:"circles",style_cross:"cross",shape:"markers",char:"markers",bar:"bar",candle:"candle",background:"background",barcolor:"barcolor",hline:"hline",fill:"fill",drawing_line:"drawing_line",drawing_box:"drawing_box",label:"label",drawing_polyline:"drawing_polyline",linefill:"linefill",table:"table"};function _c(t){return t==null||t===""?"line":kb[t]??"line"}function Mi(t){if(typeof t!="string")return!1;let e=t.trim();if(!e)return!1;let n=e.toLowerCase();if(n==="na"||n==="nan")return!1;let r=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})$/.exec(e);return!(r&&parseInt(r[1]??"ff",16)===0||/rgba?\\([^)]*,\\s*0(?:\\.0+)?\\s*\\)$/.test(e))}function se(t,e){return Mi(t)?t.trim():e}var bc="#00000000";var vn="#2962ff",wa="#38c0fd",kt="#089981",jt="#f23645",wn="#787b86";var Sa="#ff9800",Sn="#5b9cf6",Ea="#ff5d00",Ca="#0ecb81",Ia="#f6465d";var Ab=new Map;function D(t,e){Ab.set(t,e)}function Mb(t,e=""){return`<svg viewBox="0 0 16 16" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`}function k(t,e=""){return`<svg viewBox="0 0 24 24" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`}var z=Mb;D("style-candles",z(\'<path d="M4.5 2v2M4.5 12v2M11.5 2v1.5M11.5 11v3"/><rect x="2.8" y="4" width="3.4" height="8" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="3.5" width="3.4" height="7.5" rx="0.6" fill="currentColor"/>\'));D("style-bars",z(\'<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>\'));D("style-line",z(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>\'));D("style-area",z(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/><path d="M1.5 11.5 5.5 7l3 2.5 5-6V13.5h-12z" fill="currentColor" fill-opacity="0.25" stroke="none"/>\'));D("style-baseline",z(\'<path d="M1.5 8h13" stroke-dasharray="2 2"/><path d="M2.5 8 5.25 4.5 8 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M2.5 8 5.25 4.5 8 8"/><path d="M8 8l2.75 3.5L13.5 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M8 8l2.75 3.5L13.5 8"/>\'));D("style-heikinashi",z(\'<path d="M4.5 12v2M11.5 2v2"/><rect x="2.8" y="5" width="3.4" height="7" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="4" width="3.4" height="7" rx="0.6" fill="currentColor"/>\'));D("indicators",z(\'<path d="M1.5 12.5 5 7l2.5 3.5L11 4l3.5 5"/><circle cx="11" cy="4" r="1.4" fill="currentColor" stroke="none"/>\'));D("undo",z(\'<path d="M6.2 9.5 2.7 6l3.5-3.5"/><path d="M2.7 6h6.8a3.65 3.65 0 0 1 0 7.3H7.5"/>\'));D("redo",z(\'<path d="M9.8 9.5 13.3 6 9.8 2.5"/><path d="M13.3 6H6.5a3.65 3.65 0 0 0 0 7.3h2"/>\'));D("objects",z(\'<path d="M8 1.8 14 5 8 8.2 2 5z"/><path d="M2 8l6 3.2L14 8" opacity="0.7"/><path d="M2 11l6 3.2 6-3.2" opacity="0.4"/>\'));D("clock",z(\'<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>\'));D("calendar",z(\'<rect x="2.2" y="3.2" width="11.6" height="10.6" rx="1.4"/><path d="M5.2 1.8v2.8M10.8 1.8v2.8M2.2 6.8h11.6"/>\'));D("datawindow",z(\'<rect x="1.8" y="2.5" width="12.4" height="11" rx="1.5"/><path d="M4.5 5.5h4M4.5 8h7M4.5 10.5h5.5"/>\'));D("camera",z(\'<path d="M5.5 4 6.5 2.5h3L10.5 4h3A1 1 0 0 1 14.5 5v7.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"/><circle cx="8" cy="8.5" r="2.6"/>\'));D("gear",z(\'<path d="M6.55 1.4h2.9l.32 1.72c.48.14.92.38 1.3.7l1.66-.55 1.45 2.5-1.35 1.1c.08.34.12.7.12 1.07s-.04.73-.12 1.07l1.35 1.1-1.45 2.5-1.66-.55a4.3 4.3 0 0 1-1.3.7L9.45 14.6h-2.9l-.32-1.72a4.3 4.3 0 0 1-1.3-.7l-1.66.55-1.45-2.5 1.35-1.1A4.4 4.4 0 0 1 3.05 7.94c0-.37.04-.73.12-1.07l-1.35-1.1 1.45-2.5 1.66.55c.38-.32.82-.56 1.3-.7L6.55 1.4z"/><circle cx="8" cy="8" r="2.2"/>\'));D("search",z(\'<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>\'));D("bell",z(\'<path d="M8 2a4 4 0 0 0-4 4v2.5L2.5 11v1h11v-1L12 8.5V6a4 4 0 0 0-4-4z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/>\'));D("market-open",k(\'<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>\'));D("market-pre",k(\'<path d="M12 2v8"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m8 6 4-4 4 4"/><path d="M16 18a4 4 0 0 0-8 0"/>\'));D("market-post",k(\'<path d="M12 10V2"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m16 14-4 4-4-4"/><path d="M16 6a4 4 0 0 0-8 0"/>\'));D("market-extended",k(\'<path d="M22 22H2"/><path d="M12 3a5 5 0 0 0 7.5 7.5A7.5 7.5 0 1 1 12 3Z"/>\'));D("market-closed",k(\'<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>\'));D("market-holiday",k(\'<path d="m10 20-1.25-2.5L6 16"/><path d="M10 4 8.75 6.5 6 8"/><path d="m14 20 1.25-2.5L18 16"/><path d="m14 4 1.25 2.5L18 8"/><path d="m17 10-5 5-5-5"/><path d="M4 12h16"/>\'));D("chevron-right",z(\'<path d="m6 3.5 4.5 4.5L6 12.5"/>\'));D("chevron-left",z(\'<path d="M10 3.5 5.5 8l4.5 4.5"/>\'));D("chevron-down",z(\'<path d="M3.5 6 8 10.5 12.5 6"/>\'));D("chevron-up",z(\'<path d="M3.5 10 8 5.5 12.5 10"/>\'));D("chevrons-right",z(\'<path d="m4 3.5 4.5 4.5L4 12.5"/><path d="m8.5 3.5 4.5 4.5-4.5 4.5"/>\'));D("chevrons-left",z(\'<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>\'));D("check",z(\'<path d="m2.8 8.4 3.4 3.4 7-7.6"/>\'));D("close",z(\'<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>\'));D("pin",z(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/>\'));D("pin-filled",z(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/><path d="M6.4 2.5h3.2v3.6l2 2.3v.9H4.4v-.9l2-2.3z" fill="currentColor" stroke="none"/>\'));D("eye",z(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>\'));D("eye-off",z(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>\'));D("lock",z(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7"/>\'));D("unlock",z(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.7-.7"/>\'));D("trash",z(\'<path d="M2.5 4.3h11M6.2 4.3V3.1a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.2M4.2 4.3l.5 9.1a1.15 1.15 0 0 0 1.15 1.1h4.3a1.15 1.15 0 0 0 1.15-1.1l.5-9.1M6.5 7v4.5M9.5 7v4.5"/>\'));D("group",z(\'<path d="M1.8 4.5V2.4a.6.6 0 0 1 .6-.6h2.1M11.5 1.8h2.1a.6.6 0 0 1 .6.6v2.1M14.2 11.5v2.1a.6.6 0 0 1-.6.6h-2.1M4.5 14.2H2.4a.6.6 0 0 1-.6-.6v-2.1"/><rect x="4" y="4" width="4.2" height="4.2" rx="0.7"/><rect x="7.8" y="7.8" width="4.2" height="4.2" rx="0.7"/>\'));D("ungroup",z(\'<rect x="1.6" y="1.6" width="6.2" height="6.2" rx="0.9"/><rect x="8.2" y="8.2" width="6.2" height="6.2" rx="0.9" stroke-dasharray="2 1.5"/>\'));D("clone",z(\'<rect x="5.5" y="5.5" width="9" height="9" rx="1.2"/><path d="M11 5.5v-3a1 1 0 0 0-1-1H2.5a1 1 0 0 0-1 1V10a1 1 0 0 0 1 1h3"/>\'));D("arrow-up",z(\'<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>\'));D("arrow-down",z(\'<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>\'));D("move-vertical",z(\'<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>\'));D("move",z(\'<path d="M8 1.8v12.4M1.8 8h12.4M5.6 4.2 8 1.8l2.4 2.4M5.6 11.8 8 14.2l2.4-2.4M4.2 5.6 1.8 8l2.4 2.4M11.8 5.6 14.2 8l-2.4 2.4"/>\'));D("pen",z(\'<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>\'));D("wave",z(\'<path d="M1.5 10.4c1.6 0 1.9-4.8 3.4-4.8s1.8 4.8 3.4 4.8 1.8-4.8 3.4-4.8 1.6 4.8 2.8 4.8"/>\'));D("folder-plus",z(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M8 7.6v3.6M6.2 9.4h3.6"/>\'));D("folder-minus",z(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M6.2 9.4h3.6"/>\'));D("collapse",z(\'<path d="M3 8h10"/>\'));D("expand",z(\'<rect x="2.2" y="2.2" width="11.6" height="11.6" rx="1.4"/><path d="M8 5.4v5.2M5.4 8h5.2"/>\'));D("plus",z(\'<path d="M8 2.8v10.4M2.8 8h10.4"/>\'));D("minus",z(\'<path d="M2.8 8h10.4"/>\'));D("maximize",z(\'<path d="M2.5 6V3a.5.5 0 0 1 .5-.5h3M10 2.5h3a.5.5 0 0 1 .5.5v3M13.5 10v3a.5.5 0 0 1-.5.5h-3M6 13.5H3a.5.5 0 0 1-.5-.5v-3"/>\'));D("restore",z(\'<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>\'));D("star",z(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\'));D("star-filled",z(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\',\'fill="currentColor"\'));D("grip",z(\'<circle cx="6" cy="3.5" r="1"/><circle cx="10" cy="3.5" r="1"/><circle cx="6" cy="8" r="1"/><circle cx="10" cy="8" r="1"/><circle cx="6" cy="12.5" r="1"/><circle cx="10" cy="12.5" r="1"/>\',\'fill="currentColor" stroke="none"\'));D("kebab",z(\'<circle cx="8" cy="3.2" r="1.2"/><circle cx="8" cy="8" r="1.2"/><circle cx="8" cy="12.8" r="1.2"/>\',\'fill="currentColor" stroke="none"\'));D("burger",z(\'<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>\'));D("info",z(\'<path d="M8 7.4v4.4"/><circle cx="8" cy="4.6" r="0.9" fill="currentColor" stroke="none"/>\'));D("reset",z(\'<path d="M2 8a6 6 0 1 0 6-6 6.5 6.5 0 0 0-4.5 1.83L2 5.33"/><path d="M2 2v3.33h3.33"/>\'));D("pane-collapse",z(\'<path d="M2.6 9.4h4v4M13.4 6.6h-4v-4"/><path d="m9.4 6.6 4.2-4.2M2.4 13.6l4.2-4.2"/>\'));D("pane-expand",z(\'<path d="M9.8 2.4h3.8v3.8M6.2 13.6H2.4V9.8"/><path d="m13.6 2.4-4.4 4.4M2.4 13.6l4.4-4.4"/>\'));D("cursor",k(\'<path d="M5 3l6 16 2-6 6-2z"/>\',\'fill="currentColor" stroke="none"\'));D("ruler",k(\'<path d="M21.3 15.3 8.7 2.7a1 1 0 0 0-1.4 0L2.7 7.3a1 1 0 0 0 0 1.4l12.6 12.6a1 1 0 0 0 1.4 0l4.6-4.6a1 1 0 0 0 0-1.4Z"/><path d="m7.5 10.5 2 2"/><path d="m10.5 7.5 2 2"/><path d="m13.5 4.5 2 2"/><path d="m4.5 13.5 2 2"/>\'));D("magnet",k(\'<path d="m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15"/><path d="m5 8 4 4"/><path d="m12 15 4 4"/>\'));D("eraser",k(\'<path d="m7 21-4.3-4.3a1 1 0 0 1 0-1.4L13 5a2 2 0 0 1 2.8 0l4.2 4.2a2 2 0 0 1 0 2.8L12 20"/><path d="M22 21H7"/><path d="m5 11 9 9"/>\'));D("pen-lock",k(\'<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="13" y="14.5" width="8" height="6" rx="1.2"/><path d="M15 14.5v-1.6a2 2 0 0 1 4 0v1.6"/>\'));D("pen-sync",k(\'<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="12.5" y="13.5" width="6" height="4.8" rx="1"/><path d="M15.5 18.3v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-2.8a1 1 0 0 0-1-1h-1"/>\'));D("brush",k(\'<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>\'));D("bucket",k(\'<path d="m18.5 11.5-7-7L4 12a1.8 1.8 0 0 0 0 2.5l5 5a1.8 1.8 0 0 0 2.5 0Z"/><path d="m5 5 4 4"/><path d="M3.5 13.5h13"/><path d="M21 17.5c0 1.1-.9 2-2 2s-2-.9-2-2c0-1 1.2-1.7 2-3 .8 1.3 2 2 2 3Z"/>\'));D("type",k(\'<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>\'));D("bold",k(\'<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7Z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7Z"/>\',\'stroke-width="2.4"\'));D("italic",k(\'<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>\',\'stroke-width="2.2"\'));D("price-delta",k(\'<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>\'));D("date-delta",k(\'<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>\'));D("bring-front",k(\'<rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/>\'));D("send-back",k(\'<rect x="8.5" y="8.5" width="7" height="7" rx="1.5" fill="currentColor" stroke="none" opacity="0.35"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/><rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/>\'));D("r-squared",\'<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none"><text x="2.5" y="17.5" font-size="14" font-family="serif">R\\xB2</text></svg>\');D("bands",k(\'<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>\'));D("dedekind",k(\'<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0"/><path d="M8 20a4 4 0 0 1 8 0"/><path d="M12 4v16"/>\'));D("sonic",k(\'<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>\'));D("supersonic",k(\'<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>\'));var R=wa;function Tb(){return{lineColor:R,lineWidth:2,lineStyle:"solid"}}function Pi(t=""){return{value:t,size:"normal",hAlign:"left",vAlign:"top"}}var Oc=class Lc{constructor(e){this.locked=!1,this.visible=!0,this.zIndex=0,this.id=e.id??`dw-${Lc.seq+=1}`,this.paneId=e.paneId,this.anchors=(e.anchors??[]).map(n=>({time:n.time,price:n.price})),this.style=e.style?{...e.style}:Tb(),this.text=e.text?{...e.text}:void 0,this.locked=e.locked??!1,this.visible=e.visible??!0,this.zIndex=e.zIndex??0,this.createdAt=e.createdAt??Date.now(),e.props&&this.readProps(e.props)}isComplete(){return this.anchors.length>=this.anchorSchema().min}placementMode(){return"click"}onPlaced(e){}constrainHandleDrag(e){}translateBody(e,n,r){return r.map(i=>({time:i.time+e,price:i.price+n}))}timeExtent(){if(this.anchors.length===0)return null;let e=1/0,n=-1/0;for(let r of this.anchors)r.time<e&&(e=r.time),r.time>n&&(n=r.time);return{min:e,max:n}}editableLevels(){return null}applySettings(e){for(let[n,r]of Object.entries(e))n.startsWith("text.")&&!this.text&&(this.text=Pi()),Pb(this,n,r)}applyProps(e){this.readProps(e)}serialize(){return{id:this.id,type:this.type,paneId:this.paneId,anchors:this.anchors.map(e=>({time:e.time,price:e.price})),style:{...this.style},text:this.text?{...this.text}:void 0,locked:this.locked,visible:this.visible,zIndex:this.zIndex,createdAt:this.createdAt,props:this.writeProps()}}writeProps(){}readProps(e){}};Oc.seq=0;var fe=Oc;function Pb(t,e,n){let r=e.split("."),i=t;for(let s=0;s<r.length-1;s+=1){let a=r[s],o=i[a];(o==null||typeof o!="object")&&(o={},i[a]=o),i=o}i[r[r.length-1]]=n}var qn=[{value:"solid",label:"Solid"},{value:"dashed",label:"Dashed"},{value:"dotted",label:"Dotted"}],te=[{path:"style.lineColor",label:"Line color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Line width",kind:"number",min:1,max:10,step:1,group:"line"},{path:"style.lineStyle",label:"Line style",kind:"lineStyle",options:qn,group:"line"}],tt=[{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"}],ka=[{value:"small",label:"Small"},{value:"normal",label:"Normal"},{value:"large",label:"Large"},{value:"huge",label:"Huge"}],re=[{path:"text.value",label:"Text",kind:"text",group:"text"},{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:ka,group:"text"},{path:"text.bold",label:"Bold",kind:"boolean",group:"text"},{path:"text.italic",label:"Italic",kind:"boolean",group:"text"}];function Oe(t,e,n,r,i,s){let a=i-n,o=s-r,l=a*a+o*o;if(l<=1e-9)return Math.hypot(t-n,e-r);let c=((t-n)*a+(e-r)*o)/l;return c=c<0?0:c>1?1:c,Math.hypot(t-(n+c*a),e-(r+c*o))}function Aa(t,e,n){let r=1/0;for(let i=1;i<n.length;i+=1){let s=n[i-1],a=n[i],o=Oe(t,e,s[0],s[1],a[0],a[1]);o<r&&(r=o)}return r}function Zt(t,e,n,r,i,s,a=0){let o=Math.min(n,i)-a,l=Math.max(n,i)+a,c=Math.min(r,s)-a,u=Math.max(r,s)+a;return t>=o&&t<=l&&e>=c&&e<=u}function wr(t,e,n){let r=!1;for(let i=0,s=n.length-1;i<n.length;s=i,i+=1){let a=n[i],o=n[s];a[1]>e!=o[1]>e&&t<(o[0]-a[0])*(e-a[1])/(o[1]-a[1])+a[0]&&(r=!r)}return r}function me(t,e,n,r=6){for(let i=0;i<n.length;i+=1){let s=n[i];if(Math.hypot(t-s[0],e-s[1])<=r)return i}return-1}function Ye(t,e,n,r,i,s,a){if(i==="none")return[t,e,n,r];let o=n-t,l=i==="left"||i==="both",c=i==="right"||i==="both";if(Math.abs(o)<1e-6){if(l&&c)return[t,0,n,a];let f=r>=e;return c?f?[t,e,n,a]:[t,e,n,0]:f?[t,0,n,r]:[t,a,n,r]}let u=(r-e)/o,p=f=>e+u*(f-t),h=l?-2:Math.min(t,n),d=c?s+2:Math.max(t,n);return[h,p(h),d,p(d)]}var Db=class extends fe{constructor(){super(...arguments),this.type="trendline"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&Oe(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);if(!e)return null;let n=Math.min(e[0],e[2]),r=Math.min(e[1],e[3]);return{x:n,y:r,w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,{path:"style.arrowRight",label:"Arrow",kind:"boolean",group:"line"},...re]}}},Rb=class extends fe{constructor(){super(...arguments),this.type="hline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"y"}]}}y(t){let e=this.anchors[0];return e?t.yOf(e.price,this.paneId):null}hitTest(t,e,n,r){let i=this.y(n);return i!=null&&Math.abs(e-i)<=r}handlePoints(t){let e=this.anchors[0],n=this.y(t);return!e||n==null?[]:[[t.xOf(e.time),n]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.y(t);return e==null?null:{x:0,y:e-1,w:t.width,h:2}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return{fields:[...te,...re]}}},Ob=class extends fe{constructor(){super(...arguments),this.type="ray"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);if(!i)return!1;let[s,a,o,l]=Ye(i[0],i[1],i[2],i[3],"right",n.width,n.height);return Oe(t,e,s,a,o,l)<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...re]}}},Ma=class extends fe{anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&Oe(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...re]}}},Lb=class extends Ma{constructor(){super(...arguments),this.type="extendedline"}hitTest(t,e,n,r){let i=this.pixels(n);if(!i)return!1;let[s,a,o,l]=Ye(i[0],i[1],i[2],i[3],"both",n.width,n.height);return Oe(t,e,s,a,o,l)<=r}timeExtent(){return null}},Fb=class extends fe{constructor(){super(...arguments),this.type="vline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"x"}]}}x(t){let e=this.anchors[0];return e?t.xOf(e.time):null}hitTest(t,e,n,r){let i=this.x(n);return i!=null&&Math.abs(t-i)<=r}handlePoints(t){let e=this.anchors[0],n=this.x(t);if(!e||n==null)return[];let r=t.yOf(e.price,this.paneId);return r==null?[]:[[n,r]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.x(t);return e==null?null:{x:e-1,y:0,w:2,h:t.height}}priceRange(){return null}schema(){return{fields:[...te,...re]}}},Bb=class extends fe{constructor(){super(...arguments),this.type="hray"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.pt(n);return i!=null&&Oe(t,e,i[0],i[1],n.width,i[1])<=r}handlePoints(t){let e=this.pt(t);return e?[e]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pt(t);return e?{x:e[0],y:e[1]-1,w:Math.max(0,t.width-e[0]),h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){let t=this.anchors[0];return t?{min:t.time,max:Number.POSITIVE_INFINITY}:null}schema(){return{fields:[...te,...re]}}},Vb=class extends fe{constructor(){super(...arguments),this.type="crossline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.pt(n);return i!=null&&(Math.abs(e-i[1])<=r||Math.abs(t-i[0])<=r)}handlePoints(t){let e=this.pt(t);return e?[e]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pt(t);return e?{x:e[0]-1,y:e[1]-1,w:2,h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return{fields:[...te,...re]}}},Wb=class extends Ma{constructor(){super(...arguments),this.type="infoline"}},$b=class extends Ma{constructor(){super(...arguments),this.type="trendangle"}},jb=class extends fe{constructor(){super(...arguments),this.type="box"}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i?this.style.fillColor&&Zt(t,e,i.x1,i.y1,i.x2,i.y2)?!0:[[i.x1,i.y1,i.x2,i.y1],[i.x2,i.y1,i.x2,i.y2],[i.x2,i.y2,i.x1,i.y2],[i.x1,i.y2,i.x1,i.y1]].some(a=>Oe(t,e,a[0],a[1],a[2],a[3])<=r):!1}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te.map(t=>({...t,label:t.label.replace("Line","Border")})),{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"},...re]}}},Ub={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Ta=class extends fe{defaultLabel(){return"Text"}labelText(){return this.text?.value??this.defaultLabel()}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}box(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=Ub[this.text?.size??"normal"]??14,i=this.labelText().split(`\n`),s=Math.max(1,...i.map(a=>a.length));return{x:t.xOf(e.time),y:n,w:Math.max(12,s*r*.6)+8,h:i.length*r*1.4+4}}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Zt(t,e,i.x,i.y,i.x+i.w,i.y+i.h)}handlePoints(t){let e=this.anchors[0],n=e?t.yOf(e.price,this.paneId):null;return e&&n!=null?[[t.xOf(e.time),n]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){return this.box(t)}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}},zb=class extends Ta{constructor(t){super(t),this.type="text",this.text||(this.text={...Pi(),size:"large"})}schema(){return{fields:[...re],textIsContent:!0}}},qb=class extends Ta{constructor(t){super(t),this.type="note",this.text||(this.text=Pi("Note"))}defaultLabel(){return"Note"}schema(){return{fields:[...te,...tt,...re],textIsContent:!0}}},Hb=class extends Ta{constructor(){super(...arguments),this.type="pricelabel"}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return{fields:[...te,...tt,...re.filter(t=>t.path!=="text.value")]}}},Kb={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Di=class extends fe{constructor(t){super(t),this.text||(this.text=Pi(this.defaultLabel()))}defaultLabel(){return"Callout"}labelText(){return this.text?.value??this.defaultLabel()}anchorSchema(){return{min:2,max:2,slots:[{role:"target",free:"both"},{role:"box",free:"both"}]}}box(t){let e=this.anchors[1];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=Kb[this.text?.size??"normal"]??14,i=this.labelText().split(`\n`),s=Math.max(1,...i.map(l=>l.length)),a=Math.max(20,s*r*.6)+16,o=i.length*r*1.4+12;return{x:t.xOf(e.time)-a/2,y:n-o/2,w:a,h:o}}points(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitTest(t,e,n,r){let i=this.box(n);if(i&&Zt(t,e,i.x,i.y,i.x+i.w,i.y+i.h,r))return!0;let s=this.points(n);return s!=null&&Oe(t,e,s[0][0],s[0][1],s[1][0],s[1][1])<=r}handlePoints(t){let e=this.points(t);return e?[e[0]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}translateBody(t,e,n){let r=n[0],i=n[1];return!r||!i?n.map(s=>({time:s.time+t,price:s.price+e})):[{time:r.time,price:r.price},{time:i.time+t,price:i.price+e}]}bounds(t){return this.box(t)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...tt,...re],textIsContent:!0}}},Yb=class extends Di{constructor(){super(...arguments),this.type="callout"}},Gb=class extends Di{constructor(){super(...arguments),this.type="pricenote"}defaultLabel(){return""}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return{fields:[...te,...tt,...re.filter(t=>t.path!=="text.value")]}}},Xb=class extends Di{constructor(){super(...arguments),this.type="comment"}defaultLabel(){return"Comment"}},Zb=class extends Di{constructor(){super(...arguments),this.type="signpost"}defaultLabel(){return"Signpost"}},At=class extends fe{hitTest(t,e,n,r){let i=this.geometry(n);return i?this.style.fillColor&&i.fill&&wr(t,e,i.fill)?!0:i.segments.some(s=>Oe(t,e,s[0],s[1],s[2],s[3])<=r):!1}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}},Qb=class extends At{constructor(){super(...arguments),this.type="parallelchannel"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"y"}]}}offset(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];return!t||!e||!n?0:n.price-(t.price+e.price)/2}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return[];let s=[[t.xOf(e.time),r],[t.xOf(n.time),i]],a=this.anchors[2];if(a){let o=t.yOf(a.price,this.paneId);o!=null&&s.push([t.xOf((e.time+n.time)/2),o])}return s}timeExtent(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.time,e.time),max:Math.max(t.time,e.time)}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=this.offset(),i=t.xOf(e.time),s=t.xOf(n.time),a=t.yOf(e.price,this.paneId),o=t.yOf(n.price,this.paneId),l=t.yOf(e.price+r,this.paneId),c=t.yOf(n.price+r,this.paneId);return a==null||o==null||l==null||c==null?null:{segments:[[i,a,s,o],[i,l,s,c]],fill:[[i,a],[s,o],[s,c],[i,l]]}}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=this.offset(),r=[t.price,e.price,t.price+n,e.price+n],i=this.anchors[2];return i&&r.push(i.price),{min:Math.min(...r),max:Math.max(...r)}}schema(){return{fields:[...te,...tt,...re]}}},Jb=class extends At{constructor(){super(...arguments),this.type="disjointchannel"}anchorSchema(){return{min:4,max:4,slots:[{role:"top1",free:"both"},{role:"top2",free:"both"},{role:"bot1",free:"both"},{role:"bot2",free:"both"}]}}seg(t,e,n){let r=this.anchors[t],i=this.anchors[e];if(!r||!i)return null;let s=n.yOf(r.price,this.paneId),a=n.yOf(i.price,this.paneId);return s==null||a==null?null:[n.xOf(r.time),s,n.xOf(i.time),a]}geometry(t){let e=this.seg(0,1,t),n=this.seg(2,3,t),r=[e,n].filter(s=>s!=null);if(r.length===0)return null;let i=e&&n?[[e[0],e[1]],[e[2],e[3]],[n[2],n[3]],[n[0],n[1]]]:null;return{segments:r,fill:i}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...tt,...re]}}},ev=class extends At{constructor(){super(...arguments),this.type="flattopbottom"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"flat",free:"y"}]}}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return[];let s=[[t.xOf(e.time),r],[t.xOf(n.time),i]],a=this.anchors[2];if(a){let o=t.yOf(a.price,this.paneId);o!=null&&s.push([t.xOf((e.time+n.time)/2),o])}return s}timeExtent(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.time,e.time),max:Math.max(t.time,e.time)}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=t.yOf(e.price,this.paneId),a=t.yOf(n.price,this.paneId);if(s==null||a==null)return null;let o=this.anchors[2];if(!o)return{segments:[[r,s,i,a]],fill:null};let l=t.yOf(o.price,this.paneId);return l==null?null:{segments:[[r,s,i,a],[r,l,i,l]],fill:[[r,s],[i,a],[i,l],[r,l]]}}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=[t.price,e.price],r=this.anchors[2];return r&&n.push(r.price),{min:Math.min(...n),max:Math.max(...n)}}schema(){return{fields:[...te,...tt,...re]}}},tv=2;function vc(){return{midColor:wn,midStyle:"solid",upperColor:kt,upperStyle:"solid",lowerColor:jt,lowerStyle:"solid",upperFill:`${kt}26`,lowerFill:`${jt}26`,showR2:!0}}function nv(t){let e=t.length;if(e<2)return null;let n=0,r=0,i=0,s=0,a=0;for(let f=0;f<e;f+=1){let m=t[f].close;n+=f,r+=m,i+=f*m,s+=f*f,a+=m*m}let o=e*s-n*n,l=o===0?0:(e*i-n*r)/o,c=(r-l*n)/e,u=0;for(let f=0;f<e;f+=1){let m=t[f].close-(c+l*f);u+=m*m}let p=Math.sqrt(u/e),h=Math.sqrt(o*(e*a-r*r)),d=h===0?0:(e*i-n*r)/h;return{t0:t[0].time,t1:t[e-1].time,mid0:c,mid1:c+l*(e-1),dev:tv*p,r2:Math.max(0,Math.min(1,d*d)),n:e}}var rv=class extends fe{constructor(t){super(t),this.type="regressionchannel",this.cachedRange=null,this.reg||(this.reg=vc())}anchorSchema(){return{min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}fit(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=Math.min(e.time,n.time),i=Math.max(e.time,n.time),s=t.barsInRange?.(r,i)??null,a=s?nv(s):null;return a&&(this.cachedRange={min:Math.min(a.mid0,a.mid1)-a.dev,max:Math.max(a.mid0,a.mid1)+a.dev}),a}layout(t){let e=this.fit(t);if(!e)return null;let n=t.yOf(e.mid0,this.paneId),r=t.yOf(e.mid1,this.paneId),i=t.yOf(e.mid0+e.dev,this.paneId),s=t.yOf(e.mid1+e.dev,this.paneId),a=t.yOf(e.mid0-e.dev,this.paneId),o=t.yOf(e.mid1-e.dev,this.paneId);return n==null||r==null||i==null||s==null||a==null||o==null?null:{x0:t.xOf(e.t0),x1:t.xOf(e.t1),midY0:n,midY1:r,upperY0:i,upperY1:s,lowerY0:a,lowerY1:o,r2:e.r2,showR2:this.reg.showR2}}band(t){let e=this.layout(t);return e?[[e.x0,e.upperY0],[e.x1,e.upperY1],[e.x1,e.lowerY1],[e.x0,e.lowerY0]]:null}hitTest(t,e,n,r){let i=this.layout(n);if(!i)return!1;let s=[[i.x0,i.upperY0],[i.x1,i.upperY1],[i.x1,i.lowerY1],[i.x0,i.lowerY0]];return wr(t,e,s)?!0:[[i.x0,i.midY0,i.x1,i.midY1],[i.x0,i.upperY0,i.x1,i.upperY1],[i.x0,i.lowerY0,i.x1,i.lowerY1]].some(o=>Oe(t,e,o[0],o[1],o[2],o[3])<=r)}handlePoints(t){let e=this.layout(t);if(e)return[[e.x0,e.midY0],[e.x1,e.midY1]];let n=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return[];n.push([t.xOf(r.time),i])}return n}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.band(t);if(!e)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"reg.midColor",label:"Midline color",kind:"color",group:"line"},{path:"reg.midStyle",label:"Midline style",kind:"lineStyle",group:"line"},{path:"reg.upperColor",label:"Upper line color",kind:"color",group:"line"},{path:"reg.upperStyle",label:"Upper line style",kind:"lineStyle",group:"line"},{path:"reg.lowerColor",label:"Lower line color",kind:"color",group:"line"},{path:"reg.lowerStyle",label:"Lower line style",kind:"lineStyle",group:"line"},{path:"reg.upperFill",label:"Upper fill",kind:"color",group:"fill"},{path:"reg.lowerFill",label:"Lower fill",kind:"color",group:"fill"},{path:"reg.showR2",label:"Show R\\xB2",kind:"boolean",group:"behavior"}]}}writeProps(){return{...this.reg}}readProps(t){this.reg={...vc(),...t}}},wc=`${Sn}00`;function Sc(){return{midColor:Sn,midStyle:"solid",multiplier:1,upperColor:wc,upperStyle:"solid",lowerColor:wc,lowerStyle:"solid",bandFill:`${Sn}33`}}function iv(t,e){let n=t.length;if(n<1)return null;let r=0;for(let c of t)r+=c.volume>0?c.volume:0;let i=r>0,s=0,a=0,o=0,l=[];for(let c=0;c<n;c+=1){let u=t[c],p=(u.high+u.low+u.close)/3,h=i?Math.max(0,u.volume):1;s+=h,a+=p*h,o+=p*p*h;let d=s>0?a/s:p,f=s>0?Math.max(0,o/s-d*d):0,m=Math.sqrt(f)*e;l.push({time:u.time,mid:d,upper:d+m,lower:d-m})}return l}var sv=class extends fe{constructor(t){super(t),this.type="anchoredvwap",this.cachedRange=null,this.cachedExtent=null,this.vwap||(this.vwap=Sc())}anchorSchema(){return{min:1,max:1,slots:[{role:"anchor",free:"x"}]}}series(t){let e=this.anchors[0];if(!e)return null;let n=t.barsInRange?.(e.time,Number.POSITIVE_INFINITY)??null;if(!n||n.length<1)return null;let r=iv(n.map(i=>({time:i.time,high:i.high,low:i.low,close:i.close,volume:i.volume??0})),this.vwap.multiplier);if(r&&r.length>0){let i=1/0,s=-1/0;for(let a of r)a.lower<i&&(i=a.lower),a.upper>s&&(s=a.upper);this.cachedRange={min:i,max:s},this.cachedExtent={min:r[0].time,max:r[r.length-1].time}}return r}layout(t){let e=this.series(t);if(!e)return null;let n=[],r=[],i=[];for(let s of e){let a=t.xOf(s.time),o=t.yOf(s.mid,this.paneId),l=t.yOf(s.upper,this.paneId),c=t.yOf(s.lower,this.paneId);o==null||l==null||c==null||(n.push([a,o]),r.push([a,l]),i.push([a,c]))}return n.length>0?{mid:n,upper:r,lower:i}:null}bandPolygon(t){return[...t.upper,...[...t.lower].reverse()]}hitTest(t,e,n,r){let i=this.layout(n);return i?wr(t,e,this.bandPolygon(i))?!0:Na(t,e,i.mid,r)||Na(t,e,i.upper,r)||Na(t,e,i.lower,r):!1}handlePoints(t){let e=this.layout(t);if(e&&e.mid.length>0)return[e.mid[0]];let n=this.anchors[0];if(!n)return[];let r=t.yOf(n.price,this.paneId);return r==null?[]:[[t.xOf(n.time),r]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.layout(t);if(!e)return null;let n=[...e.upper,...e.lower],r=n.map(o=>o[0]),i=n.map(o=>o[1]),s=Math.min(...r),a=Math.min(...i);return{x:s,y:a,w:Math.max(...r)-s,h:Math.max(...i)-a}}priceRange(){return this.cachedRange}timeExtent(){return this.cachedExtent}schema(){return{fields:[{path:"vwap.midColor",label:"VWAP color",kind:"color",group:"line"},{path:"vwap.midStyle",label:"VWAP style",kind:"lineStyle",group:"line"},{path:"vwap.multiplier",label:"Band multiplier",kind:"number",min:.5,max:5,step:.5,group:"behavior"},{path:"vwap.upperColor",label:"Upper band color",kind:"color",group:"line"},{path:"vwap.lowerColor",label:"Lower band color",kind:"color",group:"line"},{path:"vwap.bandFill",label:"Band fill",kind:"color",group:"fill"}]}}writeProps(){return{...this.vwap}}readProps(t){this.vwap={...Sc(),...t}}};function Na(t,e,n,r){for(let i=1;i<n.length;i+=1)if(Oe(t,e,n[i-1][0],n[i-1][1],n[i][0],n[i][1])<=r)return!0;return!1}var av=`${kt}66`,ov=`${jt}66`,lv=`${kt}BF`,cv=`${jt}BF`;function Ec(){return{rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:av,downColor:ov,vaUpColor:lv,vaDownColor:cv,showVah:!0,vahColor:wn,vahStyle:"solid",showVal:!0,valColor:wn,valStyle:"solid",showPoc:!0,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:!1,developingPocColor:vn,developingPocStyle:"dotted",showDevelopingVa:!1,developingVaColor:vn,developingVaStyle:"dotted"}}function uv(t,e){return t<0?0:t>=e?e-1:t}function Fc(t,e,n){let r=t.length,i=0,s=0;for(let u=0;u<r;u+=1){let p=t[u].up+t[u].down;i+=p,p>s&&(s=p)}let a=i*Math.min(1,Math.max(0,n)),o=e,l=e,c=s;for(;c<a&&(o>0||l<r-1);){let u=o>0?t[o-1].up+t[o-1].down:-1,p=l<r-1?t[l+1].up+t[l+1].down:-1;p>u?(l+=1,c+=p):(o-=1,c+=u)}return{vaFrom:o,vaTo:l}}function Bc(t,e,n,r){let i=r.volume;if(!(i>0))return;let s=t.length,a=r.close>=r.open?"up":"down",o=new Set;for(let l of[r.open,r.high,r.low,r.close])o.add(uv(Math.floor((l-e)/n),s));for(let l of o)t[l][a]+=i}function Vc(t){let e=0,n=0;for(let r=0;r<t.length;r+=1){let i=t[r].up+t[r].down;i>e&&(e=i,n=r)}return e>0?{poc:n,maxTotal:e}:null}function hv(t,e,n){let r=1/0,i=-1/0;for(let d of t)d.volume>0&&(d.low<r&&(r=d.low),d.high>i&&(i=d.high));if(!Number.isFinite(r))return null;let s=i>r?Math.max(1,Math.round(e)):1,a=i>r?(i-r)/s:1,o=Array.from({length:s},(d,f)=>({price:r+f*a,up:0,down:0}));for(let d of t)Bc(o,r,a,d);let l=Vc(o);if(!l)return null;let{poc:c,maxTotal:u}=l,{vaFrom:p,vaTo:h}=Fc(o,c,n);return{rows:o,rowH:a,min:r,maxTotal:u,poc:c,vaFrom:p,vaTo:h}}function pv(t,e,n,r){let i=hv(t,e,n);if(!i)return null;if(!r||t.length<1)return{profile:i,developingPoc:[],developingVaHigh:[],developingVaLow:[]};let{min:s,rowH:a}=i,o=i.rows.length,l=Array.from({length:o},(h,d)=>({price:s+d*a,up:0,down:0})),c=[],u=[],p=[];for(let h of t){Bc(l,s,a,h);let d=Vc(l);if(!d)continue;let{poc:f}=d,{vaFrom:m,vaTo:_}=Fc(l,f,n);c.push({time:h.time,price:l[f].price+a/2}),u.push({time:h.time,price:l[_].price+a}),p.push({time:h.time,price:l[m].price})}return{profile:i,developingPoc:c,developingVaHigh:u,developingVaLow:p}}var dv=class extends fe{constructor(t){super(t),this.type="fixedrangevp",this.cachedRange=null,this.frvp||(this.frvp=Ec())}anchorSchema(){return{min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}barsInSpan(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=Math.min(e.time,n.time),i=Math.max(e.time,n.time),s=t.barsInRange?.(r,i)??null;return!s||s.length<1?null:s.map(a=>({time:a.time,open:a.open,high:a.high,low:a.low,close:a.close,volume:a.volume??0}))}compute(t){let e=this.barsInSpan(t);if(!e)return null;let n=this.frvp,r=n.showDevelopingPoc||n.showDevelopingVa,i=pv(e,n.rows,n.valueAreaPct/100,r);if(i){let{profile:s}=i;this.cachedRange={min:s.min,max:s.min+s.rowH*s.rows.length}}return i}layout(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=this.compute(t);if(!r)return null;let{profile:i}=r,s=Math.min(e.time,n.time),a=Math.max(e.time,n.time),o=t.xOf(s),l=t.xOf(a),c=Math.abs(l-o),u=Math.max(1,Math.min(100,Math.max(0,this.frvp.widthPct))/100*c),p=this.frvp.anchor==="left",h=p?Math.min(o,l):Math.max(o,l),d=p?1:-1,f=[];for(let w=0;w<=i.rows.length;w+=1){let I=t.yOf(i.min+w*i.rowH,this.paneId);if(I==null)return null;f.push(I)}let m=w=>t.yOf(w,this.paneId),_=i.rows[i.vaTo].price+i.rowH,b=i.rows[i.vaFrom].price,v=i.rows[i.poc].price+i.rowH/2,S=w=>{let I=[];for(let E of w){let A=m(E.price);A!=null&&I.push([t.xOf(E.time),A])}return I};return{x0:Math.min(o,l),x1:Math.max(o,l),anchorX:h,maxW:u,grow:d,profile:i,yEdges:f,vahY:m(_),valY:m(b),pocY:m(v),developingPoc:S(r.developingPoc),developingVaHigh:S(r.developingVaHigh),developingVaLow:S(r.developingVaLow)}}hitTest(t,e,n,r){let i=this.layout(n);if(!i)return!1;let s=i.grow===1?i.anchorX:i.anchorX-i.maxW,a=i.grow===1?i.anchorX+i.maxW:i.anchorX,o=Math.min(i.yEdges[0],i.yEdges[i.yEdges.length-1]),l=Math.max(i.yEdges[0],i.yEdges[i.yEdges.length-1]);if(wr(t,e,[[s,o],[a,o],[a,l],[s,l]]))return!0;let c=[[i.x0,i.vahY],[i.x0,i.valY],[i.x0,i.pocY]];for(let[,u]of c)if(u!=null&&Oe(t,e,i.x0,u,i.x1,u)<=r)return!0;for(let u of[i.developingPoc,i.developingVaHigh,i.developingVaLow])for(let p=1;p<u.length;p+=1)if(Oe(t,e,u[p-1][0],u[p-1][1],u[p][0],u[p][1])<=r)return!0;return!1}handlePoints(t){let e=this.layout(t);if(e&&e.pocY!=null)return[[e.x0,e.pocY],[e.x1,e.pocY]];let n=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return[];n.push([t.xOf(r.time),i])}return n}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.layout(t);if(!e)return null;let n=Math.min(e.x0,e.grow===1?e.anchorX:e.anchorX-e.maxW),r=Math.max(e.x1,e.grow===1?e.anchorX+e.maxW:e.anchorX),i=Math.min(e.yEdges[0],e.yEdges[e.yEdges.length-1]),s=Math.max(e.yEdges[0],e.yEdges[e.yEdges.length-1]);return{x:n,y:i,w:r-n,h:s-i}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"frvp.rows",label:"Rows",kind:"number",min:1,max:500,step:1,group:"behavior"},{path:"frvp.valueAreaPct",label:"Value Area",kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.widthPct",label:"Width %",kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.anchor",label:"Anchor",kind:"select",options:[{value:"right",label:"Right"},{value:"left",label:"Left"}],group:"behavior"},{path:"frvp.upColor",label:"Up Volume",kind:"color",group:"fill"},{path:"frvp.downColor",label:"Down Volume",kind:"color",group:"fill"},{path:"frvp.vaUpColor",label:"Value Area Up",kind:"color",group:"fill"},{path:"frvp.vaDownColor",label:"Value Area Down",kind:"color",group:"fill"},{path:"frvp.showVah",label:"VAH",kind:"boolean",group:"line"},{path:"frvp.vahColor",label:"VAH color",kind:"color",group:"line"},{path:"frvp.vahStyle",label:"VAH style",kind:"lineStyle",options:qn,group:"line"},{path:"frvp.showVal",label:"VAL",kind:"boolean",group:"line"},{path:"frvp.valColor",label:"VAL color",kind:"color",group:"line"},{path:"frvp.valStyle",label:"VAL style",kind:"lineStyle",options:qn,group:"line"},{path:"frvp.showPoc",label:"POC",kind:"boolean",group:"line"},{path:"frvp.pocColor",label:"POC color",kind:"color",group:"line"},{path:"frvp.pocStyle",label:"POC style",kind:"lineStyle",options:qn,group:"line"},{path:"frvp.showDevelopingPoc",label:"Developing POC",kind:"boolean",group:"line"},{path:"frvp.developingPocColor",label:"Developing POC color",kind:"color",group:"line"},{path:"frvp.developingPocStyle",label:"Developing POC style",kind:"lineStyle",options:qn,group:"line"},{path:"frvp.showDevelopingVa",label:"Developing VA",kind:"boolean",group:"line"},{path:"frvp.developingVaColor",label:"Developing VA color",kind:"color",group:"line"},{path:"frvp.developingVaStyle",label:"Developing VA style",kind:"lineStyle",options:qn,group:"line"}]}}writeProps(){return{...this.frvp}}readProps(t){this.frvp={...Ec(),...t}}},fv=class extends At{constructor(){super(...arguments),this.type="pitchfork"}anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=f=>{let m=t.yOf(f.price,this.paneId);return m==null?null:[t.xOf(f.time),m]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(a);if(!o)return null;let l=(s[0]+o[0])/2,c=(s[1]+o[1])/2,u=l-i[0],p=c-i[1],h=t.width,d=t.height;return{segments:[Ye(i[0],i[1],l,c,"right",h,d),Ye(s[0],s[1],s[0]+u,s[1]+p,"right",h,d),Ye(o[0],o[1],o[0]+u,o[1]+p,"right",h,d),[s[0],s[1],o[0],o[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...re]}}},Wc=class extends At{anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=m=>{let _=t.yOf(m.price,this.paneId);return _==null?null:[t.xOf(m.time),_]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(this.medianStart(e,n,a)),l=r(a);if(!o||!l)return null;let c=(s[0]+l[0])/2,u=(s[1]+l[1])/2,p=c-o[0],h=u-o[1],d=t.width,f=t.height;return{segments:[Ye(o[0],o[1],c,u,"right",d,f),Ye(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Ye(l[0],l[1],l[0]+p,l[1]+h,"right",d,f),[s[0],s[1],l[0],l[1]],[i[0],i[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...re]}}},mv=class extends Wc{constructor(){super(...arguments),this.type="schiffpitchfork"}medianStart(t,e){return{time:t.time,price:(t.price+e.price)/2}}},yv=class extends Wc{constructor(){super(...arguments),this.type="modifiedschiffpitchfork"}medianStart(t,e){return{time:(t.time+e.time)/2,price:(t.price+e.price)/2}}},gv=class extends At{constructor(){super(...arguments),this.type="insidepitchfork"}anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=m=>{let _=t.yOf(m.price,this.paneId);return _==null?null:[t.xOf(m.time),_]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r({time:(e.time+n.time)/2,price:(e.price+n.price)/2}),l=r(a);if(!o||!l)return null;let c=(s[0]+l[0])/2,u=(s[1]+l[1])/2,p=l[0]-o[0],h=l[1]-o[1],d=t.width,f=t.height;return{segments:[Ye(c,u,c+p,u+h,"right",d,f),Ye(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Ye(l[0],l[1],l[0]+p,l[1]+h,"right",d,f),[s[0],s[1],l[0],l[1]],[o[0],o[1],l[0],l[1]],[i[0],i[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...re]}}},xv=class extends fe{constructor(){super(...arguments),this.type="arrow"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&Oe(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,{path:"style.arrowRight",label:"Head (end)",kind:"boolean",group:"line"},{path:"style.arrowLeft",label:"Head (start)",kind:"boolean",group:"line"},...re]}}},Cc=48,_v=class extends fe{constructor(){super(...arguments),this.type="ellipse"}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}oval(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:(s+a)/2,cy:(r+i)/2,rx:Math.abs(a-s)/2,ry:Math.abs(i-r)/2}}perimeter(t){let e=[];for(let n=0;n<=Cc;n+=1){let r=n/Cc*Math.PI*2;e.push([t.cx+t.rx*Math.cos(r),t.cy+t.ry*Math.sin(r)])}return e}hitTest(t,e,n,r){let i=this.oval(n);if(!i||i.rx<1||i.ry<1)return!1;let s=((t-i.cx)/i.rx)**2+((e-i.cy)/i.ry)**2;return this.style.fillColor&&s<=1?!0:Aa(t,e,this.perimeter(i))<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.oval(t);return e?{x:e.cx-e.rx,y:e.cy-e.ry,w:e.rx*2,h:e.ry*2}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...tt,...re]}}},bv=class extends At{constructor(){super(...arguments),this.type="triangle"}anchorSchema(){return{min:3,max:3,slots:[{role:"v1",free:"both"},{role:"v2",free:"both"},{role:"v3",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=l=>{let c=t.yOf(l.price,this.paneId);return c==null?null:[t.xOf(l.time),c]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(a);return o?{segments:[[i[0],i[1],s[0],s[1]],[s[0],s[1],o[0],o[1]],[o[0],o[1],i[0],i[1]]],fill:[i,s,o]}:null}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...tt,...re]}}},vv=512,Pa=class extends At{anchorSchema(){return{min:2,max:vv,slots:[]}}geometry(t){let e=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return null;e.push([t.xOf(r.time),i])}if(e.length<2)return null;let n=[];for(let r=1;r<e.length;r+=1)n.push([e[r-1][0],e[r-1][1],e[r][0],e[r][1]]);return{segments:n,fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...re]}}},wv=class extends Pa{constructor(){super(...arguments),this.type="polyline"}},$c=class extends Pa{placementMode(){return"freehand"}handlePoints(t){return[]}bounds(t){let e=[],n=[];for(let s of this.anchors){let a=t.yOf(s.price,this.paneId);a!=null&&(e.push(t.xOf(s.time)),n.push(a))}if(e.length===0)return null;let r=Math.min(...e),i=Math.min(...n);return{x:r,y:i,w:Math.max(...e)-r,h:Math.max(...n)-i}}},Sv=class extends $c{constructor(){super(...arguments),this.type="freehand"}},Ev=[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Width",kind:"number",min:4,max:60,step:1,group:"line"}],Cv=class extends $c{constructor(){super(...arguments),this.type="highlighter"}schema(){return{fields:Ev}}},Iv=class extends fe{constructor(){super(...arguments),this.type="circle"}anchorSchema(){return{min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}geom(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:s,cy:r,r:Math.hypot(a-s,i-r)}}hitTest(t,e,n,r){let i=this.geom(n);if(!i||i.r<1)return!1;let s=Math.hypot(t-i.cx,e-i.cy);return this.style.fillColor&&s<=i.r?!0:Math.abs(s-i.r)<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.geom(t);return e?{x:e.cx-e.r,y:e.cy-e.r,w:e.r*2,h:e.r*2}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...tt,...re]}}},Nv=class extends At{constructor(){super(...arguments),this.type="rotatedrect"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"w",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.px(t,2);if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=n[0]-e[0],s=n[1]-e[1],a=Math.hypot(i,s);if(a<1e-6)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let o=-s/a,l=i/a,c=(r[0]-e[0])*o+(r[1]-e[1])*l,u=o*c,p=l*c,h=e,d=n,f=[n[0]+u,n[1]+p],m=[e[0]+u,e[1]+p];return{segments:[[h[0],h[1],d[0],d[1]],[d[0],d[1],f[0],f[1]],[f[0],f[1],m[0],m[1]],[m[0],m[1],h[0],h[1]]],fill:[h,d,f,m]}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te.map(t=>({...t,label:t.label.replace("Line","Border")})),...tt,...re]}}},kv=class extends Pa{constructor(){super(...arguments),this.type="path"}},Ic=40,Av=class extends At{constructor(){super(...arguments),this.type="arc"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"apex",free:"both"}]}}pinApex(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];t&&e&&n&&(n.time=(t.time+e.time)/2)}onPlaced(){this.pinApex()}constrainHandleDrag(){this.pinApex()}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.anchors[2];if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=t.yOf(r.price,this.paneId);if(i==null)return null;let s=(e[0]+n[0])/2,a=(e[1]+n[1])/2,o=(n[0]-e[0])/2,l=(n[1]-e[1])/2,c=Math.hypot(o,l);if(c<1e-6)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let u=-l/c,p=o/c,h=(i-a)*p;h<0&&(u=-u,p=-p);let d=Math.abs(h),f=[];for(let _=0;_<=Ic;_+=1){let b=_/Ic*Math.PI,v=Math.cos(b),S=Math.sin(b);f.push([s+v*o+S*d*u,a+v*l+S*d*p])}let m=[];for(let _=1;_<f.length;_+=1)m.push([f[_-1][0],f[_-1][1],f[_][0],f[_][1]]);return m.push([f[f.length-1][0],f[f.length-1][1],f[0][0],f[0][1]]),{segments:m,fill:f}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te.map(t=>({...t,label:t.label.replace("Line","Border")})),...tt,...re]}}},Nc=40,Mv=class extends At{constructor(){super(...arguments),this.type="curve"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"control",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.px(t,2);if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=[];for(let a=0;a<=Nc;a+=1){let o=a/Nc,l=1-o;i.push([l*l*e[0]+2*l*o*r[0]+o*o*n[0],l*l*e[1]+2*l*o*r[1]+o*o*n[1]])}let s=[];for(let a=1;a<i.length;a+=1)s.push([i[a-1][0],i[a-1][1],i[a][0],i[a][1]]);return{segments:s,fill:i}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...te,...tt,...re]}}},Tv={head:11,headW:9,stemW:3.5,len:22},jc=class extends fe{anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}glyphPoints(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=t.xOf(e.time),{head:i,headW:s,stemW:a,len:o}=Tv,l=[[0,0],[-s,i],[-a,i],[-a,o],[a,o],[a,i],[s,i]],c=this.dir(),u=([p,h])=>{switch(c){case"up":return[p,h];case"down":return[p,-h];case"left":return[h,p];default:return[-h,p]}};return l.map(p=>{let[h,d]=u(p);return[r+h,n+d]})}hitTest(t,e,n,r){let i=this.glyphPoints(n);return i!=null&&wr(t,e,i)}handlePoints(t){let e=this.anchors[0];if(!e)return[];let n=t.yOf(e.price,this.paneId);return n==null?[]:[[t.xOf(e.time),n]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.glyphPoints(t);if(!e)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}schema(){return{fields:[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},...re]}}},Pv=class extends jc{constructor(){super(...arguments),this.type="arrowmarkup"}dir(){return"up"}},Dv=class extends jc{constructor(){super(...arguments),this.type="arrowmarkdown"}dir(){return"down"}},Rv=["\\u2605","\\u2606","\\u25CF","\\u25C6","\\u25B2","\\u25BC","\\u27A4","\\u2691","\\u271A","\\u2715","\\u2764","\\u2666"],Ov=["small","normal","large","huge"],kc={small:16,normal:22,large:32,huge:44},Uc=class extends fe{constructor(t){super(t),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal")}sizePx(){return kc[this.size]??kc.normal}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}center(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.center(n);if(!i)return!1;let s=this.sizePx()/2+r;return Math.abs(t-i[0])<=s&&Math.abs(e-i[1])<=s}handlePoints(t){let e=this.center(t);return e?[e]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.center(t);if(!e)return null;let n=this.sizePx();return{x:e[0]-n/2,y:e[1]-n/2,w:n,h:n}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}schema(){return{fields:[{path:"glyph",label:"Icon",kind:"select",options:Rv.map(t=>({value:t,label:t})),group:"line"},{path:"size",label:"Size",kind:"select",options:Ov.map(t=>({value:t,label:t})),group:"line"},{path:"style.lineColor",label:"Color",kind:"color",group:"line"},...re]}}writeProps(){return{glyph:this.glyph,size:this.size}}readProps(t){typeof t.glyph=="string"&&(this.glyph=t.glyph),typeof t.size=="string"&&(this.size=t.size)}},Lv=class extends Uc{constructor(){super(...arguments),this.type="flagmark"}defaultGlyph(){return"\\u2691"}},Fv=class extends Uc{constructor(){super(...arguments),this.type="iconstamp"}defaultGlyph(){return"\\u2605"}},Ac=t=>t==="small"||t==="normal"||t==="large"||t==="huge";function Bv(t){if(!t||typeof t!="object")return null;let e=t;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==!1,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var Mt=class extends fe{constructor(t){super(t),this.levels||(this.levels=this.defaultLevels().map(e=>({...e}))),this.numbersSize||(this.numbersSize="small"),this.labelsSize||(this.labelsSize="normal")}fillBands(t){return[]}editableLevels(){return this.levels}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}hitTest(t,e,n,r){let i=this.entryLines(n);return i!=null&&i.some(s=>Oe(t,e,s.x1,s.y1,s.x2,s.y2)<=r)}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}schema(){return{fields:te.filter(t=>t.path!=="style.lineColor")}}writeProps(){return{levels:this.levels.map(t=>({...t})),numbersSize:this.numbersSize,labelsSize:this.labelsSize}}readProps(t){if(Array.isArray(t.levels)){let e=t.levels.map(Bv).filter(n=>n!=null);e.length&&(this.levels=e)}Ac(t.numbersSize)&&(this.numbersSize=t.numbersSize),Ac(t.labelsSize)&&(this.labelsSize=t.labelsSize)}},zc=class extends Mt{levelLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=Math.min(r,i),a=Math.max(r,i),o=n.price-e.price,l=[];for(let c of this.levels){if(!c.enabled)continue;let u=e.price+c.ratio*o,p=t.yOf(u,this.paneId);p!=null&&l.push({ratio:c.ratio,color:c.color,label:c.label,price:u,x1:s,x2:a,y:p})}return l}entryLines(t){let e=this.levelLines(t);return e?e.map(n=>({color:n.color,label:n.label,x1:n.x1,y1:n.y,x2:n.x2,y2:n.y,numberText:`${n.ratio} (${n.price.toFixed(2)})`,numberX:n.x1+4,numberY:n.y-7,numberAlign:"left",labelX:(n.x1+n.x2)/2,labelY:n.y-7})):null}fillBands(t){let e=this.levelLines(t);if(!e)return[];let n=[];for(let r=1;r<e.length;r+=1){let i=e[r-1],s=e[r];n.push({color:s.color,x:i.x1,y:Math.min(i.y,s.y),w:i.x2-i.x1,h:Math.abs(s.y-i.y)})}return n}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=e.price-t.price,r=this.levels.filter(i=>i.enabled).map(i=>t.price+i.ratio*n);return r.length===0?null:{min:Math.min(...r),max:Math.max(...r)}}},Hn=wn,En=jt,Cn=Sa,Ti="#4caf50",vr=kt,In=Sn,Ri="#9c27b0",Vv="#e91e63",qc="#26a69a",Wv="#ab47bc",$v="#ef5350",jv="#ffb74d",Uv="#38c0fd",Hc="#b2b5be",br=[Uv,In,vr,Ti,Cn,En,Vv,Ri,Hn,qc,Wv,$v];function Kc(t){return br[(t%br.length+br.length)%br.length]}var zv=[[0,Hn],[.125,En],[.236,En],[.25,En],[.382,Cn],[.5,Ti],[.618,vr],[.75,In],[.786,In],[1,Hn],[1.272,In],[1.382,Cn],[1.618,En],[2,Hn],[2.382,Cn],[2.618,Cn],[3,Hn],[4.236,Ti],[6.854,vr],[11.09,In]];function qv(t,e=0){return zv.find(([n])=>n===t)?.[1]??Kc(e)}function nt(t){return t.map((e,n)=>{let r=typeof e=="number"?{ratio:e}:e;return{ratio:r.ratio,color:r.color??qv(r.ratio,n),enabled:r.enabled!==!1,...r.label?{label:r.label}:{}}})}function Hv(t,e=t){return Array.from({length:t},(n,r)=>({ratio:r+1,color:Kc(r),enabled:r<e,label:String(r+1)}))}var Kv=nt([0,.236,.382,.5,.618,.786,1]),Yv=class extends zc{constructor(){super(...arguments),this.type="fibretracement"}defaultLevels(){return Kv}},Gv=nt([0,.382,.618,1,1.272,1.618,{ratio:2.618,color:Ri}]),Xv=class extends zc{constructor(){super(...arguments),this.type="fibextension"}defaultLevels(){return Gv}},Zv=nt([0,.382,.5,.618,1,1.618,{ratio:2.618,color:Ri}]),Qv=class extends Mt{constructor(){super(...arguments),this.type="fibextensiontrend"}anchorSchema(){return{min:3,max:3,slots:[{role:"a",free:"both"},{role:"b",free:"both"},{role:"c",free:"both"}]}}defaultLevels(){return Zv}entryLines(t){let e=this.anchors[0],n=this.anchors[1],r=this.anchors[2];if(!e||!n||!r)return null;let i=n.price-e.price,s=[t.xOf(e.time),t.xOf(n.time),t.xOf(r.time)],a=Math.min(...s),o=Math.max(...s),l=[];for(let c of this.levels){if(!c.enabled)continue;let u=r.price+c.ratio*i,p=t.yOf(u,this.paneId);p!=null&&l.push({color:c.color,label:c.label,x1:a,y1:p,x2:o,y2:p,numberText:`${c.ratio} (${u.toFixed(2)})`,numberX:a+4,numberY:p-7,numberAlign:"left",labelX:(a+o)/2,labelY:p-7})}return l}priceRange(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];if(!t||!e||!n)return null;let r=e.price-t.price,i=this.levels.filter(s=>s.enabled).map(s=>n.price+s.ratio*r);return i.push(t.price,e.price,n.price),{min:Math.min(...i),max:Math.max(...i)}}},Jv=nt([.236,.382,.5,.618,.786,1]),ew=class extends Mt{constructor(){super(...arguments),this.type="fibfan"}defaultLevels(){return Jv}fanLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.yOf(e.price,this.paneId);if(i==null)return null;let s=t.xOf(n.time),a=n.price-e.price,o=[];for(let l of this.levels){if(!l.enabled)continue;let c=t.yOf(e.price+l.ratio*a,this.paneId);if(c==null)continue;let[u,p,h,d]=Ye(r,i,s,c,"right",t.width,t.height);o.push({ratio:l.ratio,color:l.color,label:l.label,x1:u,y1:p,x2:h,y2:d,labelX:s+5,labelY:c})}return o}entryLines(t){let e=this.fanLines(t);return e?e.map(n=>({color:n.color,label:n.label,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,numberText:String(n.ratio),numberX:n.labelX,numberY:n.labelY,numberAlign:"left",labelX:n.labelX,labelY:n.labelY+13})):null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},tw=[0,1,2,3,5,8,13,21,34].map(t=>({ratio:t,color:R,enabled:!0})),nw=class extends Mt{constructor(){super(...arguments),this.type="fibtimezones"}defaultLevels(){return tw}zoneLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=n.time-e.time;if(Math.abs(r)<1e-9)return null;let i=[];for(let s of this.levels)s.enabled&&i.push({n:s.ratio,color:s.color,label:s.label,x:t.xOf(e.time+s.ratio*r)});return i}entryLines(t){let e=this.zoneLines(t);if(!e)return null;let n=t.height;return e.map(r=>({color:r.color,label:r.label,x1:r.x,y1:0,x2:r.x,y2:n,numberText:String(r.n),numberX:r.x,numberY:9,numberAlign:"center",labelX:r.x,labelY:24}))}priceRange(){return null}timeExtent(){return null}},rw=nt([0,.236,.382,.5,.618,.786,1,1.618,2.618]),iw=class extends Mt{constructor(){super(...arguments),this.type="fibchannel"}defaultLevels(){return rw}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"both"}]}}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=0,l=0,c=this.anchors[2];if(c){let p=t.yOf(c.price,this.paneId);if(p==null)return null;o=t.xOf(c.time)-s,l=p-r}let u=[];for(let p of this.levels){if(!p.enabled)continue;let h=p.ratio*o,d=p.ratio*l,f=a+h,m=i+d;u.push({color:p.color,label:p.label,x1:s+h,y1:r+d,x2:f,y2:m,numberText:String(p.ratio),numberX:f+5,numberY:m,numberAlign:"left",labelX:f+5,labelY:m+13})}return u}priceRange(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];if(!t||!e)return null;let r=n?n.price-t.price:0,i=1/0,s=-1/0;for(let a of this.levels)if(a.enabled)for(let o of[t.price,e.price]){let l=o+a.ratio*r;l<i&&(i=l),l>s&&(s=l)}return i<=s?{min:i,max:s}:null}},sw=nt([0,.236,.382,.5,.618,.786,1]),aw=class extends Mt{constructor(){super(...arguments),this.type="fibspeedfan"}defaultLevels(){return sw}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),o=t.xOf(n.time)-s,l=i-r,c=o>=0?"right":"left",u=t.width,p=t.height,h=[];for(let d of this.levels){if(!d.enabled)continue;let f=s+o,m=r+l*d.ratio,_=Ye(s,r,f,m,c,u,p);if(h.push({color:d.color,label:d.label,x1:_[0],y1:_[1],x2:_[2],y2:_[3],numberText:String(d.ratio),numberX:c==="right"?f+5:f-5,numberY:m,numberAlign:c==="right"?"left":"right",labelX:f,labelY:m}),d.ratio===1)continue;let b=s+o*d.ratio,v=r+l,S=Ye(s,r,b,v,c,u,p);h.push({color:d.color,label:d.label,x1:S[0],y1:S[1],x2:S[2],y2:S[3],numberText:String(d.ratio),numberX:b,numberY:v+(l>=0?12:-12),numberAlign:"center",labelX:b,labelY:v+12})}return h}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},ow=nt([0,.382,{ratio:.5,enabled:!1},.618,1,1.382,1.618,2,2.382,2.618,3]),lw=class extends Mt{constructor(){super(...arguments),this.type="trendfibtime"}defaultLevels(){return ow}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"p3",free:"both"}]}}entryLines(t){let e=this.anchors[0],n=this.anchors[1],r=this.anchors[2];if(!e||!n||!r)return null;let i=n.time-e.time;if(Math.abs(i)<1e-9)return null;let s=t.height,a=[];for(let o of this.levels){if(!o.enabled)continue;let l=t.xOf(r.time+o.ratio*i);a.push({color:o.color,label:o.label,x1:l,y1:0,x2:l,y2:s,numberText:String(o.ratio),numberX:l,numberY:9,numberAlign:"center",labelX:l,labelY:24})}return a}priceRange(){return null}timeExtent(){return null}};function cw(t,e,n){if(n-e>=Math.PI*2-.001)return!0;let r=t-e,i=Math.PI*2;for(;r<0;)r+=i;for(;r>=i;)r-=i;return r<=n-e+1e-6}var Da=class extends Mt{boundingLines(t){return[]}entryLines(t){return[]}hitTest(t,e,n,r){let i=this.radial(n);if(i){let s=Math.hypot(t-i.cx,e-i.cy),a=Math.atan2(e-i.cy,t-i.cx);if(cw(a,i.a0,i.a1)){for(let o of this.levels)if(o.enabled&&Math.abs(s-i.R0*o.ratio)<=r)return!0}}return this.boundingLines(n).some(s=>Oe(t,e,s[0],s[1],s[2],s[3])<=r)}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}},uw=nt([.236,.382,.5,.618,.786,1,1.618,2.618]),hw=class extends Da{constructor(){super(...arguments),this.type="fibcircles"}defaultLevels(){return uw}radial(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:s,cy:r,R0:Math.hypot(a-s,i-r),a0:0,a1:Math.PI*2}}},pw=nt([.236,.382,.5,.618,.786,1,1.618,2.618]),dw=class extends Da{constructor(){super(...arguments),this.type="fibarcs"}defaultLevels(){return pw}pts(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{cx:t.xOf(e.time),cy:r,ex:t.xOf(n.time),ey:i}}radial(t){let e=this.pts(t);if(!e)return null;let n=Math.hypot(e.ex-e.cx,e.ey-e.cy),r=Math.atan2(e.ey-e.cy,e.ex-e.cx);return{cx:e.cx,cy:e.cy,R0:n,a0:r-Math.PI/2,a1:r+Math.PI/2}}boundingLines(t){let e=this.pts(t);return e?[[e.cx,e.cy,e.ex,e.ey]]:[]}},fw=nt([.236,.382,.5,.618,.786,1]),mw=class extends Da{constructor(){super(...arguments),this.type="fibwedge"}defaultLevels(){return fw}anchorSchema(){return{min:3,max:3,slots:[{role:"apex",free:"both"},{role:"radius",free:"both"},{role:"angle",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}radial(t){let e=this.px(t,0),n=this.px(t,1),r=this.px(t,2);if(!e||!n||!r)return null;let i=Math.hypot(n[0]-e[0],n[1]-e[1]);if(i<1)return null;let s=Math.atan2(n[1]-e[1],n[0]-e[0]),a=Math.atan2(r[1]-e[1],r[0]-e[0]),o=Math.min(s,a),l=Math.max(s,a);return l-o>Math.PI&&([o,l]=[l,o+Math.PI*2]),{cx:e[0],cy:e[1],R0:i,a0:o,a1:l}}boundingLines(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return[];let r=[[e[0],e[1],n[0],n[1]]],i=this.px(t,2);if(i){let s=Math.hypot(n[0]-e[0],n[1]-e[1]),a=Math.hypot(i[0]-e[0],i[1]-e[1]);a>1e-6&&r.push([e[0],e[1],e[0]+(i[0]-e[0])/a*s,e[1]+(i[1]-e[1])/a*s])}return r}},yw=1.6180339887,Mc=Math.log(yw)/(Math.PI/2),gw=Math.PI/64,xw=Math.PI,_w=.5,bw=class extends fe{constructor(){super(...arguments),this.type="fibspiral"}anchorSchema(){return{min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}spiralPoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=Math.hypot(a-s,i-r);if(o<1)return null;let l=Math.atan2(i-r,a-s),c=Math.max(Math.log(_w/o)/Mc,-8*Math.PI*2),u=[];for(let p=c;p<=xw;p+=gw){let h=o*Math.exp(Mc*p),d=l+p;u.push([s+h*Math.cos(d),r+h*Math.sin(d)])}return u}hitTest(t,e,n,r){let i=this.spiralPoints(n);return i!=null&&i.length>=2&&Aa(t,e,i)<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length<2)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,...re]}}},vw=nt([{ratio:.125,color:En,label:"1/8"},{ratio:.25,color:Cn,label:"1/4"},{ratio:.333,color:jv,label:"1/3"},{ratio:.5,color:Ti,label:"1/2"},{ratio:1,color:Hc,label:"1/1"},{ratio:2,color:vr,label:"2/1"},{ratio:3,color:In,label:"3/1"},{ratio:4,color:qc,label:"4/1"},{ratio:8,color:Ri,label:"8/1"}]),ww=class extends Mt{constructor(){super(...arguments),this.type="gannfan"}defaultLevels(){return vw}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.yOf(e.price,this.paneId);if(i==null)return null;let s=t.xOf(n.time),a=n.price-e.price,o=[];for(let l of this.levels){if(!l.enabled)continue;let c=t.yOf(e.price+a*l.ratio,this.paneId);if(c==null)continue;let[u,p,h,d]=Ye(r,i,s,c,"right",t.width,t.height);o.push({color:l.color,x1:u,y1:p,x2:h,y2:d,numberText:l.label??String(l.ratio),numberX:s+5,numberY:c,numberAlign:"left",labelX:s+5,labelY:c})}return o}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},Sw=nt([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),Ew=class extends Mt{constructor(){super(...arguments),this.type="gannbox"}defaultLevels(){return Sw}corners(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=t.yOf(e.price,this.paneId),a=t.yOf(n.price,this.paneId);return s==null||a==null?null:{c1:e,c2:n,left:Math.min(r,i),right:Math.max(r,i),top:Math.min(s,a),bot:Math.max(s,a)}}entryLines(t){let e=this.corners(t);if(!e)return null;let{c1:n,c2:r,left:i,right:s,top:a,bot:o}=e,l=[];for(let u of this.levels){if(!u.enabled)continue;let p=t.yOf(n.price+u.ratio*(r.price-n.price),this.paneId);p!=null&&l.push({color:u.color,x1:i,y1:p,x2:s,y2:p,numberText:u.label??String(u.ratio),numberX:i-5,numberY:p,numberAlign:"right",labelX:i,labelY:p});let h=t.xOf(n.time+u.ratio*(r.time-n.time));l.push({color:u.color,x1:h,y1:a,x2:h,y2:o,numberText:"",numberX:h,numberY:a,numberAlign:"center",labelX:h,labelY:a})}let c=this.levels.find(u=>u.ratio===1)?.color??Hn;return l.push({color:c,x1:i,y1:a,x2:s,y2:o,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),l.push({color:c,x1:i,y1:o,x2:s,y2:a,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),l}hitTest(t,e,n,r){let i=this.corners(n);return i!=null&&Zt(t,e,i.left,i.top,i.right,i.bot,r)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},Cw=nt([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),Iw=[{label:"3x1",x:3,y:1,color:En},{label:"2x1",x:2,y:1,color:Cn},{label:"1x1",x:1,y:1,color:Hc},{label:"1x2",x:1,y:2,color:vr},{label:"1x3",x:1,y:3,color:In}];var Nw=class extends Mt{constructor(){super(...arguments),this.type="gannsquare"}defaultLevels(){return Cw}box(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{ox:s,oy:r,bx:a-s,py:i-r,left:Math.min(s,a),top:Math.min(r,i),right:Math.max(s,a),bot:Math.max(r,i)}}arcGeom(t){let e=this.box(t);return e?{ox:e.ox,oy:e.oy,bx:e.bx,py:e.py}:null}entryLines(t){let e=this.box(t);if(!e)return null;let n=this.anchors[0],r=this.anchors[1],i=[];for(let s of this.levels){if(!s.enabled)continue;let a=t.yOf(n.price+s.ratio*(r.price-n.price),this.paneId);a!=null&&i.push({color:s.color,x1:e.left,y1:a,x2:e.right,y2:a,numberText:s.label??String(s.ratio),numberX:e.left-5,numberY:a,numberAlign:"right",labelX:e.left,labelY:a});let o=t.xOf(n.time+s.ratio*(r.time-n.time));i.push({color:s.color,x1:o,y1:e.top,x2:o,y2:e.bot,numberText:"",numberX:o,numberY:e.top,numberAlign:"center",labelX:o,labelY:e.top})}for(let s of Iw){let a,o;s.x>s.y?(a=e.ox+e.bx,o=e.oy+s.y/s.x*e.py):(o=e.oy+e.py,a=e.ox+s.x/s.y*e.bx),i.push({color:s.color,x1:e.ox,y1:e.oy,x2:a,y2:o,numberText:s.label,numberX:a+4,numberY:o,numberAlign:"left",labelX:a+4,labelY:o})}return i}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Zt(t,e,i.left,i.top,i.right,i.bot,r)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}};var kw=24,Aw=.75;function Mw(t,e){if(!Number.isInteger(t)||!Number.isInteger(e)||e<=0)return!1;let n=t*t-1;return e%2===1?n%e===0:e%8===0?n%e!==0?!1:n/e%2!==0:!1}function Tw(t){let e=[];for(let n=0;n<t;n+=1)Mw(n,t)&&e.push(n);return e}var Pw=class extends fe{constructor(t){super(t),this.type="dedekind",this.maxCurvature===void 0&&(this.maxCurvature=kw)}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}box(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=Math.min(t.xOf(e.time),t.xOf(n.time)),a=Math.max(t.xOf(e.time),t.xOf(n.time)),o=Math.min(r,i),l=Math.max(r,i),c=a-s,u=l-o;if(c<1||u<1)return null;let p=u,h=c/p;return{left:s,right:a,top:o,bot:l,unitPx:p,x0:0,realSpan:h}}geodesics(t){let e=this.box(t);if(!e)return null;let{left:n,top:r,bot:i,unitPx:s,x0:a,realSpan:o}=e,l=Math.max(1,Math.min(64,Math.round(this.maxCurvature))),c=a-1/l,u=a+o+1/l,p=n+o*s,h=[],d=Math.floor(c*2),f=Math.ceil(u*2);for(let m=d;m<=f;m+=1){if(m%2===0)continue;let _=n+(m/2-a)*s;_<n-.5||_>p+.5||h.push({kind:"vline",x:_,y0:i,y1:r})}for(let m=1;m<=l;m+=1){let _=1/m,b=_*s;if(b<Aw)continue;let v=Tw(m);if(v.length===0)continue;let S=Math.floor(c)-1,w=Math.ceil(u)+1;for(let I=S;I<=w;I+=1)for(let E of v){let A=E/m+I;if(A+_<c||A-_>u)continue;let F=n+(A-a)*s;F+b<n-1||F-b>p+1||h.push({kind:"arc",cx:F,cy:i,r:b})}}return h}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Zt(t,e,i.left,i.top,i.right,i.bot,r)}handlePoints(t){let e=this.box(t);return e?[[e.left,e.top],[e.right,e.bot]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.box(t);return e?{x:e.left,y:e.top,w:e.right-e.left,h:e.bot-e.top}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...te,{path:"maxCurvature",label:"Max curvature",kind:"number",min:4,max:64,step:4,group:"behavior"},...re]}}writeProps(){return{maxCurvature:this.maxCurvature}}readProps(t){typeof t.maxCurvature=="number"&&Number.isFinite(t.maxCurvature)&&(this.maxCurvature=Math.max(1,Math.min(64,Math.round(t.maxCurvature))))}};var Oi=6,Dw=2;function Yc(t=Oi){return[...Hv(br.length,t)]}function Rw(t){if(!t||typeof t!="object")return null;let e=t;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==!1,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var Li={path:"showRatios",label:"Show ratios",kind:"boolean",group:"behavior"},Fi=class extends fe{constructor(t){super(t),this.waveCount===void 0&&(this.waveCount=Oi),this.showRatios===void 0&&(this.showRatios=!0);let e=Array.isArray(t.props?.levels);this.levels||(this.levels=this.defaultLevels().map(n=>({...n}))),!e&&this.shouldSyncWaveCount()&&this.syncLevelsToWaveCount()}shouldSyncWaveCount(){return!0}syncLevelsToWaveCount(){let t=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=t;for(let e=0;e<this.levels.length;e+=1)this.levels[e].enabled=e<t}editableLevels(){return this.levels}anchorSchema(){return{min:2,max:2,slots:[{role:"d1",free:"both"},{role:"d2",free:"both"}]}}geom(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=(s+a)/2,l=(r+i)/2,c=Math.hypot(a-s,i-r)/2;if(c<1)return null;let u=a-s,p=i-r,h=Math.hypot(u,p);h<1e-9?(u=1,p=0):(u/=h,p/=h);let d=this.levels.filter(I=>I.enabled&&I.ratio>0).slice().sort((I,E)=>I.ratio-E.ratio);if(d.length===0)return null;let f=Math.max(1,this.machNumber()),m=[];for(let I of d){let E=I.ratio*c;m.push({cx:o+f*(E-c)*u,cy:l+f*(E-c)*p,r:E,color:I.color,ratio:I.ratio})}let _=o-f*c*u,b=l-f*c*p,v=m[m.length-1].r,S=f*v+2*c,w=[];if(f<=1+1e-9){let I=-p,E=u;w.push([_-I*S,b-E*S,_+I*S,b+E*S])}else{let I=Math.asin(1/f),E=Math.cos(I),A=Math.sin(I),F=(B,O,K)=>[B*E-O*K*A,B*K*A+O*E],[N,j]=F(u,p,1),[T,q]=F(u,p,-1);w.push([_,b,_+N*S,b+j*S]),w.push([_,b,_+T*S,b+q*S])}return{c0x:o,c0y:l,R:c,fx:u,fy:p,noseX:_,noseY:b,circles:m,rays:w}}hitTest(t,e,n,r){let i=this.geom(n);if(!i)return!1;for(let s of i.circles)if(Math.abs(Math.hypot(t-s.cx,e-s.cy)-s.r)<=r)return!0;return i.rays.some(s=>Oe(t,e,s[0],s[1],s[2],s[3])<=r)}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.geom(t);if(!e)return null;let n=e.noseX,r=e.noseX,i=e.noseY,s=e.noseY;for(let a of e.circles)n=Math.min(n,a.cx-a.r),r=Math.max(r,a.cx+a.r),i=Math.min(i,a.cy-a.r),s=Math.max(s,a.cy+a.r);for(let a of e.rays)n=Math.min(n,a[0],a[2]),r=Math.max(r,a[0],a[2]),i=Math.min(i,a[1],a[3]),s=Math.max(s,a[1],a[3]);return{x:n,y:i,w:r-n,h:s-i}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}applySettings(t){if(super.applySettings(t),Object.prototype.hasOwnProperty.call(t,"waveCount")&&typeof this.waveCount=="number"){let e=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=e;for(let n=0;n<this.levels.length;n+=1)this.levels[n].enabled=n<e}}schema(){return{fields:[...te,{path:"waveCount",label:"Waves",kind:"number",min:3,max:12,step:1,group:"behavior"},Li,...re]}}writeProps(){return{waveCount:this.waveCount,showRatios:this.showRatios,levels:this.levels.map(t=>({...t}))}}readProps(t){if(typeof t.waveCount=="number"&&Number.isFinite(t.waveCount)&&(this.waveCount=Math.max(2,Math.min(12,Math.round(t.waveCount)))),typeof t.showRatios=="boolean"&&(this.showRatios=t.showRatios),Array.isArray(t.levels)){let e=t.levels.map(Rw).filter(n=>n!=null);e.length&&(this.levels=e)}}},Ow=class extends Fi{constructor(){super(...arguments),this.type="sonic"}defaultLevels(){return Yc(Oi)}machNumber(){return 1}},Lw=class extends Fi{constructor(t){super(t),this.type="supersonic",this.mach===void 0&&(this.mach=Dw)}defaultLevels(){return Yc(Oi)}machNumber(){return Math.max(1.01,this.mach)}schema(){return{fields:[...te,{path:"mach",label:"Mach number",kind:"number",min:1.5,max:5,step:.5,group:"behavior"},{path:"waveCount",label:"Waves",kind:"number",min:3,max:12,step:1,group:"behavior"},Li,...re]}}writeProps(){return{...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)))}},Gc=nt([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),Fw=2,Bw=class extends Fi{constructor(){super(...arguments),this.type="goldensonic"}shouldSyncWaveCount(){return!1}defaultLevels(){return Gc}machNumber(){return 1}schema(){return{fields:[...te,Li,...re]}}},Vw=class extends Fi{constructor(t){super(t),this.type="goldensupersonic",this.mach===void 0&&(this.mach=Fw)}shouldSyncWaveCount(){return!1}defaultLevels(){return Gc}machNumber(){return Math.max(1.01,this.mach)}schema(){return{fields:[...te,{path:"mach",label:"Mach number",kind:"number",min:1.5,max:5,step:.5,group:"behavior"},Li,...re]}}writeProps(){return{...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)))}},Kn=class extends fe{legRatios(){return!1}fillTriangles(){return[]}necklineIndices(){return null}anchorSchema(){let t=this.vertexLabels().length,e=[];for(let n=0;n<t;n+=1)e.push({role:`p${n}`,free:"both"});return{min:t,max:t,slots:e}}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitTest(t,e,n,r){let i=this.handlePoints(n);return i.length>=2&&Aa(t,e,i)<=r}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}patternName(){return null}ratioOk(t){return null}valid(){return null}ratioAt(t){let e=this.anchors[t-2],n=this.anchors[t-1],r=this.anchors[t];if(!e||!n||!r)return null;let i=Math.abs(n.price-e.price);return i<1e-9?null:Math.abs(r.price-n.price)/i}schema(){return{fields:[...te,...this.fillTriangles().length?tt:[]]}}},Ww=class extends Kn{constructor(){super(...arguments),this.type="xabcd"}vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}},$w=class extends Kn{constructor(){super(...arguments),this.type="abcd"}vertexLabels(){return["A","B","C","D"]}legRatios(){return!0}},jw=class extends Kn{constructor(){super(...arguments),this.type="elliottimpulse"}vertexLabels(){return["1","2","3","4","5"]}},Uw=class extends Kn{constructor(){super(...arguments),this.type="elliottcorrection"}vertexLabels(){return["A","B","C"]}},zw=class extends Kn{constructor(){super(...arguments),this.type="headshoulders"}vertexLabels(){return["","LS","","H","","RS",""]}necklineIndices(){return[2,4]}},Yn=class extends Kn{vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}legValue(t){let[e,n,r,i,s]=this.anchors;if(!e||!n||!r||!i||!s)return null;let a=(u,p)=>Math.abs(p.price-u.price),o=a(e,n),l=a(n,r),c=a(r,i);switch(t){case"ab":return o<1e-9?null:l/o;case"bc":return l<1e-9?null:c/l;case"cd":return c<1e-9?null:a(i,s)/c;default:return o<1e-9?null:a(n,s)/o}}inBand(t,e){return t!=null&&t>=e.min&&t<=e.max}ratioOk(t){let e=this.ranges();return t===2?this.inBand(this.legValue("ab"),e.ab):t===3?this.inBand(this.legValue("bc"),e.bc):t===4?this.inBand(this.legValue("cd"),e.cd):null}valid(){if(this.anchors.length<5)return null;let t=this.ranges();return this.inBand(this.legValue("ab"),t.ab)&&this.inBand(this.legValue("bc"),t.bc)&&this.inBand(this.legValue("cd"),t.cd)&&this.inBand(this.legValue("ad"),t.ad)}},qw=class extends Yn{constructor(){super(...arguments),this.type="gartley"}patternName(){return"Gartley"}ranges(){return{ab:{min:.55,max:.68},bc:{min:.382,max:.886},cd:{min:1.13,max:1.618},ad:{min:.74,max:.83}}}},Hw=class extends Yn{constructor(){super(...arguments),this.type="bat"}patternName(){return"Bat"}ranges(){return{ab:{min:.382,max:.5},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:.84,max:.92}}}},Kw=class extends Yn{constructor(){super(...arguments),this.type="butterfly"}patternName(){return"Butterfly"}ranges(){return{ab:{min:.74,max:.83},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:1.272,max:1.618}}}},Yw=class extends Yn{constructor(){super(...arguments),this.type="crab"}patternName(){return"Crab"}ranges(){return{ab:{min:.382,max:.618},bc:{min:.382,max:.886},cd:{min:2.618,max:3.618},ad:{min:1.55,max:1.69}}}},Gw=class extends Yn{constructor(){super(...arguments),this.type="shark"}patternName(){return"Shark"}ranges(){return{ab:{min:.382,max:.618},bc:{min:1.13,max:1.618},cd:{min:1.618,max:2.24},ad:{min:.886,max:1.13}}}},Xw={min:1.272,max:1.414},Zw={min:.74,max:.83},Qw=class extends Yn{constructor(){super(...arguments),this.type="cypher"}patternName(){return"Cypher"}ranges(){return{ab:{min:.382,max:.618},bc:{min:0,max:1/0},cd:{min:0,max:1/0},ad:{min:0,max:1/0}}}xcOverXa(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[3];if(!t||!e||!n)return null;let r=Math.abs(e.price-t.price);return r<1e-9?null:Math.abs(n.price-t.price)/r}cdOverXc(){let t=this.anchors[0],e=this.anchors[3],n=this.anchors[4];if(!t||!e||!n)return null;let r=Math.abs(e.price-t.price);return r<1e-9?null:Math.abs(n.price-e.price)/r}ratioOk(t){return t===2?this.inBand(this.legValue("ab"),this.ranges().ab):null}valid(){return this.anchors.length<5?null:this.inBand(this.legValue("ab"),this.ranges().ab)&&this.inBand(this.xcOverXa(),Xw)&&this.inBand(this.cdOverXc(),Zw)}};function Tc(t){return`${t>=0?"+":""}${t.toFixed(2)}`}function Jw(t){let e=Math.abs(t),n=864e5,r=36e5,i=6e4;if(e>=n){let s=Math.floor(e/n),a=Math.round(e%n/r);return a?`${s}d ${a}h`:`${s}d`}if(e>=r){let s=Math.floor(e/r),a=Math.round(e%r/i);return a?`${s}h ${a}m`:`${s}h`}return e>=i?`${Math.round(e/i)}m`:`${Math.round(e/1e3)}s`}var eS=class extends fe{constructor(t){super(t),this.showPrice===void 0&&(this.showPrice=!0),this.showDate===void 0&&(this.showDate=!0)}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}measureLabel(t){let e=[];return this.showPrice&&e.push(this.priceLabel()),this.showDate&&e.push(this.timeLabel(t)),e}isUp(){let t=this.anchors[0],e=this.anchors[1];return t!=null&&e!=null&&e.price>=t.price}priceLabel(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return"";let n=e.price-t.price,r=t.price!==0?n/t.price*100:0;return`${Tc(n)} (${Tc(r)}%)`}timeLabel(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return"";let r=Jw(n.time-e.time),i=t.barsBetween?Math.round(t.barsBetween(e.time,n.time)):null;return i!=null?`${i} bars, ${r}`:r}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i!=null&&Zt(t,e,i.x1,i.y1,i.x2,i.y2,r)}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"showPrice",label:"Show price",kind:"boolean",group:"behavior"},{path:"showDate",label:"Show date",kind:"boolean",group:"behavior"},...te.filter(t=>t.path!=="style.lineColor"),{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:ka,group:"text"}]}}writeProps(){return{showPrice:this.showPrice,showDate:this.showDate}}readProps(t){typeof t.showPrice=="boolean"&&(this.showPrice=t.showPrice),typeof t.showDate=="boolean"&&(this.showDate=t.showDate)}},tS=class extends eS{constructor(){super(...arguments),this.type="datepricerange"}},nS=[{value:"long",label:"Long"},{value:"short",label:"Short"}],Ut=class gt extends fe{constructor(e){super(e),this.type="position",this.riskPercent===void 0&&(this.riskPercent=gt.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=gt.DEFAULT_ACCOUNT_BALANCE),this.showText===void 0&&(this.showText=!0),this.showHeader===void 0&&(this.showHeader=!0),this.showPrices===void 0&&(this.showPrices=!1),this.showLossSize===void 0&&(this.showLossSize=!0),this.showTargetLabel===void 0&&(this.showTargetLabel=!0),this.showStopLabel===void 0&&(this.showStopLabel=!0),this.profitColor===void 0&&(this.profitColor=gt.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=gt.DEFAULT_LOSS_COLOR)}directionLabel(){let e=this.prices();return e&&e.target>=e.entry?"LONG":"SHORT"}get direction(){return this.directionLabel()==="LONG"?"long":"short"}set direction(e){let n=this.anchors[0],r=this.anchors[1],i=this.anchors[2];!n||!r||!i||(e==="long"||e==="short")&&e!==this.direction&&(r.price=2*n.price-r.price,i.price=2*n.price-i.price)}get quantity(){return this.positionSize()}set quantity(e){let n=this.prices();if(!n||!Number.isFinite(e)||e<0)return;let r=Math.abs(n.entry-n.stop);r<1e-9||this.accountBalance<=0||(this.riskPercent=e*r/this.accountBalance*100)}get entryPrice(){return this.anchors[0]?.price??0}set entryPrice(e){let n=this.anchors[0];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(0))}get stopPrice(){return this.anchors[1]?.price??0}set stopPrice(e){let n=this.anchors[1];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(1))}get targetPrice(){return this.anchors[2]?.price??0}set targetPrice(e){let n=this.anchors[2];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(2))}anchorSchema(){return{min:2,max:2,slots:[{role:"entry",free:"both"},{role:"stop",free:"both"},{role:"target",free:"both"}]}}onPlaced(e){let n=this.anchors[0];if(!n)return;let r=e.xOf(n.time),i=e.yOf(n.price,this.paneId);if(i==null)return;let s=this.anchors[1],a=s?e.yOf(s.price,this.paneId):null,o,l;s&&a!=null&&Math.abs(a-i)>=gt.MIN_DRAG_PX?(o=a,l=r+Math.max(Math.abs(e.xOf(s.time)-r),gt.MIN_WIDTH_PX)):(o=i-gt.DEFAULT_RISK_PX*gt.DEFAULT_RR,l=r+gt.DEFAULT_WIDTH_PX);let c=i-(o-i)/gt.DEFAULT_RR,u=e.pxToPoint(l,i,this.paneId).time;this.anchors=[{time:n.time,price:n.price},{time:u,price:e.pxToPoint(r,c,this.paneId).price},{time:u,price:e.pxToPoint(r,o,this.paneId).price}]}constrainHandleDrag(e){let n=this.anchors[0],r=this.anchors[1],i=this.anchors[2];if(!n||!r||!i)return;let s=Math.sign(r.price-n.price),a=Math.sign(i.price-n.price);s===0||a===0||s!==a||(e===2?r.price=2*n.price-r.price:i.price=2*n.price-i.price)}resolved(){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;if(this.anchors[2])return[e,n,this.anchors[2]];let r={time:n.time,price:e.price-(n.price-e.price)/gt.DEFAULT_RR};return[e,r,n]}prices(){let e=this.resolved();return e?{entry:e[0].price,stop:e[1].price,target:e[2].price}:null}rr(){let e=this.prices();if(!e)return 0;let n=Math.abs(e.entry-e.stop);return n<1e-9?0:Math.abs(e.target-e.entry)/n}rewardPct(){let e=this.prices();return e&&e.entry!==0?Math.abs(e.target-e.entry)/e.entry*100:0}riskPct(){let e=this.prices();return e&&e.entry!==0?Math.abs(e.entry-e.stop)/e.entry*100:0}dollarLoss(){return Math.max(0,this.accountBalance)*(Math.max(0,this.riskPercent)/100)}positionSize(){let e=this.prices();if(!e)return 0;let n=Math.abs(e.entry-e.stop);return n<1e-9?0:this.dollarLoss()/n}headerLabel(){return`${this.directionLabel()} \\xB7 R:R ${this.rr().toFixed(2)}`}lossSizeLabel(){return`Loss $${iS(this.dollarLoss())} \\xB7 Size ${sS(this.positionSize())}`}targetLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Pc(e.target)}`:"";return`Target +${this.rewardPct().toFixed(2)}%${n}`}stopLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Pc(e.stop)}`:"";return`Stop \\u2212${this.riskPct().toFixed(2)}%${n}`}levelDisplayValue(e,n){let r=this.prices();if(!r)return 0;let i=e==="stop"?r.stop:r.target;return Dc(n==="price"?i:Math.abs(i-r.entry))}levelPriceFromDisplay(e,n,r){let i=this.prices();if(!i||n==="price")return r;let s=e==="stop"?i.stop:i.target,a=Math.sign(s-i.entry);return a===0&&(a=(e==="target"?1:-1)*(this.direction==="long"?1:-1)),i.entry+a*Math.abs(r)}box(e){let n=this.handlePoints(e);if(n.length<3)return null;let r=n.map(i=>i[0]);return{x1:Math.min(...r),x2:Math.max(...r),ey:n[0][1],sy:n[1][1],ty:n[2][1]}}layout(e){return this.box(e)}hitTest(e,n,r,i){let s=this.box(r);if(!s)return!1;let a=Math.min(s.ey,s.sy,s.ty),o=Math.max(s.ey,s.sy,s.ty);return Zt(e,n,s.x1,a,s.x2,o,i)}handlePoints(e){let n=this.resolved();if(!n)return[];let r=[];for(let i of n){let s=e.yOf(i.price,this.paneId);if(s==null)return[];r.push([e.xOf(i.time),s])}return r}hitHandle(e,n,r,i){return me(e,n,this.handlePoints(r),i+3)}bounds(e){let n=this.box(e);if(!n)return null;let r=Math.min(n.ey,n.sy,n.ty);return{x:n.x1,y:r,w:n.x2-n.x1,h:Math.max(n.ey,n.sy,n.ty)-r}}priceRange(){let e=this.resolved();if(!e)return null;let n=e.map(r=>r.price);return{min:Math.min(...n),max:Math.max(...n)}}schema(){return{fields:[{path:"riskPercent",label:"Risk %",kind:"number",min:0,max:100,step:.1,group:"behavior"},{path:"accountBalance",label:"Account balance",kind:"number",min:0,max:1e12,step:1,group:"behavior"},{path:"quantity",label:"Position size",kind:"number",group:"behavior"},{path:"direction",label:"Direction",kind:"select",options:nS,group:"behavior"},{path:"entryPrice",label:"Entry price",kind:"number",group:"behavior"},{path:"stopPrice",label:"Stop price",kind:"number",group:"behavior"},{path:"targetPrice",label:"Target price",kind:"number",group:"behavior"},{path:"showText",label:"Show text",kind:"boolean",group:"behavior"},{path:"showHeader",label:"Show direction & ratio",kind:"boolean",group:"behavior"},{path:"showLossSize",label:"Show loss & size",kind:"boolean",group:"behavior"},{path:"showTargetLabel",label:"Show target label",kind:"boolean",group:"behavior"},{path:"showStopLabel",label:"Show stop label",kind:"boolean",group:"behavior"},{path:"showPrices",label:"Show level prices",kind:"boolean",group:"behavior"},{path:"profitColor",label:"Profit zone",kind:"color",group:"fill"},{path:"lossColor",label:"Loss zone",kind:"color",group:"fill"},...te.filter(e=>e.path!=="style.lineColor"),{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:ka,group:"text"}]}}writeProps(){return{riskPercent:this.riskPercent,accountBalance:this.accountBalance,showText:this.showText,showHeader:this.showHeader,showPrices:this.showPrices,showLossSize:this.showLossSize,showTargetLabel:this.showTargetLabel,showStopLabel:this.showStopLabel,profitColor:this.profitColor,lossColor:this.lossColor}}readProps(e){typeof e.riskPercent=="number"&&Number.isFinite(e.riskPercent)&&(this.riskPercent=e.riskPercent),typeof e.accountBalance=="number"&&Number.isFinite(e.accountBalance)&&(this.accountBalance=e.accountBalance),typeof e.showText=="boolean"&&(this.showText=e.showText),typeof e.showHeader=="boolean"&&(this.showHeader=e.showHeader),typeof e.showPrices=="boolean"&&(this.showPrices=e.showPrices),typeof e.showLossSize=="boolean"&&(this.showLossSize=e.showLossSize),typeof e.showTargetLabel=="boolean"&&(this.showTargetLabel=e.showTargetLabel),typeof e.showStopLabel=="boolean"&&(this.showStopLabel=e.showStopLabel),typeof e.profitColor=="string"&&(this.profitColor=e.profitColor),typeof e.lossColor=="string"&&(this.lossColor=e.lossColor)}};Ut.DEFAULT_RR=2;Ut.MIN_DRAG_PX=6;Ut.DEFAULT_RISK_PX=64;Ut.DEFAULT_WIDTH_PX=150;Ut.MIN_WIDTH_PX=48;Ut.DEFAULT_RISK_PERCENT=1;Ut.DEFAULT_ACCOUNT_BALANCE=1e4;Ut.DEFAULT_PROFIT_COLOR=Ca;Ut.DEFAULT_LOSS_COLOR=Ia;var rS=Ut;function iS(t){if(!Number.isFinite(t))return"0";let e=Math.round(t*100)/100;return Number.isInteger(e)?String(e):e.toFixed(2)}function sS(t){return!Number.isFinite(t)||t===0?"0":t>=100?t.toFixed(2):t>=1?t.toFixed(4).replace(/\\.?0+$/,""):t.toPrecision(4).replace(/\\.?0+$/,"")}function Pc(t){return Number.isFinite(t)?Math.abs(t)>=1?t.toFixed(2):t.toPrecision(4).replace(/\\.?0+$/,""):"0"}function Dc(t){return Math.round(t*1e8)/1e8}var aS=[{value:"auto",label:"Auto",ms:0},{value:"1",label:"1m",ms:6e4},{value:"5",label:"5m",ms:3e5},{value:"15",label:"15m",ms:9e5},{value:"30",label:"30m",ms:18e5},{value:"60",label:"1h",ms:36e5},{value:"240",label:"4h",ms:144e5},{value:"D",label:"1D",ms:864e5}];function Rc(){return{timeframe:"auto",upColor:"",downColor:""}}var oS=class extends fe{constructor(t){super(t),this.type="magnifier",this.chipRect=null,this.magnifier||(this.magnifier=Rc())}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}placementMode(){return"drag"}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i?Zt(t,e,i.x1,i.y1,i.x2,i.y2)?!0:[[i.x1,i.y1,i.x2,i.y1],[i.x2,i.y1,i.x2,i.y2],[i.x2,i.y2,i.x1,i.y2],[i.x1,i.y2,i.x1,i.y1]].some(a=>Oe(t,e,a[0],a[1],a[2],a[3])<=r):!1}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return me(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"magnifier.timeframe",label:"Timeframe",kind:"select",options:aS,group:"behavior"},...te.map(t=>({...t,label:t.label.replace("Line","Border")})),{path:"magnifier.upColor",label:"Up candles",kind:"color",group:"fill"},{path:"magnifier.downColor",label:"Down candles",kind:"color",group:"fill"}]}}writeProps(){return{...this.magnifier}}readProps(t){this.magnifier={...Rc(),...t}}},lS=new Map;function L(t){lS.set(t.type,t)}var cS=k(\'<line x1="4" y1="19" x2="20" y2="5"/>\'),uS=k(\'<line x1="3" y1="12" x2="21" y2="12"/>\');L({type:"trendline",group:"lines",label:"Trend Line",icon:cS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Db(t)});L({type:"hline",group:"lines",label:"Horizontal Line",icon:uS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"dashed"},create:t=>new Rb(t)});var hS=k(\'<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>\'),pS=k(\'<rect x="4" y="6" width="16" height="12" rx="1"/>\'),dS=k(\'<path d="M5 6h14M12 6v13"/>\');L({type:"ray",group:"lines",label:"Ray",icon:hS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Ob(t)});var fS=k(\'<path d="M5 19 19 5"/><path d="M5 19 8.5 19M5 19 5 15.5"/><path d="M19 5 15.5 5M19 5 19 8.5"/>\'),mS=k(\'<line x1="12" y1="3" x2="12" y2="21"/>\'),yS=k(\'<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>\'),gS=k(\'<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>\'),xS=k(\'<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>\'),_S=k(\'<path d="M4 20 20 6"/><path d="M4 20 15 20"/><path d="M11 20a7 7 0 0 0-2-4.9"/>\');L({type:"extendedline",group:"lines",label:"Extended Line",icon:fS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Lb(t)});L({type:"vline",group:"lines",label:"Vertical Line",icon:mS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Fb(t)});L({type:"hray",group:"lines",label:"Horizontal Ray",icon:yS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Bb(t)});L({type:"crossline",group:"lines",label:"Cross Line",icon:gS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Vb(t)});L({type:"infoline",group:"lines",label:"Info Line",icon:xS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Wb(t)});L({type:"trendangle",group:"lines",label:"Trend Angle",icon:_S,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new $b(t)});L({type:"box",group:"shapes",label:"Rectangle",icon:pS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}26`},create:t=>new jb(t)});L({type:"text",group:"annotations",label:"Text",icon:dS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new zb(t)});var bS=k(\'<path d="M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-6l-5 5v-5H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"/>\');L({type:"callout",group:"annotations",label:"Callout",icon:bS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new Yb(t)});var vS=k(\'<path d="M5 4h14a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-7l-4 4v-4H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z"/><path d="M8 8.5h8M8 12h5"/>\'),wS=k(\'<rect x="10" y="4.5" width="11" height="8" rx="1.5"/><path d="M10 8.5 4 16"/><circle cx="3.5" cy="16.5" r="1.6" fill="currentColor" stroke="none"/>\'),SS=k(\'<path d="M5 4.5h14a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-7l-4 4v-4H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2Z"/>\'),ES=k(\'<path d="M3 12 7 8h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7Z"/><path d="M10.5 12.5h6" stroke-width="1.4"/>\'),CS=k(\'<path d="M12 11.5V21"/><rect x="5" y="4" width="14" height="7" rx="1"/><path d="M9 7.5h6"/>\');L({type:"note",group:"annotations",label:"Note",icon:vS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new qb(t)});L({type:"pricenote",group:"annotations",label:"Price Note",icon:wS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new Gb(t)});L({type:"comment",group:"annotations",label:"Comment",icon:SS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new Xb(t)});L({type:"pricelabel",group:"annotations",label:"Price Label",icon:ES,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new Hb(t)});L({type:"signpost",group:"annotations",label:"Signpost",icon:CS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new Zb(t)});var IS=k(\'<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>\'),NS=k(\'<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>\'),kS=k(\'<circle cx="4" cy="12" r="1.6" fill="currentColor"/><line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\');L({type:"parallelchannel",group:"channels",label:"Parallel Channel",icon:IS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new Qb(t)});L({type:"disjointchannel",group:"channels",label:"Disjoint Channel",icon:NS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new Jb(t)});var AS=k(\'<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="18" x2="21" y2="11"/>\');L({type:"flattopbottom",group:"channels",label:"Flat Top/Bottom",icon:AS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new ev(t)});var MS=k(\'<line x1="3" y1="8" x2="21" y2="4"/><line x1="3" y1="16" x2="21" y2="12"/><line x1="3" y1="12" x2="21" y2="8" stroke-dasharray="3 3"/>\');L({type:"regressionchannel",group:"channels",label:"Linear Regression",icon:MS,defaultStyle:{lineColor:wn,lineWidth:1,lineStyle:"solid"},create:t=>new rv(t)});L({type:"pitchfork",group:"pitchforks",label:"Pitchfork",icon:kS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new fv(t)});var TS=k(\'<circle cx="4" cy="8" r="1.6" fill="currentColor"/><line x1="4" y1="8" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\'),PS=k(\'<circle cx="6" cy="9" r="1.6" fill="currentColor"/><line x1="6" y1="9" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\'),DS=k(\'<line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="8" x2="10" y2="16"/><line x1="10" y1="8" x2="21" y2="8"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="16" x2="21" y2="16"/>\');L({type:"schiffpitchfork",group:"pitchforks",label:"Schiff Pitchfork",icon:TS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new mv(t)});L({type:"modifiedschiffpitchfork",group:"pitchforks",label:"Modified Schiff Pitchfork",icon:PS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new yv(t)});L({type:"insidepitchfork",group:"pitchforks",label:"Inside Pitchfork",icon:DS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new gv(t)});var RS=k(\'<path d="M7 7h10v10"/><path d="M7 17 17 7"/>\'),OS=k(\'<ellipse cx="12" cy="12" rx="9" ry="6"/>\'),LS=k(\'<path d="M12 4 20 19 4 19Z"/>\');L({type:"arrow",group:"shapes",label:"Arrow",icon:RS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",arrowRight:!0},create:t=>new xv(t)});L({type:"ellipse",group:"shapes",label:"Ellipse",icon:OS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new _v(t)});L({type:"triangle",group:"shapes",label:"Triangle",icon:LS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new bv(t)});var FS=k(\'<polyline points="3 17 9 10 13 14 21 5"/>\'),BS=k(\'<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>\'),VS=k(\'<path d="M9 11 15 5l4 4-6 6H9Z"/><path d="M9 15l-2 2"/><path d="M4 21h6"/>\');L({type:"polyline",group:"shapes",label:"Polyline",icon:FS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new wv(t)});L({type:"freehand",group:"shapes",label:"Brush",icon:BS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Sv(t)});L({type:"highlighter",group:"shapes",label:"Highlighter",icon:VS,defaultStyle:{lineColor:`${Ea}59`,lineWidth:14,lineStyle:"solid"},create:t=>new Cv(t)});var WS=k(\'<circle cx="12" cy="12" r="8"/>\'),$S=k(\'<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>\'),jS=k(\'<path d="M4 19 9 11 13 14 17 8 20 4"/><path d="M17.2 5.5 20 4 19.4 7.1"/>\'),US=k(\'<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>\'),zS=k(\'<path d="M4 18Q12 1 20 14"/>\'),qS=k(\'<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>\'),HS=k(\'<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>\');L({type:"circle",group:"shapes",label:"Circle",icon:WS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new Iv(t)});L({type:"rotatedrect",group:"shapes",label:"Rotated Rectangle",icon:$S,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}26`},create:t=>new Nv(t)});L({type:"path",group:"shapes",label:"Path",icon:jS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new kv(t)});L({type:"arc",group:"shapes",label:"Arc",icon:US,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}26`},create:t=>new Av(t)});L({type:"curve",group:"shapes",label:"Curve",icon:zS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Mv(t)});L({type:"arrowmarkup",group:"shapes",label:"Arrow Mark Up",icon:qS,defaultStyle:{lineColor:kt,lineWidth:1,lineStyle:"solid"},create:t=>new Pv(t)});L({type:"arrowmarkdown",group:"shapes",label:"Arrow Mark Down",icon:HS,defaultStyle:{lineColor:jt,lineWidth:1,lineStyle:"solid"},create:t=>new Dv(t)});var KS=k(\'<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>\'),YS=k(\'<path d="m12 3 2.6 5.8 6.4.6-4.8 4.2 1.4 6.2L12 16.9 6.4 19.8 7.8 13.6 3 9.4l6.4-.6Z"/>\');L({type:"flagmark",group:"stamps",label:"Flag",icon:KS,defaultStyle:{lineColor:vn,lineWidth:1,lineStyle:"solid"},create:t=>new Lv(t)});L({type:"iconstamp",group:"stamps",label:"Icon",icon:YS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Fv(t)});var GS=k(\'<line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="3" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/>\'),XS=k(\'<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="11" x2="21" y2="11"/><line x1="3" y1="15" x2="14" y2="15"/><line x1="3" y1="20" x2="14" y2="20"/>\');L({type:"fibretracement",group:"fibonacci",label:"Fib Retracement",icon:GS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Yv(t)});L({type:"fibextension",group:"fibonacci",label:"Fib Extension",icon:XS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Xv(t)});var ZS=k(\'<path d="M3 20 10 9l4 5"/><path d="M14 14h7M14 9h7M14 4h7"/>\');L({type:"fibextensiontrend",group:"fibonacci",label:"Trend-Based Fib Extension",icon:ZS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Qv(t)});var QS=k(\'<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>\'),JS=k(\'<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>\');L({type:"fibfan",group:"fibonacci",label:"Fib Fan",icon:QS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new ew(t)});L({type:"fibtimezones",group:"fibonacci",label:"Fib Time Zones",icon:JS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"dashed"},create:t=>new nw(t)});var eE=k(\'<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>\'),tE=k(\'<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>\'),nE=k(\'<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>\');L({type:"fibchannel",group:"fibonacci",label:"Fib Channel",icon:eE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new iw(t)});L({type:"fibspeedfan",group:"fibonacci",label:"Fib Speed Resistance Fan",icon:tE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new aw(t)});L({type:"trendfibtime",group:"fibonacci",label:"Trend-Based Fib Time",icon:nE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"dashed"},create:t=>new lw(t)});var rE=k(\'<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>\'),iE=k(\'<path d="M8 20a4 4 0 0 1 8 0"/><path d="M4.5 20a7.5 7.5 0 0 1 15 0"/><circle cx="12" cy="20" r="1.4" fill="currentColor" stroke="none"/>\'),sE=k(\'<path d="M4 20 20 16M4 20 14 4"/><path d="M11.8 18.1A8 8 0 0 0 8.2 13.2"/><path d="M16.6 16.9A13 13 0 0 0 10.9 9"/>\'),aE=k(\'<path d="M13 12a2 2 0 1 1-2-2 4 4 0 0 1 4 4 6 6 0 0 1-9 5.2 9 9 0 0 1 .5-15"/>\');L({type:"fibcircles",group:"fibonacci",label:"Fib Circles",icon:rE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new hw(t)});L({type:"fibarcs",group:"fibonacci",label:"Fib Speed Resistance Arcs",icon:iE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new dw(t)});L({type:"fibwedge",group:"fibonacci",label:"Fib Wedge",icon:sE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new mw(t)});L({type:"fibspiral",group:"fibonacci",label:"Fib Spiral",icon:aE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new bw(t)});var oE=k(\'<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>\'),lE=k(\'<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 12h16M12 4v16M4 4 20 20" opacity="0.6"/>\');L({type:"gannfan",group:"fibonacci",label:"Gann Fan",icon:oE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new ww(t)});L({type:"gannbox",group:"fibonacci",label:"Gann Box",icon:lE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Ew(t)});var cE=k(\'<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 20 20 4M4 20 20 12M4 20 12 4" opacity="0.7"/><path d="M4 20a16 16 0 0 1 16-16" opacity="0.5"/>\');L({type:"gannsquare",group:"fibonacci",label:"Gann Square",icon:cE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Nw(t)});var uE=k(\'<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0" opacity="0.9"/><path d="M6 20a4 4 0 0 1 8 0" opacity="0.75"/><path d="M10 20a2 2 0 0 1 4 0" opacity="0.6"/><path d="M8 20v-6M12 20v-9M16 20v-6" opacity="0.45"/>\');L({type:"dedekind",group:"geometry",label:"Dedekind Tessellation",icon:uE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Pw(t)});var hE=k(\'<circle cx="16" cy="12" r="5" opacity="0.55"/><circle cx="13" cy="12" r="3.5" opacity="0.75"/><circle cx="10.5" cy="12" r="2"/><path d="M8 4v16"/>\'),pE=k(\'<circle cx="17" cy="12" r="4.5" opacity="0.45"/><circle cx="13" cy="12" r="3" opacity="0.7"/><circle cx="10" cy="12" r="1.6"/><path d="M6 12 16 5M6 12 16 19"/>\');L({type:"sonic",group:"geometry",label:"Sonic",icon:hE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Ow(t)});L({type:"supersonic",group:"geometry",label:"Supersonic",icon:pE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Lw(t)});var dE=k(\'<circle cx="16" cy="12" r="5" opacity="0.4"/><circle cx="13" cy="12" r="3.2" opacity="0.65"/><circle cx="10.8" cy="12" r="1.8"/><path d="M8 4v16"/><path d="M15 8.5h2M12.5 10h2" opacity="0.5"/>\'),fE=k(\'<circle cx="17" cy="12" r="4.5" opacity="0.4"/><circle cx="12.5" cy="12" r="2.8" opacity="0.65"/><circle cx="9.8" cy="12" r="1.4"/><path d="M6 12 16 5M6 12 16 19"/>\');L({type:"goldensonic",group:"geometry",label:"Golden Sonic",icon:dE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Bw(t)});L({type:"goldensupersonic",group:"geometry",label:"Golden Supersonic",icon:fE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Vw(t)});var mE=k(\'<path d="M3 18 7 8 11 14 15 6 20 16"/>\'),yE=k(\'<path d="M4 17 9 7 14 15 20 5"/>\'),gE=k(\'<path d="M3 19 8 9 12 13 17 5 21 9"/>\'),xE=k(\'<path d="M4 7 11 16 20 9"/>\'),_E=k(\'<path d="M3 18 6 12 9 16 12 5 15 16 18 12 21 18"/>\');L({type:"xabcd",group:"patterns",label:"XABCD Pattern",icon:mE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Ww(t)});L({type:"abcd",group:"patterns",label:"ABCD Pattern",icon:yE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new $w(t)});L({type:"elliottimpulse",group:"patterns",label:"Elliott Impulse Wave (1-5)",icon:gE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new jw(t)});L({type:"elliottcorrection",group:"patterns",label:"Elliott Correction Wave (ABC)",icon:xE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Uw(t)});L({type:"headshoulders",group:"patterns",label:"Head & Shoulders",icon:_E,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new zw(t)});var bE=k(\'<path d="M3 17 7 6 12 14 17 5 21 16"/><path d="M3 17 21 16" opacity="0.45"/>\'),Gn={group:"patterns",icon:bE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"}};L({type:"gartley",label:"Gartley",...Gn,create:t=>new qw(t)});L({type:"bat",label:"Bat",...Gn,create:t=>new Hw(t)});L({type:"butterfly",label:"Butterfly",...Gn,create:t=>new Kw(t)});L({type:"crab",label:"Crab",...Gn,create:t=>new Yw(t)});L({type:"shark",label:"Shark",...Gn,create:t=>new Gw(t)});L({type:"cypher",label:"Cypher",...Gn,create:t=>new Qw(t)});var vE=k(\'<rect x="4" y="6" width="16" height="12" rx="1"/><path d="M4 18 20 6" opacity="0.5"/>\');L({type:"datepricerange",group:"measure",label:"Date & Price Range",icon:vE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new tS(t)});var wE=k(\'<rect x="4.5" y="4.5" width="15" height="7.5" rx="1" fill="currentColor" fill-opacity="0.25"/><rect x="4.5" y="12" width="15" height="7.5" rx="1"/>\');L({type:"position",group:"measure",label:"Long/Short Position",icon:wE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new rS(t)});var SE=k(\'<circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.3 15.3 5.2 5.2"/><path d="M8 12.5v-3M10.5 13.5v-5.5M13 12v-2"/>\');L({type:"magnifier",group:"measure",label:"Magnifier",icon:SE,defaultStyle:{lineColor:"",lineWidth:1,lineStyle:"solid"},coversSeries:!0,placementHint:"Drag an area on the chart to view it at a lower timeframe",create:t=>new oS(t)});var EE=k(\'<line x1="5" y1="3" x2="5" y2="21"/><path d="M5 16c4 0 5-9 8-9s3 5 8 3"/>\');L({type:"anchoredvwap",group:"measure",label:"Anchored VWAP",icon:EE,defaultStyle:{lineColor:Sn,lineWidth:2,lineStyle:"solid"},create:t=>new sv(t)});var CE=k(\'<path d="M4 4v16"/><path d="M4 8h10"/><path d="M4 12h14"/><path d="M4 16h8"/><path d="M4 20h12"/>\');L({type:"fixedrangevp",group:"measure",label:"Fixed Range Volume Profile",icon:CE,defaultStyle:{lineColor:kt,lineWidth:1,lineStyle:"solid"},create:t=>new dv(t)});function Ra(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var IE=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var Xc=["indicators","screenshot"],MC=new Set(Xc),TC=new Set(IE);var Zc=280;var PC=`\n.vela-panel[hidden] { display: none !important; }\n.vela-panel {\n position: relative;\n width: var(--vela-panel-w, ${Zc}px);\n flex: none;\n border-left: 1px solid var(--vela-border);\n display: flex;\n flex-direction: column;\n color: var(--vela-fg);\n font-size: 13px;\n box-sizing: border-box;\n background: var(--vela-bg);\n}\n.vela-panel-header {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 10px 8px 10px 14px;\n border-bottom: 1px solid var(--vela-border);\n font-size: 14px;\n font-weight: 600;\n color: var(--vela-fg-bright);\n}\n.vela-panel-title { flex: none; }\n.vela-panel-title:empty { display: none; }\n/* The contributed slot claims the space between title and close; its children lay out\n inline and the close button stays pinned right. */\n.vela-panel-header-slot { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; }\n.vela-panel-close {\n all: unset;\n cursor: pointer;\n width: 26px;\n height: 26px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: var(--vela-fg-muted);\n font-size: 16px;\n}\n.vela-panel-close .vela-icon { width: 16px; height: 16px; }\n.vela-panel-close:hover { background: var(--vela-hover); color: var(--vela-fg-bright); }\n/* The pin: same footprint as the close button it sits beside; filled + bright once pinned. */\n.vela-panel-pin {\n all: unset;\n cursor: pointer;\n width: 26px;\n height: 26px;\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: var(--vela-fg-muted);\n}\n.vela-panel-pin .vela-icon { width: 15px; height: 15px; }\n.vela-panel-pin:hover { background: var(--vela-hover); color: var(--vela-fg-bright); }\n.vela-panel-pin[data-on=\'1\'] { color: var(--vela-fg-bright); }\n.vela-panel-body { flex: 1; overflow: auto; padding: 8px; }\n.vela-panel-body::-webkit-scrollbar { width: 8px; }\n.vela-panel-body::-webkit-scrollbar-thumb { background: var(--vela-scroll); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }\n/* Straddles the panel\'s inner border so the whole seam is grabbable; it paints only under the\n pointer \\u2014 a permanently visible bar would read as a second border. */\n.vela-panel-resizer {\n position: absolute;\n top: 0;\n bottom: 0;\n left: -3px;\n width: 7px;\n cursor: col-resize;\n touch-action: none;\n z-index: 1;\n}\n.vela-panel-resizer::after {\n content: \'\';\n position: absolute;\n top: 0;\n bottom: 0;\n left: 3px;\n width: 1px;\n background: transparent;\n}\n/* The same hover ink as the workspace grid splitters and the canvas pane separators, so\n every draggable seam in the shell reads as one family. */\n.vela-panel-resizer:hover::after,\n.vela-panel-resizer[data-dragging]::after { background: var(--vela-separator-hover-line); }\n/* An OVERLAY panel floats over the chart\'s right edge instead of taking a column: the\n chart keeps its width and layout (the dock host is position:relative \\u2014 the anchoring the\n mobile rule below relies on too). Same z-order as that mobile overlay, above the chart\'s\n own DOM overlays; the shadow separates it from the plot it covers. */\n.vela-panel[data-overlay] {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n max-width: 100%;\n z-index: 25;\n box-shadow: var(--vela-shadow);\n}\n/* Mobile: a 280px column would crush a phone-width chart \\u2014 the panel overlays the\n chart area instead (its flex parent is position:relative), full-bleed, closed by\n the same header \\u2715. Width dragging is a pointer affordance; off on mobile. */\n[data-layout=\'mobile\'] .vela-panel {\n position: absolute;\n inset: 0;\n width: auto;\n z-index: 25;\n border-left: none;\n}\n[data-layout=\'mobile\'] .vela-panel-resizer { display: none; }\n`;var Bi=class{constructor(){Ja(this,"ordinals",new Map)}next(e,n,r){let i=`${n}:${r.trim().toLowerCase()}`,s=this.ordinals.get(i)??0;return this.ordinals.set(i,s+1),Ra({instanceId:e,kind:n,title:r,ordinal:s})}};function Xn(t){let e=t.data;if(e.length===0)return[];let n=e[e.length-1]?.value;return Array.isArray(n)?n:[]}function xe(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t&&typeof t=="object"){let e=t;if(Array.isArray(e.data)){let n=typeof e.offset=="number"?e.offset:0,r=e.data[e.data.length-1-n];return typeof r=="number"&&Number.isFinite(r)?r:void 0}}}function Vi(t){let e=(U(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function Jc(t){let e=(U(t)??"none").toLowerCase();return e==="b"||e==="both"?"both":e==="l"||e==="left"?"left":e==="r"||e==="right"?"right":"none"}function La(t){let e=(U(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function eu(t){if(t===void 0)return{invisible:!1};if(t===null)return{invisible:!0};if(typeof t=="number")return{invisible:!0};if(typeof t=="string"){if(t==="")return{invisible:!1};let e=se(t);return e?{color:e,invisible:!1}:{invisible:!0}}return{invisible:!0}}function Oa(t,e){let n=xe(t.x1),r=xe(t.y1),i=xe(t.x2),s=xe(t.y2);if(n===void 0||r===void 0||i===void 0||s===void 0)return null;let a=(U(t.style)??"").toLowerCase(),o=a==="style_arrow_left"||a==="style_arrow_both",l=a==="style_arrow_right"||a==="style_arrow_both",{color:c,invisible:u}=eu(t.color);return{id:e,paneId:"unrouted",xloc:Vi(t.xloc),x1:n,y1:r,x2:i,y2:s,extend:Jc(t.extend),color:c,invisible:u,width:Math.max(1,xe(t.width)??1),style:La(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function tu(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let s=Oa(i,n.next(e,"line",String(i.id??r.length)));s&&r.push(s)}return r}function nu(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let s=i.line1,a=i.line2;if(!s||!a)continue;let o=n.next(e,"linefill",String(i.id??r.length)),l=Oa(s,`${o}:a`),c=Oa(a,`${o}:b`);!l||!c||r.push({id:o,paneId:"unrouted",line1:l,line2:c,color:se(i.color),overlay:i.force_overlay===!0})}return r}function ru(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function NE(t){if(typeof t=="number"&&Number.isFinite(t))return ru(t);let e=(U(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function Fa(t){let e=(U(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function iu(t){let e=(U(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function Ba(t){return(U(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function su(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let s=xe(i.left),a=xe(i.top),o=xe(i.right),l=xe(i.bottom);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c=(U(i.text_formatting)??"").toLowerCase(),u=U(i.text);r.push({id:n.next(e,"box",String(i.id??r.length)),paneId:"unrouted",xloc:Vi(i.xloc),left:s,top:a,right:o,bottom:l,extend:Jc(i.extend),bgColor:se(i.bgcolor),borderColor:se(i.border_color),borderWidth:Math.max(0,xe(i.border_width)??1),borderStyle:La(i.border_style),text:u&&u.length>0?u:void 0,textColor:se(i.text_color),textSize:NE(i.text_size),hAlign:Fa(i.text_halign),vAlign:iu(i.text_valign),wrap:(U(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:Ba(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return r}var kE=["label_up","label_down","label_left","label_right","label_center","label_lower_left","label_lower_right","label_upper_left","label_upper_right","circle","square","diamond","flag","arrowup","arrowdown","triangleup","triangledown","cross","xcross","text_outline","none"];function AE(t){let e=(U(t)??"").toLowerCase().replace(/^style_/,"");return kE.includes(e)?e:"label_down"}function ME(t){let e=(U(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function au(t){if(typeof t=="number"&&Number.isFinite(t))return ru(t);let e=(U(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function ou(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let s=xe(i.x),a=ME(i.yloc),o=xe(i.y);if(s===void 0||a==="price"&&o===void 0)continue;let l=U(i.text),c=U(i.tooltip),{color:u,invisible:p}=eu(i.color);r.push({id:n.next(e,"label",String(i.id??r.length)),paneId:"unrouted",xloc:Vi(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:AE(i.style),color:u,noFill:p,textColor:se(i.textcolor),size:au(i.size),textAlign:Fa(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:Ba(i.text_font_family),overlay:i.force_overlay===!0})}return r}function lu(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=Vi(i.xloc),o=[];for(let c of s){let u=xe(c.price),p=xe(c.index),h=xe(c.time),d=a==="bar_time"?h:p,f=a==="bar_time"?p:h,m,_;if(d!==void 0)m=d,_=a;else if(f!==void 0)m=f,_=a==="bar_time"?"bar_index":"bar_time";else continue;u!==void 0&&o.push({xloc:_,x:m,price:u})}if(o.length<2)continue;let l=(U(i.line_style)??"").toLowerCase();r.push({id:n.next(e,"polyline",String(i.id??r.length)),paneId:"unrouted",points:o,curved:i.curved===!0,closed:i.closed===!0,lineColor:se(i.line_color),fillColor:se(i.fill_color),lineWidth:Math.max(1,xe(i.line_width)??1),lineStyle:La(i.line_style),arrowLeft:l==="style_arrow_left"||l==="style_arrow_both",arrowRight:l==="style_arrow_right"||l==="style_arrow_both",overlay:i.force_overlay===!0})}return r}var TE=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function PE(t){let e=(U(t)??"").toLowerCase();return TE.includes(e)?e:"top_right"}function DE(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:au(t)}function Qc(t){let e=xe(t);return e!==void 0&&e>0?e:void 0}function RE(t){if(!t||typeof t!="object")return null;let e=t,n=U(e.text),r=U(e.tooltip),i=(U(e.text_formatting)??"").toLowerCase();return{text:n&&n.length>0?n:void 0,textColor:se(e.text_color),bgColor:se(e.bgcolor),hAlign:Fa(e.text_halign),vAlign:iu(e.text_valign),textSize:DE(e.text_size),fontFamily:Ba(e.text_font_family),tooltip:r&&r.length>0?r:void 0,bold:i.includes("bold"),italic:i.includes("italic"),width:Qc(e.width),height:Qc(e.height),merged:e._merged===!0}}function OE(t){if(!Array.isArray(t))return[];let e=[],n=new Set;for(let r of t){if(!r||typeof r!="object")continue;let i=r,s=xe(i.startCol??i.start_column??i.startColumn),a=xe(i.startRow??i.start_row),o=xe(i.endCol??i.end_column??i.endColumn),l=xe(i.endRow??i.end_row);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c={startCol:Math.min(Math.round(s),Math.round(o)),startRow:Math.min(Math.round(a),Math.round(l)),endCol:Math.max(Math.round(s),Math.round(o)),endRow:Math.max(Math.round(a),Math.round(l))},u=`${c.startCol}:${c.startRow}:${c.endCol}:${c.endRow}`;n.has(u)||(n.add(u),e.push(c))}return e}function cu(t,e,n){let r=[];for(let i of Xn(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(l=>(Array.isArray(l)?l:[]).map(c=>RE(c))),o=OE(i.merges);for(let l of o){let c=a[l.startRow]?.[l.startCol];c?.merged&&(c.merged=!1)}r.push({id:n.next(e,"table",String(i.id??r.length)),paneId:"unrouted",position:PE(i.position),columns:Math.max(0,Math.round(xe(i.columns)??0)),rows:Math.max(0,Math.round(xe(i.rows)??0)),bgColor:se(i.bgcolor),frameColor:se(i.frame_color),frameWidth:Math.max(0,xe(i.frame_width)??0),borderColor:se(i.border_color),borderWidth:Math.max(0,xe(i.border_width)??0),cells:a,merges:o,overlay:i.force_overlay===!0})}return r}var hu=vn;function pu(t,e){let n=new Bi,r=[],i=[],s=[],a=[],o=[],l=[],c=[],u=[],p=[],h=[],d=[],f=[],m=new Map,_=new Set,b=[];for(let w of t.plots){let I=_c(w.style),E=w.title??w.key;switch(I){case"skip":break;case"barcolor":{if(!Sr(w.options.display))break;let A=Er(w.data.length,le(w.options.show_last));for(let F=A;F<w.data.length;F+=1){let N=w.data[F],j=se(N.options?.color);j&&f.push({time:N.time,color:j})}break}case"fill":Sr(w.options.display)&&b.push(w);break;case"hline":{let A=KE(w,E,e,n);A&&o.push(A);break}case"background":Sr(w.options.display)&&a.push(...YE(w,E,e,n));break;case"drawing_line":l.push(...tu(w,e,n));break;case"drawing_box":c.push(...su(w,e,n));break;case"label":u.push(...ou(w,e,n));break;case"drawing_polyline":p.push(...lu(w,e,n));break;case"linefill":h.push(...nu(w,e,n));break;case"table":d.push(...cu(w,e,n));break;case"markers":Sr(w.options.display)&&u.push(...GE(w,e,n));break;default:{let A=n.next(e,I,E);m.set(w.key,A),w.options.force_overlay===!0&&_.add(w.key),i.push(FE(I,w,A,E));let F=$E(w,E,e,n);F&&o.push(F)}}}for(let w of b){let I=w.plot1?m.get(w.plot1):void 0,E=w.plot2?m.get(w.plot2):void 0;if(!I||!E){r.push(`fill "${w.key}" references unknown plots (${w.plot1??"?"}/${w.plot2??"?"})`);continue}let A=_.has(w.plot1)&&_.has(w.plot2);s.push({id:n.next(e,"fill",w.title??w.key),paneId:"unrouted",fromSeriesId:I,toSeriesId:E,...HE(w),...A?{overlay:!0}:{}})}let v=t.trades?LE(t.trades):[];return{model:{id:e,title:t.meta.title,overlay:t.meta.overlay,paneHint:t.meta.overlay?"price":"new",series:i,fills:s,backgrounds:a,priceLines:o,lines:l,boxes:c,labels:u,polylines:p,linefills:h,tables:d,barColors:f.length?f:void 0,trades:v.length?v:void 0,inputs:[],inputValues:{}},warnings:r}}function LE(t){let e=new Map,n=r=>{let i=`${r.time}|${r.side}|${r.label??""}`,s=e.get(i);if(!s){e.set(i,r);return}s.qty=(s.qty??0)+(r.qty??0),r.kind==="entry"&&s.kind==="exit"&&(s.kind="entry",s.price=r.price,s.tradeId=r.tradeId)};for(let r of t){let i=r.size>0,s=Math.abs(r.size);n({time:r.entry_time,price:r.entry_price,side:i?"buy":"sell",kind:"entry",label:r.entry_comment??r.entry_id,qty:s,tradeId:r.id}),r.status==="closed"&&r.exit_time!=null&&r.exit_price!=null&&n({time:r.exit_time,price:r.exit_price,side:i?"sell":"buy",kind:"exit",label:r.exit_comment??r.exit_id,qty:s,tradeId:r.id})}return[...e.values()].sort((r,i)=>r.time-i.time)}function FE(t,e,n,r){let i=le(e.options.show_last),s=e.options.force_overlay===!0?{overlay:!0}:{},a=du(e.options.display);if(t==="candle"||t==="bar"){let m={id:n,title:r,paneId:"unrouted",kind:t,bars:qE(e,Er(e.data.length,i)),visible:a.pane,display:a,...s},_=jE(e);return _&&(m.barColors=_),m}let o=t,l=se(mu(e)),c={...a,pane:a.pane&&!!l},u=le(e.options.linewidth)??1,p=o==="line"||o==="step"||o==="area",h=zE(WE(UE(e),i,p),le(e.options.offset)),d={color:l??hu,width:u,lineStyle:yu(e.options.linestyle)??"solid"},f=le(e.options.histbase);return f!==void 0&&(o==="histogram"||o==="columns"||o==="area")&&(d.base=f),{id:n,title:r,paneId:"unrouted",kind:o,points:h,style:d,visible:c.pane,display:c,...s}}var uu={pane:!0,priceScale:!0,legend:!0,dataWindow:!0},BE={pane:"pane",data_window:"dataWindow",status_line:"legend",price_scale:"priceScale"},VE=["all","none","pane","data_window","status_line","price_scale"];function du(t){if(typeof t!="string")return{...uu};let e={pane:!1,priceScale:!1,legend:!1,dataWindow:!1};for(let n=0;n<t.length;){let r=VE.find(i=>t.startsWith(i,n));if(!r||r==="all")return{...uu};r!=="none"&&(e[BE[r]]=!0),n+=r.length}return e}function Sr(t){return du(t).pane}function Er(t,e){return e===void 0||e<=0?0:Math.max(0,t-Math.floor(e))}function WE(t,e,n){let r=Er(t.length,e);return n&&(r-=1),r<=0?t:t.map((i,s)=>s<r?{...i,value:null}:i)}function $E(t,e,n,r){if(t.options.trackprice!==!0)return null;for(let i=t.data.length-1;i>=0;i-=1){let s=t.data[i];if(!(typeof s.value!="number"||!Number.isFinite(s.value)))return{id:r.next(n,"hline",e),paneId:"unrouted",price:s.value,color:se(s.options?.color)??se(mu(t)),lineStyle:"dotted",width:le(t.options.linewidth),title:e}}return null}function jE(t){let e=!1,n=t.data.map(r=>{let i=r.options??{},s=se(i.color),a=se(i.wickcolor),o=se(i.bordercolor);return!s&&!a&&!o?null:(e=!0,{color:s,wickColor:a,borderColor:o})});return e?n:void 0}function UE(t){let e=t.data.some(n=>Mi(n.options?.color));return t.data.map(n=>{let r=typeof n.value=="number"&&Number.isFinite(n.value)?n.value:null,i=se(n.options?.color);return i?{time:n.time,value:r,color:i}:e?{time:n.time,value:r,color:bc}:{time:n.time,value:r}})}function fu(t){let e=[];for(let n=1;n<t.length;n+=1){let r=t[n].time-t[n-1].time;r>0&&e.push(r)}return e.length===0?0:(e.sort((n,r)=>n-r),e[e.length>>1]??0)}function zE(t,e){if(!e)return t;let n=e*fu(t);return n?t.map(r=>({...r,time:r.time+n})):t}function qE(t,e=0){let n=e>0?new Array(t.data.length):[];for(let r=e;r<t.data.length;r+=1){let i=t.data[r],s=i.value;if(!Array.isArray(s)||s.length<4)continue;let a={time:i.time,open:s[0]??0,high:s[1]??0,low:s[2]??0,close:s[3]??0};e>0?n[r]=a:n.push(a)}return n}function mu(t){for(let e of t.data)if(typeof e.options?.color=="string"&&e.options.color)return e.options.color;return U(t.options.color)}function HE(t){if(t.options.gradient===!0||t.data.some(s=>s.options&&(typeof s.options.top_color=="string"||typeof s.options.bottom_color=="string")))return{gradient:t.data.map(a=>{let o=a.options??{},l=le(o.top_value),c=le(o.bottom_value),u=typeof o.top_color=="string"?o.top_color:void 0,p=typeof o.bottom_color=="string"?o.bottom_color:void 0;return l===void 0||c===void 0||!u&&!p?null:{topValue:l,bottomValue:c,topColor:u??"rgba(0,0,0,0)",bottomColor:p??"rgba(0,0,0,0)"}})};let n=t.data.map(s=>se(s.options?.color)??null),r=new Set(n.filter(s=>s!==null)),i=n.some(s=>s===null);return r.size===0?{color:se(t.options.color)}:r.size===1&&!i?{color:[...r][0]}:{colors:n}}function KE(t,e,n,r){if(!Sr(t.options.display))return null;let i;for(let s of t.data)if(typeof s.value=="number"&&Number.isFinite(s.value)){i=s.value;break}return i===void 0?null:{id:r.next(n,"hline",e),paneId:"unrouted",price:i,color:se(t.options.color),lineStyle:yu(t.options.linestyle)??"dashed",title:e,width:le(t.options.linewidth)}}function yu(t){let e=U(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="solid"||e==="dashed"||e==="dotted"?e:void 0}function YE(t,e,n,r){let i=[],s=t.options.force_overlay===!0?{overlay:!0}:{},a=t.data,o=a.length>1?(a[1]?.time??0)-(a[0]?.time??0):0,l=Er(a.length,le(t.options.show_last));for(;l<a.length;){let c=a[l],u=se(c.options?.color);if(c.value===!0&&u){let p=c.time,h=c.time,d=l;for(;d+1<a.length;){let f=a[d+1];if(f.value===!0&&se(f.options?.color)===u)h=f.time,d+=1;else break}i.push({id:r.next(n,"background",e),paneId:"unrouted",from:p,to:h+o,color:u,...s}),l=d+1}else l+=1}return i}function GE(t,e,n){let r=le(t.options.offset),i=r?r*fu(t.data):0,s=t.style==="char"||t.options.char!==void 0,a=!s&&!("shape"in t.options)&&t.data.some(p=>p.options!==void 0&&"height"in p.options),o=a?XE(t):null,l=t.options.force_overlay===!0?{overlay:!0}:{},c=[],u=Er(t.data.length,le(t.options.show_last));for(let p=u;p<t.data.length;p+=1){let h=t.data[p],d=h.value,f=typeof d=="number"&&Number.isFinite(d);if(d!==!0&&!f||a&&(!f||d===0))continue;let m=h.options??t.options,_=m.color!==void 0?m.color:t.options.color;if(_!==void 0&&!Mi(_))continue;let b=U(m.text)??U(t.options.text),v=b&&b.trim().length>0?b:void 0,S=a?f&&d>0?kt:jt:void 0,w=se(m.color)??se(t.options.color)??S??hu,I=s?U(m.char)??U(t.options.char)??"\\u2605":void 0;c.push({id:n.next(e,"label",`${t.key}#${c.length}`),paneId:"unrouted",xloc:"bar_time",x:h.time+i,y:f?d:0,yloc:QE(U(m.location)??U(t.options.location)),text:I!==void 0?v!==void 0?`${I}\n${v}`:I:v,style:I!==void 0?"none":JE(U(m.shape)??U(t.options.shape)),color:w,textColor:se(m.textcolor)??se(t.options.textcolor)??(I!==void 0?w:void 0),size:o!==null&&f?ZE(Math.abs(d),o):eC(U(m.size)??U(t.options.size)),textAlign:"center",fontFamily:"default",...l})}return c}function XE(t){let e=0;for(let n of t.data)typeof n.value=="number"&&Number.isFinite(n.value)&&(e=Math.max(e,Math.abs(n.value)));return{maxAbs:e,minH:le(t.options.minheight)??5,maxH:le(t.options.maxheight)??100}}function ZE(t,e){let n=e.maxAbs>0?t/e.maxAbs:1,r=e.minH+n*(e.maxH-e.minH);return r<=12?"tiny":r<=24?"small":r<=44?"normal":r<=72?"large":"huge"}function QE(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function JE(t){switch((t??"").toLowerCase().replace(/^shape_/,"").replace(/_/g,"")){case"diamond":return"diamond";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"labelup":return"label_up";case"labeldown":return"label_down";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"square":return"square";case"cross":return"cross";case"xcross":return"xcross";case"flag":return"flag";default:return"circle"}}function eC(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function tC(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";case"source":return"source";case"color":return"color";case"price":return"price";case"time":return"time";case"session":return"session";case"timeframe":return"timeframe";case"symbol":return"symbol";case"text_area":return"text_area";default:return"string"}}function nC(t){return t==="int"||t==="float"||t==="price"||t==="time"}var gu={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 rC(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return gu[e]??t}function iC(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?gu[e[1].toLowerCase()]:void 0}function sC(t){return(t.type==="string"||t.type==null)&&iC(t.defval)!==void 0}function aC(t,e){if(e==="bool")return!!t;if(nC(e))return typeof t=="number"?t:Number(t)||0;let n=typeof t=="string"?t:t==null?"":String(t);return e==="color"?rC(n):n}function xu(t){return t.map((e,n)=>{let r=sC(e)?"color":tC(e.type);return{key:e.varId??e.title??`input${n}`,title:e.title??e.varId??`Input ${n+1}`,type:r,defval:aC(e.defval,r),min:e.minval,max:e.maxval,step:e.step,options:Array.isArray(e.options)?e.options.map(i=>String(i)):void 0,group:e.group,inline:e.inline,tooltip:e.tooltip}})}function oC(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";default:return"string"}}function Va(t,e){return e==="bool"?!!t:e==="int"||e==="float"?typeof t=="number"?t:Number(t)||0:typeof t=="string"?t:t==null?"":String(t)}function lC(t){let e=t.replace(/_/g," ");return e.charAt(0).toUpperCase()+e.slice(1)}function _u(t,e){let n=t.getPropsMeta(),r=t.prop;return n.filter(i=>i.mutable&&i.name).map(i=>{let s=i.name,a=oC(i.type),o=Va(i.defval,a),l=Va(r[s]??i.defval,a),c=e?.[s],u=l!==o?l:c!==void 0?Va(c,a):o;return{key:s,title:lC(s),type:a,defval:u,min:i.minval,max:i.maxval,options:Array.isArray(i.options)?i.options.map(p=>String(p)):void 0}})}function bu(t,e){for(let[n,r]of Object.entries(e))try{t.prop[n]=r}catch(i){console.warn(`[vela-pinets] prop "${n}" rejected:`,i instanceof Error?i.message:i)}}var vu=!1;function Wa(){if(vu)return;vu=!0;let t=$n.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!=="table")return;let s=this.pine.table,a=n;if(!s||typeof s.cell_set_text_formatting=="function"||typeof a._setCellProp!="function")return;let o=(c,u,p,h)=>a._setCellProp(c,u,p,"text_formatting",h);s.cell_set_text_formatting=(c,u,p,h)=>o(c,u,p,h);let l=s.cell;typeof l=="function"&&(s.cell=(...c)=>{let u=c[c.length-1],p=u&&typeof u=="object"&&!Array.isArray(u)&&"text_formatting"in u?u:null;if(!p&&c.length<14)return l(...c);let h=p?c.slice(0,-1):c.slice(0,13),d,f;if(p){let{text_formatting:S,...w}=p;d=S,f=Object.keys(w).length>0?[...h,w]:h}else d=c[13],f=h;let m=l(...f),_=p??{},b=h.length>1?h[1]:_.column??0,v=h.length>2?h[2]:_.row??0;return o(h[0],b,v,d),m})})}var wu=["plotshape","plotchar","plotarrow"],Su=!1;function $a(){if(Su)return;Su=!0;let t=$n.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!==void 0||!wu.some(a=>r.includes(a)))return;let s={idx:void 0,n:0,len:0};for(let a of wu){let o=this.pine[a];if(typeof o!="function")continue;let l=o;this.pine[a]=(...c)=>{let u=c[c.length-1];if(!(u!==null&&typeof u=="object"&&"__callsiteId"in u)){let h=this.idx;s.len===0&&s.idx!==void 0&&h!==s.idx&&(s.len=s.n,s.n=0),s.idx=h;let d=s.len>0?s.n%s.len:s.n;s.n+=1,c.push({__callsiteId:`~m${d}`})}return l(...c)}}})}function cC(t,e,n){if(n==="none")return[];if(n==="strategy"&&t.getDeclarationType()!=="strategy")return[];let r=_u(t,e);if(typeof n=="string")return r;let i=new Map(r.map(s=>[s.key,s]));return n.map(s=>i.get(s)).filter(s=>s!==void 0)}function ku(t,e,n,r="all"){let i=yn.from(t),s=xu(i.getInputsMeta()),a=cC(i,n,r),o=i.prop.overlay,l=typeof o=="boolean"?o:void 0,c=l??/(?<![\\w.$])overlay\\s*[:=]\\s*true/.test(t),p=/^\\s*(?:indicator|strategy)\\s*\\(\\s*(?:title\\s*=\\s*)?(["\'])((?:\\\\.|(?!\\1).)*)\\1/m.exec(t)?.[2]?.replace(/\\\\(.)/g,"$1").trim()||"Indicator",h=/chart\\.(left|right)_visible_bar(_time)?\\b/.test(t),d={source:t,instanceId:e,...l!==void 0?{declaredOverlay:l}:{}};return{language:"pine",inputs:s,...a.length>0?{props:a}:{},meta:{title:p,overlay:c},reactsToViewport:h,token:d}}function Ua(t,e,n,r={}){let i=JSON.stringify([n,r]);if(t.lastKey!==i||!t.lastInd){let s=new yn(e,n);bu(s,r),t.lastInd=s,t.lastKey=i}return t.lastInd}async function Au(t){let{ind:e,bars:n,market:r,visibleRange:i,prepared:s,instanceId:a,inputs:o,props:l,fetchSeries:c}=t;Wa(),$a();let u=za(n,r.timeframe,r.symbolInfo),p={getMarketData:(m,_,b,v,S)=>Tu(m,_,r)?Promise.resolve(u):Pu(c,m,_,b,v,S,$i(r,m)),getSymbolInfo:async m=>$i(r,m)},h=new on(p,qa(r),r.timeframe,u.length);await h.ready(),i&&h.setVisibleRange(i.left,i.right);let d=await h.run(e),f=typeof h.usesVisibleRange=="function"?h.usesVisibleRange():!1;return{model:va(d)?Mu(d,a,s,o,l??{},n[0]?.time):null,alerts:(d.alerts??[]).map(Ru),warnings:(d.warnings??[]).map(Ou),reactsToViewport:f,ctx:d}}function Mu(t,e,n,r,i,s){let{model:a}=pu(Ai(t),e),o=typeof i.overlay=="boolean"?i.overlay:n.token.declaredOverlay;return o!==void 0&&(a.overlay=o,a.paneHint=o?"price":"new"),a.inputs=n.inputs,a.inputValues={...Nu(n.inputs),...r},n.props&&(a.props=n.props,a.propValues={...Nu(n.props),...i}),s!=null&&(a.anchorTime=s),a}function Eu(t){if(typeof t!="string")return null;let e=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/.exec(t);return e?{start:Number(e[1])*60+Number(e[2]),end:Number(e[3])*60+Number(e[4])}:null}var ja=(t,e)=>e.start<=e.end?t>=e.start&&t<e.end:t>=e.start||t<e.end,Wi=new Map;function Cu(t,e){let n=`${e}:${Math.floor(t/36e5)}`,r=Wi.get(n);if(r==null){try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).formatToParts(t),s=a=>Number(i.find(o=>o.type===a)?.value??NaN);r=Math.round((Date.UTC(s("year"),s("month")-1,s("day"),s("hour")%24,s("minute"))-t)/6e4)}catch{r=NaN}Wi.size>1e5&&Wi.clear(),Wi.set(n,r)}return Number.isNaN(r)?null:((Math.floor(t/6e4)+r)%1440+1440)%1440}function uC(t){return t==null?null:/^\\d+$/.test(t)?Number(t):/^1?D$/i.test(t)?1440:null}function hC(t,e,n){let r=typeof n=="object"&&n!=null?n:null,i=uC(e),s=Eu(r?.session),a=typeof r?.timezone=="string"?r.timezone:null;if(i==null||s==null||a==null||t.length===0)return null;let o=Eu(r?.session_extended),l=s;if(o)for(let c of t){let u=Cu(c.time,a);if(u!=null&&!ja(u,s)&&ja(u,o)){l=o;break}}return c=>{let u=Cu(c,a);if(u==null||!ja(u,l))return null;let p=(l.end-u+1440)%1440||1440;return c+Math.min(i,p)*6e4}}function za(t,e,n){let r=hC(t,e,n);return t.map(i=>{let s={openTime:i.time,open:i.open,high:i.high,low:i.low,close:i.close,volume:i.volume??0},a=r?.(i.time);return a!=null&&(s.closeTime=a),s})}function qa(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function Tu(t,e,n){return(t==null||t===qa(n))&&(e==null||e===n.timeframe)}async function Pu(t,e,n,r,i,s,a){if(!t||!e||!n)return[];let o=await t(e,n,{from:i,to:s,limit:r});return za(o,n,a)}function pC(t,e,n){let r="",i=!1;return{markDirty:()=>{i=!0},getMarketData:async(s,a,o,l,c)=>{let u=e();if(!Tu(s,a,u))return Pu(n,s,a,o,l,c,$i(u,s));let p=za(t(),u.timeframe,u.symbolInfo);if(l==null)return p;let h=p.filter(m=>(m.openTime??0)>=l),d=h[h.length-1],f=d?`${h.length}|${d.openTime}|${d.close}|${d.high}|${d.low}|${d.volume}`:"";return!i&&f===r?[]:(i=!1,r=f,h)},getSymbolInfo:async s=>$i(e(),s)}}function Du(t){let e=t.bars();Wa(),$a();let n=Ua(t.cache,t.token.source,t.inputs,t.props??{}),r=e[0]?.time,i=Math.max(1,e.length),s=pC(t.bars,t.market,t.fetchSeries),a=new on(s,qa(t.market()),t.market().timeframe,i);t.visibleRange&&a.setVisibleRange(t.visibleRange.left,t.visibleRange.right);let o=a.stream(n,{live:!0,interval:1e3,pageSize:i}),l=!1,c=null;return o.on("data",u=>{if(!l&&(c=u,!!va(u)))try{t.onModel(Mu(u,t.token.instanceId,t.prepared,t.inputs,t.props??{},r))}catch(p){t.onError?.(p instanceof Error?p:new Error(String(p)))}}),o.on("alert",u=>t.onAlert?.(Ru(u))),o.on("warning",u=>t.onWarning?.(Ou(u))),o.on("error",u=>t.onError?.(u instanceof Error?u:new Error(String(u)))),{stop:()=>{l=!0,o.stop()},setVisibleRange:(u,p)=>{a.setVisibleRange(u,p),s.markDirty()},markDirty:()=>s.markDirty(),lastCtx:()=>c}}function $i(t,e){let n=e&&e.split(";")[0];return n&&n!==t.symbol?Iu({symbol:n,timeframe:t.timeframe}):Iu(t)}function Iu(t){if(t.symbolInfo)return t.symbolInfo;let e=t.symbol,n=e.replace(/(USDT|USDC|USD|PERP|BUSD)$/i,"")||e;return{ticker:e,tickerid:e,main_tickerid:e,description:e,prefix:"",root:e,type:"crypto",basecurrency:n,currency:"USD",timezone:"UTC",session:"regular",mintick:.01,minmove:1,pointvalue:1,pricescale:100}}function Nu(t){let e={};for(let n of t)e[n.key]=n.defval;return e}function Ru(t){return{id:String(t.id??""),message:String(t.message??""),title:t.title,time:Number(t.time??0),barIndex:Number(t.bar_index??0),freq:t.freq}}function Ou(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var lt=t=>le(t)??0;function Lu(t){if(t==null||typeof t!="object")return;let e=t;return{position:lt(e.position_size),avgPrice:lt(e.position_avg_price),equity:lt(e.equity),openPnl:lt(e.openprofit),netPnl:lt(e.netprofit),grossProfit:lt(e.grossprofit),grossLoss:lt(e.grossloss),wins:lt(e.wintrades),losses:lt(e.losstrades),even:lt(e.eventrades),maxDrawdown:lt(e.max_drawdown),maxRunup:lt(e.max_runup),initialCapital:lt(e.initial_capital)}}var ji=(t,e)=>{let n=le(e);return n===void 0?{}:{[t]:n}};function Fu(t){if(t==null||typeof t!="object")return[];let e=t,n=[];for(let r of[...Array.isArray(e.closedtrades)?e.closedtrades:[],...Array.isArray(e.opentrades)?e.opentrades:[]]){let i=r??{},s=le(i.entry_price),a=le(i.entry_time),o=le(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=le(i.exit_price),c=le(i.exit_time);n.push({id:U(i.id)??`trade_${n.length}`,side:o>0?"long":"short",qty:Math.abs(o),entry:{id:U(i.entry_id)??"",time:a,price:s,...U(i.entry_comment)!==void 0?{comment:U(i.entry_comment)}:{}},...l!==void 0&&c!==void 0?{exit:{id:U(i.exit_id)??"",time:c,price:l,...U(i.exit_comment)!==void 0?{comment:U(i.exit_comment)}:{}}}:{},open:i.status!=="closed",...ji("pnl",i.profit),...ji("commission",i.commission),...ji("maxDrawdown",i.max_drawdown),...ji("maxRunup",i.max_runup)})}return n}function Bu(t){try{return structuredClone(t)}catch{return}}function dC(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return Bu(e?e[e.length-1]:t)}function fC(t){return t.replace(/^glb\\d+_/,"")}function Ha(t,e){if(t)for(let[n,r]of Object.entries(t)){if(n.startsWith("_"))continue;let i=dC(r);i!==void 0&&(e[fC(n)]=i)}}function Vu(t,e,n){let r=t??{},i=r.fullContext??r,s=h=>!n||n.includes(h),a=s("meta")||s("plots")?Ai(t):null,o={};if(a&&s("plots"))for(let h of a.plots)h.key.startsWith("__")||(o[h.key]=h.data.map(d=>({time:d.time,value:Bu(d.value)??null})));let l={};s("variables")&&(Ha(i.const,l),Ha(i.var,l),Ha(i.let,l));let c=s("strategy")?Lu(i.strategy):void 0,u=s("trades")&&i.strategy?Fu(i.strategy):void 0,p=typeof i.idx=="number"?i.idx:typeof i.length=="number"?i.length-1:-1;return{language:"pine",phase:e,barIndex:p,meta:a&&s("meta")?{title:a.meta.title,overlay:a.meta.overlay,precision:a.meta.precision,shorttitle:a.meta.shorttitle}:{title:"",overlay:!1},plots:o,variables:l,...c?{strategy:c}:{},...u&&u.length>0?{trades:u}:{},warnings:s("warnings")?(i.warnings??[]).map(h=>({message:String(h.message??""),method:typeof h.method=="string"?h.method:void 0,bar:Number(h.bar??0)})):[]}}var Wu=self,Be=t=>Wu.postMessage(t),cn=new Map,Ya=new Map,mC=0,$u=(t,e,n)=>new Promise((r,i)=>{let s=++mC;Ya.set(s,{resolve:r,reject:i}),Be({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:n})});function Ui(t){t.chain=t.chain.then(()=>gC(t))}function yC(t,e){let n=t.bars[t.bars.length-1];n&&e.time===n.time?t.bars[t.bars.length-1]=e:(!n||e.time>n.time)&&t.bars.push(e)}function Ka(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=Du({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,props:t.props,bars:()=>t.bars,market:()=>t.market,fetchSeries:$u,visibleRange:t.visibleRange,onModel:e=>{t.stopped||Be({kind:"model",sessionId:t.id,model:e})},onAlert:e=>Be({kind:"alert",sessionId:t.id,alert:e}),onWarning:e=>Be({kind:"warning",sessionId:t.id,warning:e}),onError:e=>Be({kind:"error",sessionId:t.id,message:e.message})}))}async function gC(t){if(!t.stopped)try{let e=t.prepared.token,n=await Au({ind:Ua(t.cache,e.source,t.inputs,t.props),bars:t.bars,market:t.market,visibleRange:t.visibleRange,prepared:t.prepared,instanceId:e.instanceId,inputs:t.inputs,props:t.props,fetchSeries:$u});if(t.stopped)return;Be({kind:"reactsToViewport",sessionId:t.id,value:n.reactsToViewport});for(let r of n.alerts)Be({kind:"alert",sessionId:t.id,alert:r});for(let r of n.warnings)Be({kind:"warning",sessionId:t.id,warning:r});t.lastCtx=n.ctx,n.model&&Be({kind:"model",sessionId:t.id,model:n.model}),Be({kind:"done",sessionId:t.id})}catch(e){Be({kind:"error",sessionId:t.id,message:e instanceof Error?e.message:String(e)})}}Wu.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{Be({kind:"prepared",reqId:e.reqId,prepared:ku(e.source,e.instanceId,e.defaultProps,e.propsVisibility)})}catch(n){Be({kind:"prepared",reqId:e.reqId,error:n instanceof Error?n.message:String(n)})}return;case"execute":{let n={id:e.sessionId,mode:e.mode??"static",prepared:e.prepared,market:e.market,bars:e.bars,inputs:e.inputs,props:e.props??{},visibleRange:e.visibleRange,cache:{},stopped:!1,deferred:e.historyState==="backfill",chain:Promise.resolve(),stream:null,lastCtx:null};if(cn.set(n.id,n),n.mode==="live"){n.deferred||Ka(n);return}n.deferred?Be({kind:"done",sessionId:n.id}):Ui(n);return}case"update":{let n=cn.get(e.sessionId);if(!n)return;if(n.inputs={...n.inputs,...e.inputs},e.props&&(n.props={...n.props,...e.props}),n.mode==="live"){n.deferred||Ka(n);return}n.deferred?Be({kind:"done",sessionId:n.id}):Ui(n);return}case"setVisibleRange":{let n=cn.get(e.sessionId);if(!n)return;if(n.visibleRange=e.range,n.mode==="live"){n.stream?.setVisibleRange(e.range.left,e.range.right);return}n.deferred?Be({kind:"done",sessionId:n.id}):Ui(n);return}case"notifyBars":{let n=cn.get(e.sessionId);if(!n||n.mode==="live")return;n.bars=e.bars,n.deferred=!1,Ui(n);return}case"bars":{let n=cn.get(e.sessionId);if(!n||n.mode!=="live")return;if(e.restart){n.bars=e.bars,n.deferred=!1,Ka(n);return}for(let r of e.bars)yC(n,r);return}case"getContext":{let n=cn.get(e.sessionId),r=n?n.mode==="live"?n.stream?.lastCtx()??null:n.lastCtx:null,i=!n||n.stopped?"idle":n.mode==="live"?"streaming":"idle";Be({kind:"contextResult",reqId:e.reqId,snapshot:r==null?null:Vu(r,i,e.select)});return}case"stop":{let n=cn.get(e.sessionId);n&&(n.stopped=!0,n.stream?.stop()),cn.delete(e.sessionId);return}case"fetchSeriesResult":{let n=Ya.get(e.reqId);if(!n)return;Ya.delete(e.reqId),e.error?n.reject(new Error(e.error)):n.resolve(e.bars??[]);return}}});})();\n';
|
|
1728
|
+
var worker_default = '"use strict";(()=>{var xd=Object.defineProperty;var bd=(t,e,n)=>e in t?xd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var jl=(t,e,n)=>bd(t,typeof e!="symbol"?e+"":e,n);function vd(t){return e=>new Y(e.array.map(n=>Math.abs(n)),e.type,t)}function wd(t){return e=>{let n=0,r=0;for(let i of e.array){let s=Number(i);isNaN(s)||(r++,n+=(s-n)/r)}return r===0?NaN:t.precision(n)}}var Sd=Object.defineProperty,Ed=(t,e,n)=>e in t?Sd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nd=(t,e,n)=>Ed(t,typeof e!="symbol"?e+"":e,n),Ht=class t{constructor(e,n,r){this._definition=e,this.context=n,Nd(this,"_udt");for(let i in e)this[i]=e[i];this._udt=r}get __def__(){return this._definition}copy(){return new t(this.__def__,this.context,this._udt)}toString(){let e={};for(let n in this.__def__){let r=this[n];r!=null&&typeof r=="object"&&typeof r.toString=="function"&&!(r instanceof Array)?e[n]=r.toString():e[n]=r}try{return JSON.stringify(e)}catch{return"{"+Object.keys(e).map(n=>`"${n}":${String(e[n])}`).join(",")+"}"}}},Cd=Object.defineProperty,Id=(t,e,n)=>e in t?Cd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kd=(t,e,n)=>Id(t,typeof e!="symbol"?e+"":e,n),y=class t{constructor(e,n=0){this.data=e,this.offset=n,kd(this,"beforeStart",NaN)}get(e){(e==null||Number.isNaN(e))&&(e=0);let n=this.offset+e;Number.isInteger(n)||(n=Math.trunc(n));let r=this.data.length-1-n;return r<0?this.beforeStart:r>=this.data.length?NaN:this.data[r]}set(e,n){let r=this.data.length-1-(this.offset+e);r>=0&&r<this.data.length&&(this.data[r]=n)}get length(){return this.data.length}toArray(){return this.data}static from(e){if(e instanceof t)return e;if(Array.isArray(e))return new t(e);if(e!=null&&typeof e=="object"&&"__value"in e){let n=e.__value;if(n instanceof t)return n;if(n===null||typeof n!="object")return new t([n])}return new t([e])}};function Ad(t){if(!t||typeof t!="string")return null;if(t.startsWith("#")){let n=t.slice(1);return n.length===6?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),1]:n.length===8?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),parseInt(n.slice(6,8),16)/255]:null}let e=t.match(/rgba?\\(\\s*(\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\s*\\)/);return e?[parseInt(e[1]),parseInt(e[2]),parseInt(e[3]),e[4]?parseFloat(e[4]):1]:null}function Md(t,e,n,r){let i=Math.round(Math.max(0,Math.min(255,t))).toString(16).padStart(2,"0"),s=Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0"),a=Math.round(Math.max(0,Math.min(255,n))).toString(16).padStart(2,"0");if(r>=1)return`#${i}${s}${a}`.toUpperCase();let o=Math.round(Math.max(0,Math.min(255,r*255))).toString(16).padStart(2,"0");return`#${i}${s}${a}${o}`.toUpperCase()}var Oe={aqua:"#00BCD4",black:"#363A45",blue:"#2962FF",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 kr(t){if(typeof t!="string")return null;let e=t.trim(),n=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(Oe,n)&&(e=Oe[n]),Ad(e)}function Di(t,e,n,r){let i=s=>Math.round(Math.max(0,Math.min(255,s))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(n)}${i(r*255)}`.toUpperCase()}function Td(t){let e=kr(t);return e?Di(e[0],e[1],e[2],e[3]):t}function pn(t){return typeof t=="function"&&(t=t()),t&&typeof t=="object"&&Array.isArray(t.data)&&typeof t.get=="function"&&(t=t.get(0)),t}var dn=t=>t==null||typeof t=="number"&&isNaN(t),bi=(t,e,n)=>Math.min(n,Math.max(e,t)),Vs="#00000000";function ir(t){if(t=pn(t),dn(t))return[0,0,0,0];let e=kr(t);return e?[e[0],e[1],e[2],Math.round(e[3]*255)/255]:null}var sa=class{constructor(e){this.context=e}any(e){let n=y.from(e).get(0);return typeof n=="number"&&isNaN(n)?null:n}param(e,n=0){return y.from(e).get(n)}new(e,n){if(e=pn(e),n=pn(n),n===void 0||(n=dn(n)?100:bi(Math.trunc(n),0,100),dn(e)&&(e="#000000"),typeof e!="string"))return e;let r=Math.round(255*(100-n)/100).toString(16).padStart(2,"0").toUpperCase();if(e.startsWith("#")){let a=e.slice(1);return`#${a.length===8?a.slice(0,6):a}${r}`}let i=Oe[e];if(i)return`#${i.slice(1)}${r}`;let s=e.match(/rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([\\d.]+))?\\s*\\)/);if(s){let[a,o,l]=[s[1],s[2],s[3]].map(c=>parseInt(c).toString(16).padStart(2,"0"));return`#${a}${o}${l}${r}`}return`rgba(${e}, ${(100-n)/100})`}rgb(e,n,r,i){let s=u=>(u=pn(u),dn(u)?0:bi(Math.trunc(u),0,255)),[a,o,l]=[s(e),s(n),s(r)];if(i=pn(i),i===void 0)return`rgb(${a}, ${o}, ${l})`;let c=dn(i)?100:bi(i,0,100);return`rgba(${a}, ${o}, ${l}, ${(100-c)/100})`}from_gradient(e,n,r,i,s){if(e=pn(e),n=pn(n),r=pn(r),dn(e)||dn(n)||dn(r)||r===n)return Vs;if(r<n)return i=pn(i),dn(i)?Vs:i;let a=ir(i)??[0,0,0,0],o=ir(s)??[0,0,0,0],l=1-bi((e-n)/(r-n),0,1),c=1-l,u=a[3]*l+o[3]*c;if(u===0)return Vs;let p=h=>Math.trunc((a[h]*a[3]*l+o[h]*o[3]*c)/u);return Md(p(0),p(1),p(2),Math.trunc(u*255)/255)}r(e){return ir(e)?.[0]??NaN}g(e){return ir(e)?.[1]??NaN}b(e){return ir(e)?.[2]??NaN}t(e){let n=ir(e);return n?Math.round((1-n[3])*100):NaN}aqua(){return Oe.aqua}black(){return Oe.black}blue(){return Oe.blue}fuchsia(){return Oe.fuchsia}gray(){return Oe.gray}green(){return Oe.green}lime(){return Oe.lime}maroon(){return Oe.maroon}navy(){return Oe.navy}olive(){return Oe.olive}orange(){return Oe.orange}purple(){return Oe.purple}red(){return Oe.red}silver(){return Oe.silver}teal(){return Oe.teal}white(){return Oe.white}yellow(){return Oe.yellow}},yn=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(yn||{}),fo=(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))(fo||{}),mo=(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))(mo||{}),yo=(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))(yo||{}),Oi=["pane","data_window","status_line","price_scale"],Pd=[...Oi,"all","none"];function Ri(t){let e=new Set;if(typeof t!="string")return e;for(let n=0;n<t.length;){let r=Pd.find(i=>t.startsWith(i,n));if(!r)break;if(r==="all")return new Set(Oi);r!=="none"&&e.add(r),n+=r.length}return e}function Xc(t){let e=Oi.filter(n=>t.has(n));return e.length===Oi.length?"all":e.length===0?"none":e.join("")}function Zc(t,e){return Xc(new Set([...Ri(t),...Ri(e)]))}function Qc(t,e){let n=Ri(t);for(let r of Ri(e))n.delete(r);return Xc(n)}var go=(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))(go||{}),_o=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(_o||{}),xo=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(xo||{}),bo=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(bo||{}),Jc=(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))(Jc||{}),vo=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(vo||{}),wo=(t=>(t.bar_index="bi",t.bar_time="bt",t))(wo||{}),So=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(So||{}),Eo=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Eo||{}),No=(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))(No||{}),Co=(t=>(t.family_default="default",t.family_monospace="monospace",t))(Co||{}),Io=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(Io||{}),ko=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(ko||{}),Ao=(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))(Ao||{}),Mo=(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))(Mo||{}),To=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(To||{}),Po=(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))(Po||{}),Do=(t=>(t.left="left",t.none="none",t.right="right",t))(Do||{}),Oo=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(Oo||{}),eu={order:yn,currency:fo,dayofweek:mo,display:{...yo,__union:Zc,__minus:Qc},shape:go,location:_o,size:xo,format:bo,barmerge:vo,xloc:wo,yloc:So,extend:Eo,text:No,font:Co,adjustment:Io,backadjustment:ko,earnings:Ao,dividends:Mo,splits:To,position:Po,scale:Do,settlement_as_close:Oo},Dd=Object.freeze({__proto__:null,order:yn,currency:fo,dayofweek:mo,display:yo,displayUnion:Zc,displayMinus:Qc,shape:go,location:_o,size:xo,format:bo,plot:Jc,barmerge:vo,xloc:wo,yloc:So,extend:Eo,text:No,font:Co,adjustment:Io,backadjustment:ko,earnings:Ao,dividends:Mo,splits:To,position:Po,scale:Do,settlement_as_close:Oo,default:eu}),Od=Object.defineProperty,Rd=(t,e,n)=>e in t?Od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ld=(t,e,n)=>Rd(t,typeof e!="symbol"?e+"":e,n),ye=class extends Error{constructor(e,n){super(e),Ld(this,"method"),this.name="PineRuntimeError",this.method=n}};function Ce(t){return t==null||typeof t=="number"&&isNaN(t)}var Fd=/^(#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?|rgba?\\(.*\\))$/;function Li(t){if(typeof t!="string"||!Fd.test(t))return null;let e=kr(t);return e?Di(e[0],e[1],e[2],e[3]):null}function Wl(t,e){if(typeof t=="number"&&typeof e=="number")return Math.abs(t-e)<=1e-10;if(t===e)return!0;if(typeof t=="string"&&typeof e=="string"){let n=Li(t);return n!==null&&n===Li(e)}return!1}function Ro(t,e){if(t.type===H.string){let n=Ce(e)?"":e;return r=>Wl(Ce(r)?"":r,n)}return Ce(e)?t.type===H.color&&!(t.context?.pineVersion>=6)?Ce:()=>!1:n=>!Ce(n)&&Wl(n,e)}function li(t,e){let n;for(let i=0;i<t.length;i++)if(t[i]instanceof Ht){n=t[i];break}if(!n)return null;let r;return typeof e=="string"?r=e:r=(n._udt?._definitionKeys??Object.keys(n.__def__))[e??0],i=>i instanceof Ht?i[r]:NaN}function tu(t,e,n){let r=Ce(t),i=Ce(e);return r||i?r&&i?0:(r?1:-1)*(n?-1:1):n?t<e?-1:t>e?1:0:t-e}function nu(t,e=yn.ascending){let n=t.some(i=>typeof i=="string"),r=t.map((i,s)=>s);return r.sort((i,s)=>tu(t[i],t[s],n)||i-s),e!==yn.ascending&&r.reverse(),r}function Vd(t,e=yn.ascending){let n=t.some(r=>typeof r=="string");return t.sort((r,i)=>tu(r,i,n)),e!==yn.ascending&&t.reverse(),t}function jn(t,e,n){throw new ye(`Index ${t} is out of bounds, array size is ${e}.`,n)}function hs(t){throw new ye(`Cannot call \\`${t}()\\` if array is empty.`,`array.${t}`)}function ru(t,e){if(t<0||t>100)throw new ye(`Invalid value of the \'percentage\' argument (${t}) in the \'${e}\' function. It must be in the range [0..100].`,e)}function Bd(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?H.int:H.float:t.every(e=>typeof e=="string")?H.string:t.every(e=>typeof e=="boolean")?H.bool:H.any}function an(t){return typeof t=="number"?Number.isInteger(t)?H.int:H.float:typeof t=="string"?H.string:typeof t=="boolean"?H.bool:H.any}function ci(t,e){if(t===void 0||typeof t=="number"&&isNaN(t)||e===H.any)return!0;switch(e){case H.int:return Number.isInteger(t)||isNaN(t);case H.float:return typeof t=="number";case H.string:return typeof t=="string";case H.bool:return typeof t=="boolean";case H.box:case H.label:case H.line:case H.linefill:case H.table:case H.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function $d(t){return(e,n,r)=>{let i=e.array,s=li(i,r)??(l=>l),a=0,o=i.length-1;for(;a<=o;){let l=Math.floor((a+o)/2),c=s(i[l]);if(c===n)return l;c<n?a=l+1:o=l-1}return-1}}function jd(t){return(e,n,r)=>{let i=e.array,s=li(i,r)??(l=>l),a=0,o=i.length;for(;a<o;){let l=Math.floor((a+o)/2);s(i[l])<n?a=l+1:o=l}return a<i.length&&s(i[a])===n?a:Math.max(a-1,0)}}function Wd(t){return(e,n,r)=>{let i=e.array,s=li(i,r)??(l=>l),a=0,o=i.length;for(;a<o;){let l=Math.floor((a+o)/2);s(i[l])<=n?a=l+1:o=l}return a>0&&s(i[a-1])===n?a-1:a}}function Ud(t){return e=>{e.array.length=0}}function qd(t){return(e,n)=>(e.array.push(...n.array),e)}function zd(t){return e=>new Y([...e.array],e.type,t)}function Hd(t){return(e,n,r=!0)=>{let i=e.array,s=n.array;if(i.length!==s.length)return NaN;let a=0,o=0,l=0,c=[];for(let f=0;f<i.length;f++){let m=Number(i[f]),_=Number(s[f]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(_)&&_!==null&&_!==void 0&&(a+=m,o+=_,l++,c.push(f))}if(l===0)return NaN;let u=a/l,p=o/l,h=0;for(let f of c){let m=Number(i[f]),_=Number(s[f]);h+=(m-u)*(_-p)}let d=r?l:l-1;return d<=0?NaN:t.precision(h/d)}}function Kd(t){return e=>e.array.length===0?!1:e.array.every(n=>!isNaN(n)&&n)}function Gd(t){return(e,n,r=0,i)=>{let s=e.array.length,a=Ce(r)?0:r,o=i===void 0||Ce(i)?s:i;if((a<0||a>=s)&&jn(a,s,"array.fill"),(o<0||o>s)&&jn(o,s,"array.fill"),!ci(n,e.type))throw new Error(`Cannot call \'array.fill\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);let l=typeof n=="number"?t.precision(n):n;for(let c=a;c<o;c++)e.array[c]=l}}function Yd(t){return e=>(e.array.length===0&&hs("first"),e.array[0])}function Xd(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new ye(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.get");return e.array[r]}}function Zd(t){return(e,n)=>e.array.some(Ro(e,n))}function Qd(t){return(e,n)=>e.array.findIndex(Ro(e,n))}function Jd(t){return(e,n,r)=>{if(!ci(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.`);let i=n<0?e.array.length+n:n;if(i<0||i>e.array.length)throw new ye(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.insert");e.array.splice(i,0,r)}}function Fi(t,e=0){let n=String(t).match(/^(\\d+)(?:\\.(\\d+))?(?:e([+-]\\d+))?$/);if(!n)return[String(t),""];let r=n[1]+(n[2]??""),i=n[1].length+Number(n[3]??0)+e;return i<=0&&(r="0".repeat(1-i)+r,i=1),i>r.length&&(r+="0".repeat(i-r.length)),[r.slice(0,i),r.slice(i)]}function ef(t,e,n){let r=new DataView(new ArrayBuffer(8));r.setFloat64(0,t);let i=r.getBigUint64(0),s=Number(i>>52n&0x7ffn),a=i&(1n<<52n)-1n,o;s===0?o=-1074:(a|=1n<<52n,o=s-1075);let l=a*10n**BigInt(n.length),c=BigInt(e+n||"0");return o>=0?l<<=BigInt(o):c<<=BigInt(-o),l>c?1:l<c?-1:0}function Vi(t,e,n,r,i){if(n.length<=r)return[e,n];let s=e+n.slice(0,r),a=Number(n[r]),o=n.slice(r+1),l;if(a!==5||/[1-9]/.test(o))l=a>=5;else if(i==="halfUp")l=!0;else if(!/[1-9]/.test(s))l=!1;else{let u=ef(t,e,n);l=u>0||u===0&&Number(s[s.length-1])%2===1}if(l){let u=s.split(""),p=u.length-1;for(;p>=0&&u[p]==="9";)u[p--]="0";p>=0?u[p]=String(Number(u[p])+1):u.unshift("1"),s=u.join("")}let c=s.length-r;return[s.slice(0,c),s.slice(c)]}function tf(t){let e=0,n=!1,r=o=>{let l="",c=!1;for(;e<t.length;){let u=t[e];if(u==="\'"){if(t[e+1]==="\'"){l+="\'",e+=2;continue}c=!c,e++;continue}if(!c&&o(u))break;!c&&u==="%"&&(n=!0),l+=u,e++}return l},i=r(o=>/[#0,.]/.test(o)),s="";for(;e<t.length&&/[#0,.]/.test(t[e]);)s+=t[e++];let a=r(()=>!1);return{prefix:i,number:s,suffix:a,percent:n}}function dr(t,e,n){if(!Number.isFinite(t))return String(t);let{prefix:r,number:i,suffix:s,percent:a}=tf(e),[o,l=""]=i.split(".");if(!/[#0]/.test(i)){let[I]=Vi(Math.abs(t),...Fi(Math.abs(t)),0,n);return(t<0?"-":"")+r+s+(I.replace(/^0+(?=\\d)/,"")||"0")}let c=a?100:1,u=(o.match(/0/g)??[]).length,p=o.lastIndexOf(","),h=p>=0?o.length-p-1:0,d=(l.match(/0/g)??[]).length,f=l.length,m=Math.abs(t),[_,x]=Fi(m,c===100?2:0),[w,S]=Vi(m*c,_,x,f,n),v=!/[1-9]/.test(w+S),E=w.replace(/^0+/,""),C=S.padEnd(f,"0");for(;C.length>d&&C.endsWith("0");)C=C.slice(0,-1);return E.length<u&&(E=E.padStart(u,"0")),!E&&d===0&&(E="0"),h>0&&(E=E.replace(new RegExp(`\\\\B(?=(\\\\d{${h}})+(?!\\\\d))`,"g"),",")),(t<0&&(n==="halfEven"||!v)?"-":"")+r+E+(C?"."+C:"")+s}function iu(t){if(!Number.isFinite(t))return String(t);let e=Math.abs(t),n=t<0?"-":"";if(e>=1e21){let[o,l]=e.toExponential().split("e"),[c,u]=Vi(e,o.split(".")[0],o.split(".")[1]??"",10,"halfUp"),p=Number(l);return c.length>1&&(u=c.slice(1)+u,c=c[0],p++),u=u.replace(/0+$/,""),n+c+(u?"."+u:"")+"E"+p}let[r,i]=Vi(e,...Fi(e),10,"halfEven"),s=i.replace(/0+$/,""),a=r.replace(/^0+(?=\\d)/,"");return/[1-9]/.test(a+s)?n+a+(s?"."+s:""):"0"}function nf(t){if(Number.isNaN(t))return"NaN";if(!Number.isFinite(t))return t>0?"Infinity":"-Infinity";if(t===0)return"0.0";let e=Math.abs(t),n=t<0?"-":"";if(e>=.001&&e<1e7){let[o,l]=Fi(e);return n+o+"."+(l||"0")}let[r,i]=e.toExponential().split("e"),[s,a]=r.split(".");return n+s+"."+(a||"0")+"E"+Number(i)}var rf=[[1e12,"T"],[1e9,"B"],[1e6,"M"],[1e3,"K"]];function sf(t){if(!Number.isFinite(t))return String(t);let e=Math.abs(t),n=rf.find(([s])=>e>=s),r=n?e/n[0]:e,i=dr(r,n?"#.###":"#","halfUp");return(t<0&&i!=="0"?"-":"")+i+(n?n[1]:"")}var Ul=t=>t==null||typeof t=="number"&&Number.isNaN(t);function su(t,e,n){return t.type==="string"?Ul(e)?"":String(e):typeof e=="number"?n(e):Ul(e)?"NaN":String(e)}function af(t){return Array.from(t.array,e=>su(t,e,iu))}function au(t){let e=t.type==="float"||t.type!=="int"&&t.array.some(n=>typeof n=="number"&&!Number.isInteger(n)&&!Number.isNaN(n));return Array.from(t.array,n=>su(t,n,r=>Number.isNaN(r)?"NaN":e?nf(r):String(r)))}function of(t){return(e,n="")=>au(e).join(n)}function lf(t){return e=>(e.array.length===0&&hs("last"),e.array[e.array.length-1])}function cf(t){return(e,n)=>{let r=e.array,i=Ro(e,n);for(let s=r.length-1;s>=0;s--)if(i(r[s]))return s;return-1}}function uf(t){return(e,n=0)=>{let r=e.array,i=r.length;if(i===0)return t.NA;if(Ce(n)&&(n=0),(n<0||n>=i)&&jn(n,i,"array.max"),n===0){let a=NaN;for(let o=0;o<i;o++){let l=r[o];!Ce(l)&&!(l<=a)&&(a=l)}return a}let s=r.filter(a=>!Ce(a)).sort((a,o)=>o-a);return s.length?s[Math.min(n,s.length-1)]:t.NA}}function hf(t){return e=>{let n=e.array.filter(i=>!Ce(i)).sort((i,s)=>i-s);if(n.length===0)return NaN;let r=Math.floor(n.length/2);return n.length%2!==0?n[r]:(n[r-1]+n[r])/2}}function pf(t){return(e,n=0)=>{let r=e.array,i=r.length;if(i===0)return t.NA;if(Ce(n)&&(n=0),(n<0||n>=i)&&jn(n,i,"array.min"),n===0){let a=NaN;for(let o=0;o<i;o++){let l=r[o];!Ce(l)&&!(l>=a)&&(a=l)}return a}let s=r.filter(a=>!Ce(a)).sort((a,o)=>a-o);return s.length?s[Math.min(n,s.length-1)]:t.NA}}function df(t){return e=>{let n=new Map,r=0;for(let s of e.array){if(Ce(s))continue;let a=(n.get(s)||0)+1;n.set(s,a),a>r&&(r=a)}let i=[];for(let[s,a]of n)a===r&&i.push(s);return i.sort((s,a)=>typeof s=="number"&&typeof a=="number"?s-a:typeof s=="string"&&typeof a=="string"?s<a?-1:s>a?1:0:0),i.length?i[0]:NaN}}var ff="array.percentile_linear_interpolation";function mf(t){return(e,n)=>{if(Ce(n))return NaN;ru(n,ff);let r=e.array,i=r.length;if(i===0)return NaN;let s=[];for(let u=0;u<i;u++){let p=r[u];Ce(p)||s.push(Number(p))}let a=s.length<i;for(s.sort((u,p)=>u-p);s.length<i;)s.push(NaN);let o=n*i/100-.5;if(o<=0)return t.precision(s[0]);if(o>=i-1)return t.precision(s[i-1]);let l=Math.floor(o),c=o-l;return c===0?t.precision(s[l]):a?NaN:t.precision(s[l]*(1-c)+s[l+1]*c)}}function yf(t){return(e,n)=>{if(Ce(n))return NaN;ru(n,"array.percentile_nearest_rank");let r=e.array,i=r.length;if(i===0)return NaN;let s=new Array;for(let o=0;o<i;o++){let 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);let a=Math.ceil(n/100*i);return a<=0?s[0]:a>s.length?NaN:s[a-1]}}function gf(t){return(e,n)=>{let r=e.array.length;if(r===0)return NaN;(n<0||n>=r)&&jn(n,r,"array.percentrank");let i=e.array[Math.floor(n)];if(Ce(i))return NaN;let s=0;for(let o of e.array)!Ce(o)&&o<=i&&s++;let a=r-1;return a<=0?NaN:(s-1)/a*100}}function _f(t){return e=>(e.array.length===0&&hs("pop"),e.array.pop())}function xf(t){return(e,n)=>{if(!ci(n,e.type))throw new Error(`Cannot call \'array.push\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);e.array.push(typeof n=="number"?t.precision(n):n)}}function bf(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function vf(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new ye(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.remove");return e.array.splice(r,1)[0]}}function wf(t){return e=>{e.array.reverse()}}function Sf(t){return(e,n,r)=>{if(!ci(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.`);let i=n<0?e.array.length+n:n;if(i<0||i>=e.array.length)throw new ye(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.set");e.array[i]=typeof r=="number"?t.precision(r):r}}function Ef(t){return e=>(e.array.length===0&&hs("shift"),e.array.shift())}function Nf(t){return e=>e.array.length}function Br(t){if(typeof t!="string"||!/^(0|[1-9]\\d*)$/.test(t))return-1;let e=Number(t);return e<=4294967294?e:-1}function Cf(t,e,n){let r=[];r.length=n;let i=s=>{let a=r.length;s<a?t.splice(e+s,a-s):s>a&&t.splice(e+a,0,...new Array(s-a)),r.length=s};return new Proxy(r,{get(s,a,o){let l=Br(a);return l!==-1?l<s.length?t[e+l]:void 0:Reflect.get(s,a,o)},set(s,a,o,l){if(a==="length")return i(Number(o)),!0;let c=Br(a);return c!==-1?(c>=s.length&&i(c+1),t[e+c]=o,!0):Reflect.set(s,a,o,l)},has(s,a){let o=Br(a);return o!==-1?o<s.length:Reflect.has(s,a)},deleteProperty(s,a){let o=Br(a);return o!==-1?(o<s.length&&(t[e+o]=void 0),!0):Reflect.deleteProperty(s,a)},ownKeys(s){let a=[];for(let o=0;o<s.length;o++)a.push(String(o));return a.concat(Reflect.ownKeys(s))},getOwnPropertyDescriptor(s,a){let o=Br(a);return o!==-1?o>=s.length?void 0:{value:t[e+o],writable:!0,enumerable:!0,configurable:!0}:Reflect.getOwnPropertyDescriptor(s,a)}})}function If(t){return(e,n=0,r)=>{let i=e.array.length,s=Ce(n)?0:n,a=r===void 0||Ce(r)?i:r;if((s<0||s>=i)&&jn(s,i,"array.slice"),(a<0||a>i)&&jn(a,i,"array.slice"),s>a)throw new ye("Index \'from\' should be less than index \'to\'.","array.slice");return new Y(Cf(e.array,s,a-s),e.type,t)}}function kf(t){return e=>e.array.some(n=>!isNaN(n)&&n)}function Af(t){return(e,n=yn.ascending,r)=>{let i=e.array,s=Array.from(i),a=li(s,r),o=a?nu(s.map(a),n).map(l=>s[l]):Vd(s,n);for(let l=0;l<o.length;l++)i[l]=o[l]}}function Mf(t){return(e,n=yn.ascending,r)=>{let i=Array.from(e.array),s=li(i,r);return new Y(nu(s?i.map(s):i,n),H.int,t)}}function Tf(t){return e=>{let n=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new Y(e.array.map(()=>NaN),H.float,t):r===0?new Y(e.array.map(()=>1),H.float,t):new Y(e.array.map(i=>(i-n)/r),H.float,t)}}function Pf(t){return(e,n=!0)=>{let r=e.array,i=r.length;if(i===0)return NaN;let s=0,a=0,o=0;for(let u=0;u<i;u++){let p=Number(r[u]);!isNaN(p)&&p!==null&&p!==void 0&&(s+=p,a+=p*p,o++)}if(o===0)return NaN;let l=s/o,c=a/o-l*l;return c<0?NaN:(!n&&o>1&&(c=c*o/(o-1)),!n&&o===1?NaN:t.precision(Math.sqrt(c)))}}function Df(t){return e=>{let n=0,r=0;for(let i of e.array){let s=Number(i);isNaN(s)||(n+=s,r++)}return r===0?NaN:t.precision(n)}}function Of(t){return(e,n)=>{if(!ci(n,e.type))throw new Error(`Cannot call \'array.unshift\' with argument \'value\'=\'${n}\'. An argument of \'literal ${typeof n}\' type was used but a \'${e.type}\' is expected.`);e.array.unshift(typeof n=="number"?t.precision(n):n)}}function Rf(t){return(e,n=!0)=>{let r=0,i=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(r+=c,i++)}if(i===0)return NaN;let s=r/i,a=0;for(let l of e.array){let c=Number(l);!isNaN(c)&&c!==null&&c!==void 0&&(a+=(c-s)*(c-s))}let o=n?i:i-1;return o<=0?NaN:t.precision(a/o)}}var Lf=Object.defineProperty,Ff=(t,e,n)=>e in t?Lf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e,n)=>Ff(t,typeof e!="symbol"?e+"":e,n),H=(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))(H||{}),Y=class{constructor(e,n,r){this.array=e,this.type=n,this.context=r,ee(this,"_abs"),ee(this,"_avg"),ee(this,"_binary_search"),ee(this,"_binary_search_leftmost"),ee(this,"_binary_search_rightmost"),ee(this,"_clear"),ee(this,"_concat"),ee(this,"_copy"),ee(this,"_covariance"),ee(this,"_every"),ee(this,"_fill"),ee(this,"_first"),ee(this,"_get"),ee(this,"_includes"),ee(this,"_indexof"),ee(this,"_insert"),ee(this,"_join"),ee(this,"_last"),ee(this,"_lastindexof"),ee(this,"_max"),ee(this,"_median"),ee(this,"_min"),ee(this,"_mode"),ee(this,"_percentile_linear_interpolation"),ee(this,"_percentile_nearest_rank"),ee(this,"_percentrank"),ee(this,"_pop"),ee(this,"_push"),ee(this,"_range"),ee(this,"_remove"),ee(this,"_reverse"),ee(this,"_set"),ee(this,"_shift"),ee(this,"_size"),ee(this,"_slice"),ee(this,"_some"),ee(this,"_sort"),ee(this,"_sort_indices"),ee(this,"_standardize"),ee(this,"_stdev"),ee(this,"_sum"),ee(this,"_unshift"),ee(this,"_variance"),this._abs=vd(this.context),this._avg=wd(this.context),this._binary_search=$d(this.context),this._binary_search_leftmost=jd(this.context),this._binary_search_rightmost=Wd(this.context),this._clear=Ud(this.context),this._concat=qd(this.context),this._copy=zd(this.context),this._covariance=Hd(this.context),this._every=Kd(this.context),this._fill=Gd(this.context),this._first=Yd(this.context),this._get=Xd(this.context),this._includes=Zd(this.context),this._indexof=Qd(this.context),this._insert=Jd(this.context),this._join=of(this.context),this._last=lf(this.context),this._lastindexof=cf(this.context),this._max=uf(this.context),this._median=hf(this.context),this._min=pf(this.context),this._mode=df(this.context),this._percentile_linear_interpolation=mf(this.context),this._percentile_nearest_rank=yf(this.context),this._percentrank=gf(this.context),this._pop=_f(this.context),this._push=xf(this.context),this._range=bf(this.context),this._remove=vf(this.context),this._reverse=wf(this.context),this._set=Sf(this.context),this._shift=Ef(this.context),this._size=Nf(this.context),this._slice=If(this.context),this._some=kf(this.context),this._sort=Af(this.context),this._sort_indices=Mf(this.context),this._standardize=Tf(this.context),this._stdev=Pf(this.context),this._sum=Df(this.context),this._unshift=Of(this.context),this._variance=Rf(this.context)}get length(){return this.array.length}toString(){return"["+af(this).join(", ")+"]"}[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 Vf(t){return(...e)=>{let n=Bd(e);return new Y([...e],n===H.int?H.float:n,t)}}function Bf(t){return(e,n)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;if(n===void 0){let i=r?Array(r).fill(NaN):[];return new Y(i,H.any,t)}return new Y(Array(r).fill(t.precision(n||0)),an(n||0),t)}}function $f(t){return(e=0,n)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0,i=n===void 0?t.pineVersion>=6?!1:NaN:n;return new Y(Array(r).fill(i),H.bool,t)}}function jf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.box,t)}}function Wf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.color,t)}}function Uf(t){return(e=0,n=NaN)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(t.precision(n)),H.float,t)}}function qf(t){return(e=0,n=NaN)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(t.precision(n)),H.int,t)}}function zf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.label,t)}}function Hf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.line,t)}}function Kf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.linefill,t)}}function Gf(t){return(e=0,n="")=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.string,t)}}function Yf(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new Y(Array(r).fill(n),H.table,t)}}function Xf(t){return(e,n=0)=>y.from(e).get(n)}function Zf(t){return(...e)=>new Y([...e],H.int,t)}var aa=class{constructor(e){this.context=e,this.abs=(n,...r)=>n.abs(...r),this.avg=(n,...r)=>n.avg(...r),this.binary_search=(n,...r)=>n.binary_search(...r),this.binary_search_leftmost=(n,...r)=>n.binary_search_leftmost(...r),this.binary_search_rightmost=(n,...r)=>n.binary_search_rightmost(...r),this.clear=(n,...r)=>n.clear(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.covariance=(n,...r)=>n.covariance(...r),this.every=(n,...r)=>n.every(...r),this.fill=(n,...r)=>n.fill(...r),this.first=(n,...r)=>n.first(...r),this.from=Vf(e),this.get=(n,...r)=>n.get(...r),this.includes=(n,...r)=>n.includes(...r),this.indexof=(n,...r)=>n.indexof(...r),this.insert=(n,...r)=>n.insert(...r),this.join=(n,...r)=>n.join(...r),this.last=(n,...r)=>n.last(...r),this.lastindexof=(n,...r)=>n.lastindexof(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.new=Bf(e),this.new_bool=$f(e),this.new_box=jf(e),this.new_color=Wf(e),this.new_float=Uf(e),this.new_int=qf(e),this.new_label=zf(e),this.new_line=Hf(e),this.new_linefill=Kf(e),this.new_string=Gf(e),this.new_table=Yf(e),this.param=Xf(),this.percentile_linear_interpolation=(n,...r)=>n.percentile_linear_interpolation(...r),this.percentile_nearest_rank=(n,...r)=>n.percentile_nearest_rank(...r),this.percentrank=(n,...r)=>n.percentrank(...r),this.pop=(n,...r)=>n.pop(...r),this.push=(n,...r)=>n.push(...r),this.range=(n,...r)=>n.range(...r),this.remove=(n,...r)=>n.remove(...r),this.reverse=(n,...r)=>n.reverse(...r),this.set=(n,...r)=>n.set(...r),this.shift=(n,...r)=>n.shift(...r),this.size=(n,...r)=>n.size(...r),this.slice=(n,...r)=>n.slice(...r),this.some=(n,...r)=>n.some(...r),this.sort=(n,...r)=>n.sort(...r),this.sort_indices=(n,...r)=>n.sort_indices(...r),this.standardize=(n,...r)=>n.standardize(...r),this.stdev=(n,...r)=>n.stdev(...r),this.sum=(n,...r)=>n.sum(...r),this.unshift=(n,...r)=>n.unshift(...r),this.variance=(n,...r)=>n.variance(...r),this.__from_int=Zf(e)}};function Qf(t){return e=>{e.map.clear()}}function ui(t,e){if(t.has(e))return e;let n=Li(e);if(n===null)return e;for(let r of t.keys())if(Li(r)===n)return r;return e}function Jf(t){return(e,n)=>e.map.has(ui(e.map,n))}function em(t){return e=>{let n=new ti(t);return n.map=new Map(e.map),n.valueType=e.valueType,n}}function tm(t){return(e,n)=>{let r=e.map.get(ui(e.map,n));return r===void 0?e.valueType==="string"?"":NaN:r}}function nm(t){return e=>{let n=Array.from(e.map.keys()),r=an(n[0]);return new Y(n,r,t)}}function rm(t){return(e,n,r)=>{let i=ui(e.map,n),s=e.map.get(i);return e.map.set(i,r),s===void 0?NaN:s}}function im(t){return(e,n)=>{for(let[r,i]of n.map)e.map.set(ui(e.map,r),i)}}function sm(t){return(e,n)=>{let r=ui(e.map,n),i=e.map.get(r);return e.map.delete(r)?i:NaN}}function am(t){return e=>e.map.size}function om(t){return e=>{let n=Array.from(e.map.values()),r=an(n[0]);return new Y(n,r,t)}}var lm=Object.defineProperty,cm=(t,e,n)=>e in t?lm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Et=(t,e,n)=>cm(t,typeof e!="symbol"?e+"":e,n),ti=class{constructor(e){this.context=e,Et(this,"map"),Et(this,"valueType"),Et(this,"_clear"),Et(this,"_contains"),Et(this,"_copy"),Et(this,"_get"),Et(this,"_keys"),Et(this,"_put"),Et(this,"_put_all"),Et(this,"_remove"),Et(this,"_size"),Et(this,"_values"),this.map=new Map,this._clear=Qf(this.context),this._contains=Jf(this.context),this._copy=em(this.context),this._get=tm(this.context),this._keys=nm(this.context),this._put=rm(this.context),this._put_all=im(this.context),this._remove=sm(this.context),this._size=am(this.context),this._values=om(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 um(t){return e=>{let n=new ti(t);return e==="string"&&(n.valueType=e),n}}function hm(t){return(e,n=0)=>y.from(e).get(n)}var oa=class{constructor(e){this.context=e,this.clear=(n,...r)=>n.clear(...r),this.contains=(n,...r)=>n.contains(...r),this.copy=(n,...r)=>n.copy(...r),this.get=(n,...r)=>n.get(...r),this.keys=(n,...r)=>n.keys(...r),this.new=um(e),this.param=hm(),this.put=(n,...r)=>n.put(...r),this.put_all=(n,...r)=>n.put_all(...r),this.remove=(n,...r)=>n.remove(...r),this.size=(n,...r)=>n.size(...r),this.values=(n,...r)=>n.values(...r)}};function pm(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r&&(r instanceof Y?s=r.array:Array.isArray(r)?s=r:s=[r]),i===0){for(let l=0;l<s.length;l++){let c=s[l];c instanceof y&&(c=c.get(0)),e.matrix.push([c])}return}let a=e.matrix[0].length,o=n!==void 0?n:a;for(let l=0;l<i;l++){let c=l<s.length?s[l]:NaN;c instanceof y&&(c=c.get(0)),e.matrix[l].splice(o,0,c)}}}function dm(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r)if(r instanceof Y)s=r.array;else if(Array.isArray(r))s=r;else if(r instanceof y){let c=r.get(0);Array.isArray(c)?s=c:s=[c]}else s=[r];let a=i>0?e.matrix[0].length:s.length,o=n!==void 0?n:i,l=[];for(let c=0;c<a;c++)if(c<s.length){let u=s[c];u instanceof y&&(u=u.get(0)),l.push(u)}else l.push(NaN);e.matrix.splice(o,0,l)}}function fm(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length;if(r===0)return NaN;let i=0,s=0;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(i+=l,s++)}return s===0?NaN:i/s}}function mm(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n<0||n>=i)throw new ye(`Column index ${n} is out of bounds, matrix has ${i} columns.`,"matrix.col");let s=[];for(let o=0;o<r;o++)s.push(e.matrix[o][n]);let a=an(s[0]);return new Y(s,a,t)}}function ym(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function gm(t){return(e,n)=>{let r=e.matrix.length,i=n.matrix.length;if(r===0){for(let o=0;o<i;o++)e.matrix.push([...n.matrix[o]]);return}let s=e.matrix[0].length,a=i>0?n.matrix[0].length:0;if(s!==a&&i>0){console.error(`matrix.concat: Column count mismatch ${s} vs ${a}`);return}for(let o=0;o<i;o++)e.matrix.push([...n.matrix[o]])}}function _m(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0,i=new le(n,r,NaN,t);return i.matrix=e.matrix.map(s=>[...s]),i}}function xm(t){let e=t.length;if(e===0)return 0;if(e===1)return t[0][0];if(e===2)return t[0][0]*t[1][1]-t[0][1]*t[1][0];let n=t.map(i=>[...i]),r=1;for(let i=0;i<e;i++){let s=i;for(;s<e&&n[s][i]===0;)s++;if(s===e)return 0;s!==i&&([n[i],n[s]]=[n[s],n[i]],r*=-1),r*=n[i][i];for(let a=i+1;a<e;a++){let o=n[a][i]/n[i][i];for(let l=i;l<e;l++)n[a][l]-=o*n[i][l]}}return r}function bm(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;return n!==r?NaN:xm(e.matrix)}}function vm(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new le(0,0,NaN,t);let i=e.matrix[0].length,s=new le(r,i,NaN,t);if(n instanceof le)for(let a=0;a<r;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=l-c}else{let a=n;for(let o=0;o<r;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]-a}return s}}function wm(t){let e=t.length;if(e!==2)return Array(e).fill(NaN);let n=t[0][0],r=t[0][1],i=t[1][0],s=t[1][1],a=n+s,o=n*s-r*i,l=a*a-4*o;if(l<0)return[NaN,NaN];let c=(a+Math.sqrt(l))/2,u=(a-Math.sqrt(l))/2;return[c,u]}function Sm(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r){let a=an(e.matrix[0][0]);return new Y([],a,t)}let i=wm(e.matrix),s=an(i[0]);return new Y(i,s,t)}}function Em(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new le(0,0,NaN,t);let i=new le(n,r,0,t);for(let s=0;s<n;s++)i.matrix[s][s]=1;return i}}function Nm(t){return e=>{let n=e.matrix.length;return n===0?0:n*e.matrix[0].length}}function Cm(t){return(e,n,r,i,s,a)=>{let o=e.matrix.length;if(o===0)return;let l=e.matrix[0].length,c=r!==void 0?r:0,u=i!==void 0?i:o,p=s!==void 0?s:0,h=a!==void 0?a:l;for(let d=c;d<u&&!(d>=o);d++)for(let f=p;f<h&&!(f>=l);f++)e.matrix[d][f]=n}}function Im(t){return(e,n,r)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0;if(n<0||n>=i)throw new ye(`Row index ${n} is out of bounds, matrix has ${i} rows.`,"matrix.get");if(r<0||r>=s)throw new ye(`Column index ${r} is out of bounds, matrix has ${s} columns.`,"matrix.get");let a=e.matrix[n][r];return a===void 0?NaN:a}}function Ai(t){let e=t.length;if(e===0)return[];let n=new Array(e);for(let i=0;i<e;i++){n[i]=new Array(2*e);for(let s=0;s<e;s++)n[i][s]=t[i][s];for(let s=0;s<e;s++)n[i][e+s]=i===s?1:0}for(let i=0;i<e;i++){let s=Math.abs(n[i][i]),a=i;for(let l=i+1;l<e;l++){let c=Math.abs(n[l][i]);c>s&&(s=c,a=l)}if(s<1e-14)return t.map(l=>l.map(()=>NaN));if(a!==i){let l=n[i];n[i]=n[a],n[a]=l}let o=n[i][i];for(let l=i;l<2*e;l++)n[i][l]/=o;for(let l=0;l<e;l++){if(l===i)continue;let c=n[l][i];if(c!==0)for(let u=i;u<2*e;u++)n[l][u]-=c*n[i][u]}}let r=new Array(e);for(let i=0;i<e;i++){r[i]=new Array(e);for(let s=0;s<e;s++)r[i][s]=n[i][e+s]}return r}function km(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new le(n,r,NaN,t);let i=Ai(e.matrix),s=new le(n,r,NaN,t);return s.matrix=i,s}}function Am(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i+s!==n-1&&e.matrix[i][s]!==0)return!1;return!0}}function Mm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(e.matrix[s][i]!==-e.matrix[i][s])return!1;return!0}}function Tm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++){let a=e.matrix[i][s];if(a!==0&&a!==1)return!1}return!0}}function Pm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i!==s&&e.matrix[i][s]!==0)return!1;return!0}}function Dm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(i===s){if(e.matrix[i][s]!==1)return!1}else if(e.matrix[i][s]!==0)return!1;return!0}}function Om(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;return n===r}}function Rm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;for(let i=0;i<n;i++){let s=0;for(let a=0;a<r;a++){let o=e.matrix[i][a];if(o<0)return!1;s+=o}if(Math.abs(s-1)>1e-10)return!1}return!0}}function Lm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;for(let i=0;i<n;i++)for(let s=0;s<i;s++)if(e.matrix[i][s]!==e.matrix[s][i])return!1;return!0}}function Fm(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;if(n!==r)return!1;let i=!0,s=!0;for(let a=0;a<n;a++)for(let o=0;o<r;o++)a>o&&e.matrix[a][o]!==0&&(i=!1),a<o&&e.matrix[a][o]!==0&&(s=!1);return i||s}}function Vm(t){return e=>{let n=e.matrix.length;if(n===0)return!0;let r=e.matrix[0].length;for(let i=0;i<n;i++)for(let s=0;s<r;s++)if(e.matrix[i][s]!==0)return!1;return!0}}function Bm(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0,s=n.matrix.length,a=s>0?n.matrix[0].length:0,o=r*s,l=i*a,c=new le(o,l,NaN,t);for(let u=0;u<r;u++)for(let p=0;p<i;p++){let h=e.matrix[u][p];for(let d=0;d<s;d++)for(let f=0;f<a;f++){let m=n.matrix[d][f];c.matrix[u*s+d][p*a+f]=h*m}}return c}}function $m(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=-1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(l>i&&(i=l),s=!0)}return s?i:NaN}}function jm(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=[];for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||i.push(l)}if(i.length===0)return NaN;i.sort((a,o)=>a-o);let s=Math.floor(i.length/2);return i.length%2!==0?i[s]:(i[s-1]+i[s])/2}}function Wm(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=1/0,s=!1;for(let a=0;a<n;a++)for(let o=0;o<r;o++){let l=e.matrix[a][o];isNaN(l)||(l<i&&(i=l),s=!0)}return s?i:NaN}}function Um(t){return e=>{let n=e.matrix.length;if(n===0)return NaN;let r=e.matrix[0].length,i=new Map,s=0,a=NaN;for(let o=0;o<n;o++)for(let l=0;l<r;l++){let c=e.matrix[o][l];if(!isNaN(c)){let u=(i.get(c)||0)+1;i.set(c,u),u>s?(s=u,a=c):u===s&&c<a&&(a=c)}}return a}}function qm(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n instanceof le){let s=n.matrix.length,a=s>0?n.matrix[0].length:0;if(i!==s)return new le(0,0,NaN,t);let o=new le(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<i;p++)u+=e.matrix[l][p]*n.matrix[p][c];o.matrix[l][c]=u}return o}else if(n instanceof Y||Array.isArray(n.array||n)){let s=n.array||n;if(i!==s.length)return new Y([],"float",t);let a=[];for(let o=0;o<r;o++){let l=0;for(let c=0;c<i;c++)l+=e.matrix[o][c]*s[c];a.push(l)}return new Y(a,"float",t)}else{let s=n,a=new le(r,i,NaN,t);for(let o=0;o<r;o++)for(let l=0;l<i;l++)a.matrix[o][l]=e.matrix[o][l]*s;return a}}}function zm(t){return e=>{let n=e.matrix.length;if(n===0)return new le(0,0,NaN,t);let r=e.matrix[0].length;if(n===r){let u=Ai(e.matrix),p=new le(n,r,NaN,t);return p.matrix=u,p}let i=u=>{let p=u.length,h=u[0].length,d=new Array(h);for(let f=0;f<h;f++){d[f]=new Array(p);for(let m=0;m<p;m++)d[f][m]=u[m][f]}return d},s=(u,p)=>{let h=u.length,d=u[0].length,f=p[0].length,m=new Array(h);for(let _=0;_<h;_++){m[_]=new Array(f).fill(0);for(let x=0;x<d;x++){let w=u[_][x];if(w!==0)for(let S=0;S<f;S++)m[_][S]+=w*p[x][S]}}return m},a=e.matrix,o=i(a),l;if(n>r){let u=s(o,a),p=Ai(u);l=s(p,o)}else{let u=s(a,o),p=Ai(u);l=s(o,p)}let c=new le(r,n,NaN,t);return c.matrix=l,c}}function Hm(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(r!==i)return new le(0,0,NaN,t);let s=new le(r,i,0,t);for(let l=0;l<r;l++)s.matrix[l][l]=1;let a=new le(r,i,NaN,t);for(let l=0;l<r;l++)a.matrix[l]=[...e.matrix[l]];let o=Math.floor(n);if(o<0)return new le(r,i,NaN,t);for(;o>0;){if(o%2===1){let c=new le(r,i,0,t);for(let u=0;u<r;u++)for(let p=0;p<i;p++){let h=0;for(let d=0;d<r;d++)h+=s.matrix[u][d]*a.matrix[d][p];c.matrix[u][p]=h}s=c}let l=new le(r,i,0,t);for(let c=0;c<r;c++)for(let u=0;u<i;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 Km(t){return e=>{let n=e.matrix.length;if(n===0)return 0;let r=e.matrix[0].length,i=e.matrix.map(a=>[...a]),s=0;for(let a=0;a<r&&s<n;a++){let o=s;for(;o<n&&Math.abs(i[o][a])<1e-10;)o++;if(o<n){[i[s],i[o]]=[i[o],i[s]];let l=i[s][a];for(let c=a;c<r;c++)i[s][c]/=l;for(let c=0;c<n;c++)if(c!==s){let u=i[c][a];for(let p=a;p<r;p++)i[c][p]-=u*i[s][p]}s++}}return s}}function Gm(t){return(e,n)=>{let r=e.matrix.length;if(r===0){let a=an(e.matrix[0][0]);return new Y([],a,t)}let i=[];for(let a=0;a<r;a++){let o=e.matrix[a].splice(n,1);i.push(o[0])}let s=an(i[0]);return new Y(i,s,t)}}function Ym(t){return(e,n)=>{let r=e.matrix.splice(n,1),i=an(r[0][0]);return new Y(r[0]||[],i,t)}}function Xm(t){return(e,n,r)=>{let i=e.matrix.length,s=i>0?e.matrix[0].length:0,a=n*r,o=[];for(let u=0;u<i;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);let l=[],c=0;for(let u=0;u<n;u++){let p=[];for(let h=0;h<r;h++)p.push(o[c++]);l.push(p)}e.matrix=l}}function Zm(t){return e=>{e.matrix.reverse();for(let n of e.matrix)n.reverse()}}function Qm(t){return(e,n)=>{let r=e.matrix.length;if(n<0||n>=r)throw new ye(`Row index ${n} is out of bounds, matrix has ${r} rows.`,"matrix.row");let i=an(e.matrix[n][0]);return new Y([...e.matrix[n]],i,t)}}function Jm(t){return e=>e.matrix.length}function ey(t){return(e,n,r,i)=>{let s=e.matrix.length,a=s>0?e.matrix[0].length:0;if(n<0||n>=s)throw new ye(`Row index ${n} is out of bounds, matrix has ${s} rows.`,"matrix.set");if(r<0||r>=a)throw new ye(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.set");e.matrix[n][r]=i}}function ty(t){return(e,n=0,r="asc")=>{e.matrix.length!==0&&e.matrix.sort((i,s)=>{let a=i[n],o=s[n];return a<o?r==="asc"?-1:1:a>o?r==="asc"?1:-1:0})}}function ny(t){return(e,n,r,i,s)=>{let a=r-n,o=s-i,l=new le(a,o,NaN,t);for(let c=0;c<a;c++){let u=n+c;if(u>=e.matrix.length)break;for(let p=0;p<o;p++){let h=i+p;if(h>=e.matrix[u].length)break;l.matrix[c][p]=e.matrix[u][h]}}return l}}function ry(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new le(0,0,NaN,t);let i=e.matrix[0].length,s=new le(r,i,NaN,t);if(n instanceof le)for(let a=0;a<r;a++)for(let o=0;o<i;o++){let l=e.matrix[a][o],c=n.matrix[a]&&n.matrix[a][o]!==void 0?n.matrix[a][o]:NaN;s.matrix[a][o]=l+c}else{let a=n;for(let o=0;o<r;o++)for(let l=0;l<i;l++)s.matrix[o][l]=e.matrix[o][l]+a}return s}}function iy(t){return(e,n,r)=>{let i=e.matrix.length;for(let s=0;s<i;s++){let a=e.matrix[s][n];e.matrix[s][n]=e.matrix[s][r],e.matrix[s][r]=a}}}function sy(t){return(e,n,r)=>{let i=e.matrix[n];e.matrix[n]=e.matrix[r],e.matrix[r]=i}}function ay(t){return e=>{let n=e.matrix.length;if(n===0)return 0;let r=e.matrix[0].length,i=Math.min(n,r),s=0;for(let a=0;a<i;a++)s+=e.matrix[a][a];return s}}function oy(t){return e=>{let n=e.matrix.length;if(n===0)return new le(0,0,NaN,t);let r=e.matrix[0].length,i=new le(r,n,NaN,t);for(let s=0;s<n;s++)for(let a=0;a<r;a++)i.matrix[a][s]=e.matrix[s][a];return i}}var ly=Object.defineProperty,cy=(t,e,n)=>e in t?ly(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,X=(t,e,n)=>cy(t,typeof e!="symbol"?e+"":e,n),le=class{constructor(e=0,n=0,r=NaN,i){if(this.context=i,X(this,"matrix"),X(this,"_add_col"),X(this,"_add_row"),X(this,"_avg"),X(this,"_col"),X(this,"_columns"),X(this,"_concat"),X(this,"_copy"),X(this,"_det"),X(this,"_diff"),X(this,"_eigenvalues"),X(this,"_eigenvectors"),X(this,"_elements_count"),X(this,"_fill"),X(this,"_get"),X(this,"_inv"),X(this,"_is_antidiagonal"),X(this,"_is_antisymmetric"),X(this,"_is_binary"),X(this,"_is_diagonal"),X(this,"_is_identity"),X(this,"_is_square"),X(this,"_is_stochastic"),X(this,"_is_symmetric"),X(this,"_is_triangular"),X(this,"_is_zero"),X(this,"_kron"),X(this,"_max"),X(this,"_median"),X(this,"_min"),X(this,"_mode"),X(this,"_mult"),X(this,"_pinv"),X(this,"_pow"),X(this,"_rank"),X(this,"_remove_col"),X(this,"_remove_row"),X(this,"_reshape"),X(this,"_reverse"),X(this,"_row"),X(this,"_rows"),X(this,"_set"),X(this,"_sort"),X(this,"_submatrix"),X(this,"_sum"),X(this,"_swap_columns"),X(this,"_swap_rows"),X(this,"_trace"),X(this,"_transpose"),this.matrix=[],e>0&&n>0)for(let s=0;s<e;s++)this.matrix.push(Array(n).fill(r));this._add_col=pm(this.context),this._add_row=dm(this.context),this._avg=fm(this.context),this._col=mm(this.context),this._columns=ym(this.context),this._concat=gm(this.context),this._copy=_m(this.context),this._det=bm(this.context),this._diff=vm(this.context),this._eigenvalues=Sm(this.context),this._eigenvectors=Em(this.context),this._elements_count=Nm(this.context),this._fill=Cm(this.context),this._get=Im(this.context),this._inv=km(this.context),this._is_antidiagonal=Am(this.context),this._is_antisymmetric=Mm(this.context),this._is_binary=Tm(this.context),this._is_diagonal=Pm(this.context),this._is_identity=Dm(this.context),this._is_square=Om(this.context),this._is_stochastic=Rm(this.context),this._is_symmetric=Lm(this.context),this._is_triangular=Fm(this.context),this._is_zero=Vm(this.context),this._kron=Bm(this.context),this._max=$m(this.context),this._median=jm(this.context),this._min=Wm(this.context),this._mode=Um(this.context),this._mult=qm(this.context),this._pinv=zm(this.context),this._pow=Hm(this.context),this._rank=Km(this.context),this._remove_col=Gm(this.context),this._remove_row=Ym(this.context),this._reshape=Xm(this.context),this._reverse=Zm(this.context),this._row=Qm(this.context),this._rows=Jm(this.context),this._set=ey(this.context),this._sort=ty(this.context),this._submatrix=ny(this.context),this._sum=ry(this.context),this._swap_columns=iy(this.context),this._swap_rows=sy(this.context),this._trace=ay(this.context),this._transpose=oy(this.context)}toString(){let e="";for(let n=0;n<this.matrix.length;n++)e+=e===""?"":`\n`,e+="["+this.matrix[n].join(", ")+"]";return e}add_col(...e){return this._add_col(this,...e)}add_row(...e){return this._add_row(this,...e)}avg(...e){return this._avg(this,...e)}col(...e){return this._col(this,...e)}columns(...e){return this._columns(this,...e)}concat(...e){return this._concat(this,...e)}copy(...e){return this._copy(this,...e)}det(...e){return this._det(this,...e)}diff(...e){return this._diff(this,...e)}eigenvalues(...e){return this._eigenvalues(this,...e)}eigenvectors(...e){return this._eigenvectors(this,...e)}elements_count(...e){return this._elements_count(this,...e)}fill(...e){return this._fill(this,...e)}get(...e){return this._get(this,...e)}inv(...e){return this._inv(this,...e)}is_antidiagonal(...e){return this._is_antidiagonal(this,...e)}is_antisymmetric(...e){return this._is_antisymmetric(this,...e)}is_binary(...e){return this._is_binary(this,...e)}is_diagonal(...e){return this._is_diagonal(this,...e)}is_identity(...e){return this._is_identity(this,...e)}is_square(...e){return this._is_square(this,...e)}is_stochastic(...e){return this._is_stochastic(this,...e)}is_symmetric(...e){return this._is_symmetric(this,...e)}is_triangular(...e){return this._is_triangular(this,...e)}is_zero(...e){return this._is_zero(this,...e)}kron(...e){return this._kron(this,...e)}max(...e){return this._max(this,...e)}median(...e){return this._median(this,...e)}min(...e){return this._min(this,...e)}mode(...e){return this._mode(this,...e)}mult(...e){return this._mult(this,...e)}pinv(...e){return this._pinv(this,...e)}pow(...e){return this._pow(this,...e)}rank(...e){return this._rank(this,...e)}remove_col(...e){return this._remove_col(this,...e)}remove_row(...e){return this._remove_row(this,...e)}reshape(...e){return this._reshape(this,...e)}reverse(...e){return this._reverse(this,...e)}row(...e){return this._row(this,...e)}rows(...e){return this._rows(this,...e)}set(...e){return this._set(this,...e)}sort(...e){return this._sort(this,...e)}submatrix(...e){return this._submatrix(this,...e)}sum(...e){return this._sum(this,...e)}swap_columns(...e){return this._swap_columns(this,...e)}swap_rows(...e){return this._swap_rows(this,...e)}trace(...e){return this._trace(this,...e)}transpose(...e){return this._transpose(this,...e)}};function Lt(t){return(e,n,r)=>new le(e,n,r,t)}function uy(t){return(e,n=0)=>y.from(e).get(n)}var la=class{constructor(e){this.context=e,this.add_col=(n,...r)=>n.add_col(...r),this.add_row=(n,...r)=>n.add_row(...r),this.avg=(n,...r)=>n.avg(...r),this.col=(n,...r)=>n.col(...r),this.columns=(n,...r)=>n.columns(...r),this.concat=(n,...r)=>n.concat(...r),this.copy=(n,...r)=>n.copy(...r),this.det=(n,...r)=>n.det(...r),this.diff=(n,...r)=>n.diff(...r),this.eigenvalues=(n,...r)=>n.eigenvalues(...r),this.eigenvectors=(n,...r)=>n.eigenvectors(...r),this.elements_count=(n,...r)=>n.elements_count(...r),this.fill=(n,...r)=>n.fill(...r),this.get=(n,...r)=>n.get(...r),this.inv=(n,...r)=>n.inv(...r),this.is_antidiagonal=(n,...r)=>n.is_antidiagonal(...r),this.is_antisymmetric=(n,...r)=>n.is_antisymmetric(...r),this.is_binary=(n,...r)=>n.is_binary(...r),this.is_diagonal=(n,...r)=>n.is_diagonal(...r),this.is_identity=(n,...r)=>n.is_identity(...r),this.is_square=(n,...r)=>n.is_square(...r),this.is_stochastic=(n,...r)=>n.is_stochastic(...r),this.is_symmetric=(n,...r)=>n.is_symmetric(...r),this.is_triangular=(n,...r)=>n.is_triangular(...r),this.is_zero=(n,...r)=>n.is_zero(...r),this.kron=(n,...r)=>n.kron(...r),this.max=(n,...r)=>n.max(...r),this.median=(n,...r)=>n.median(...r),this.min=(n,...r)=>n.min(...r),this.mode=(n,...r)=>n.mode(...r),this.mult=(n,...r)=>n.mult(...r),this.new=Lt(e),this.param=uy(),this.pinv=(n,...r)=>n.pinv(...r),this.pow=(n,...r)=>n.pow(...r),this.rank=(n,...r)=>n.rank(...r),this.remove_col=(n,...r)=>n.remove_col(...r),this.remove_row=(n,...r)=>n.remove_row(...r),this.reshape=(n,...r)=>n.reshape(...r),this.reverse=(n,...r)=>n.reverse(...r),this.row=(n,...r)=>n.row(...r),this.rows=(n,...r)=>n.rows(...r),this.set=(n,...r)=>n.set(...r),this.sort=(n,...r)=>n.sort(...r),this.submatrix=(n,...r)=>n.submatrix(...r),this.sum=(n,...r)=>n.sum(...r),this.swap_columns=(n,...r)=>n.swap_columns(...r),this.swap_rows=(n,...r)=>n.swap_rows(...r),this.trace=(n,...r)=>n.trace(...r),this.transpose=(n,...r)=>n.transpose(...r),this.new_float=Lt(e),this.new_int=Lt(e),this.new_string=Lt(e),this.new_bool=Lt(e),this.new_color=Lt(e),this.new_line=Lt(e),this.new_label=Lt(e),this.new_box=Lt(e),this.new_linefill=Lt(e),this.new_table=Lt(e)}},hy=Object.defineProperty,py=(t,e,n)=>e in t?hy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dy=(t,e,n)=>py(t,typeof e!="symbol"?e+"":e,n),ca=class{constructor(e){this.context=e,dy(this,"_live",!1)}setLive(){this._live=!0}get isnew(){return!this._live}get islast(){return this.context.idx===this.context.length-1}get isfirst(){return this.context.idx===0}get ishistory(){return this.context.idx<this.context.length-1}get isrealtime(){return this.context.idx===this.context.length-1}get isconfirmed(){return this.context.data.closeTime.data[this.context.idx]<=Date.now()}get islastconfirmedhistory(){let e=this.context.idx,n=this.context.length;if(e===n-1)return this.context.data.closeTime.data[e]<=Date.now();if(e===n-2){let r=this.context.marketData?.[n-1]?.closeTime;return r!==void 0?r>Date.now():!1}return!1}},fy=Object.defineProperty,my=(t,e,n)=>e in t?fy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Bs=(t,e,n)=>my(t,typeof e!="symbol"?e+"":e,n),Ye=class t{constructor(e,n,r){Bs(this,"time"),Bs(this,"index"),Bs(this,"price"),this.time=e,this.index=n,this.price=r}copy(){return new t(this.time,this.index,this.price)}toString(){return JSON.stringify({time:this.time,index:this.index,price:this.price})}};function yy(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}function ua(t){return t!==null&&typeof t=="object"&&"__value"in t&&(t.__value===null||typeof t.__value!="object")}var ql={series:t=>t instanceof y||typeof t=="number"||typeof t=="string"||typeof t=="boolean"||ua(t),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 Ye,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 Ye)&&!yy(t)&&!ua(t)};function jt(t){let e=t[t.length-1];if(e&&typeof e=="object"&&"__callsiteId"in e)return t.pop().__callsiteId}function ge(t,e,n,r){Array.isArray(e)&&typeof e[0]=="string"&&(e=[e]);let i={},s={},a=new Array(e.length).fill(!0);for(let o=0;o<t.length;o++){let l=t[o];if(ql.remaining_options(l)){s=l;break}let c=e.map((u,p)=>a[p]?u[o]:void 0);for(let u=0;u<c.length;u++){let p=c[u];if(p===void 0){a[u]=!1;continue}let h=n[p];if(typeof l=="number"&&isNaN(l)&&(h==="number"||h==="series"))i[p]=l;else{let d=ql[n[p]];typeof d=="function"&&d(l)?i[p]=l:a[u]=!1}}}return{...i,...s,...r}}var gy=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/;function _y(t){if(typeof t!="string")return null;let e=t.trim();if(!e)return null;if(e==="24x7")return{windows:[{start:0,end:1440}],days:new Set([1,2,3,4,5,6,7])};let n=e.split(":");if(n.length>2)return null;let r=new Set;if(n.length===2){if(!/^[1-7]+$/.test(n[1]))return null;for(let s of n[1])r.add(parseInt(s,10))}else for(let s=1;s<=7;s++)r.add(s);let i=[];for(let s of n[0].split(",")){let a=s.match(gy);if(!a)return null;let o=parseInt(a[1],10),l=parseInt(a[2],10),c=parseInt(a[3],10),u=parseInt(a[4],10);if(o>23||l>59||c>23||u>59)return null;let p=o*60+l,h=c===0&&u===0?1440:c*60+u;i.push({start:p,end:h})}return{windows:i,days:r}}function xy(t,e,n){let r=n+1,i=r%7+1;for(let{start:s,end:a}of t.windows)if(s<a){if(e>=s&&e<a&&t.days.has(r))return!0}else if(e>=s&&t.days.has(i)||e<a&&t.days.has(r))return!0;return!1}var $s=new Map;function ze(t){if(typeof t=="number"&&(t=String(t)),typeof t!="string")return null;if($s.has(t))return $s.get(t);let e=by(t.trim());return $s.set(t,e),e}function by(t){let e=/^(\\d*)([a-zA-Z]?)$/.exec(t);if(!e||t==="")return null;let n=e[1],r=e[2],i=n===""?1:parseInt(n,10);if(!(i>=1))return null;let s;switch(r){case"":s={unit:"",multiplier:i};break;case"S":case"s":s={unit:"S",multiplier:i};break;case"D":case"d":s={unit:"D",multiplier:i};break;case"W":case"w":s={unit:"W",multiplier:i};break;case"M":s={unit:"M",multiplier:i};break;case"m":s=n===""?{unit:"M",multiplier:1}:{unit:"",multiplier:i};break;case"H":case"h":s={unit:"",multiplier:i*60};break;default:s=null}return s&&s.unit===""&&s.multiplier>1440?null:s}function Sr(t,e=!1){return t.unit===""?String(t.multiplier):t.unit==="S"?`${t.multiplier}S`:t.multiplier===1&&!e?t.unit:`${t.multiplier}${t.unit}`}function ha(t){let e=ze(t);return e?Sr(e):null}function pt(t){switch(t.unit){case"S":return t.multiplier;case"":return t.multiplier*60;case"D":return t.multiplier*86400;case"W":return t.multiplier*604800;case"M":return t.multiplier*2628003}}function vy(t){return t>=365*86400?"12M":t<=30?`${[1,5,10,15,30].find(e=>t<=e)}S`:t<86400?String(Math.ceil(t/60)):t%604800===0?`${t/604800}W`:t%2628003===0?`${t/2628003}M`:`${Math.ceil(t/86400)}D`}function ou(t){let e=Date.UTC(t,0,1),n=new Date(e).getUTCDay();return e+(8-n)%7*864e5}function ni(t,e){let n=e.multiplier,r=new Date(t),i=r.getUTCFullYear();switch(e.unit){case"S":case"":{let s=pt(e)*1e3,a=Math.floor(t/864e5)*864e5;return a+Math.floor((t-a)/s)*s}case"D":{let s=Date.UTC(i,0,1),a=Math.floor((t-s)/864e5);return s+Math.floor(a/n)*n*864e5}case"W":{let s=Math.floor(t/864e5)*864e5-(r.getUTCDay()+6)%7*864e5,a=ou(new Date(s).getUTCFullYear()),o=Math.round((s-a)/6048e5);return a+Math.floor(o/n)*n*6048e5}case"M":return Date.UTC(i,Math.floor(r.getUTCMonth()/n)*n,1)}}function wy(t,e){let n=e.multiplier,r=new Date(t),i=r.getUTCFullYear();switch(e.unit){case"S":case"":{let s=(Math.floor(t/864e5)+1)*864e5;return Math.min(t+pt(e)*1e3,s)}case"D":return Math.min(t+n*864e5,Date.UTC(i+1,0,1));case"W":return Math.min(t+n*6048e5,ou(i+1));case"M":return Math.min(Date.UTC(i,r.getUTCMonth()+n,1),Date.UTC(i+1,0,1))}}var Sy=Object.defineProperty,Ey=(t,e,n)=>e in t?Sy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fr=(t,e,n)=>Ey(t,typeof e!="symbol"?e+"":e,n);function lu(t){let e=r=>r instanceof y?r.get(0):r,n=r=>r!==null&&typeof r=="object"&&Object.getPrototypeOf(r)===Object.prototype;return t.map(r=>n(r)?Object.fromEntries(Object.entries(r).map(([i,s])=>[i,e(s)])):e(r))}function Dn(t,e){let n=e.trim();if(n==="UTC"||n==="GMT"||n==="Etc/UTC"){let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}let r=n.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(r){let i=r[1]==="+"?1:-1,s=parseInt(r[2],10),a=parseInt(r[3]||"0",10),o=i*(s*60+a)*60*1e3,l=new Date(t+o);return{year:l.getUTCFullYear(),month:l.getUTCMonth()+1,day:l.getUTCDate(),hour:l.getUTCHours(),minute:l.getUTCMinutes(),second:l.getUTCSeconds(),dayOfWeek:l.getUTCDay()}}try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",weekday:"short",hour12:!1}).formatToParts(new Date(t)),s=c=>parseInt(i.find(u=>u.type===c)?.value||"0",10),a=s("hour");a===24&&(a=0);let o=i.find(c=>c.type==="weekday")?.value||"Sun",l={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:s("year"),month:s("month"),day:s("day"),hour:a,minute:s("minute"),second:s("second"),dayOfWeek:l[o]??0}}catch{let i=new Date(t);return{year:i.getUTCFullYear(),month:i.getUTCMonth()+1,day:i.getUTCDate(),hour:i.getUTCHours(),minute:i.getUTCMinutes(),second:i.getUTCSeconds(),dayOfWeek:i.getUTCDay()}}}function Ny(t,e,n){let r=new Date(Date.UTC(t,e-1,n)),i=r.getUTCDay()||7;r.setUTCDate(r.getUTCDate()+4-i);let s=new Date(Date.UTC(r.getUTCFullYear(),0,1));return Math.ceil(((r.getTime()-s.getTime())/864e5+1)/7)}var Cy=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Iy={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},Bi=class{constructor(e,n="openTime"){fr(this,"context"),fr(this,"dataField"),this.context=e,this.dataField=n}get __value(){return this.context.data[this.dataField]}param(e,n=0){return y.from(e).get(n)}any(...e){let n=lu(e),r=ge(n,Cy,Iy),i=r.bars_back??0,s=r.timeframe||"",a=this.context.data[this.dataField],o=y.from(a).get(i);if(isNaN(o)||o==null)return NaN;let l;if(!s||ha(s)===ha(this.context.timeframe))l=o;else{let c=ze(s);if(!c)throw new ye(`Cannot parse resolution \'${s}\'. - Invalid format`,"time");l=ni(o,c)}if(r.session!==void 0&&r.session!==""){let c=r.timezone||this.context.pine?.syminfo?.timezone||"UTC";return this._isInSession(l,r.session,c)?l:NaN}return l}_isInSession(e,n,r){let i=_y(n);if(!i)throw new ye(`Invalid session specification: "${n}"`,"time");let s=Dn(e,r),a=s.hour*60+s.minute;return xy(i,a,s.dayOfWeek)}},ky=[[],["time"],["time","timezone"]],Ay={time:"number",timezone:"string"},Zt=class{constructor(e,n){fr(this,"context"),fr(this,"extractor"),fr(this,"_cache",[]),fr(this,"_cacheTimezone",null),this.context=e,this.extractor=n}get __value(){let e=this.context.data.openTime,n=e instanceof y?e.data:Array.isArray(e)?e:[],r=this.context.pine?.syminfo?.timezone||"UTC";r!==this._cacheTimezone&&(this._cache=[],this._cacheTimezone=r);let i=this._cache;i.length>n.length&&(i.length=n.length);for(let s=i.length;s<n.length;s++){let a=n[s];i.push(a==null||isNaN(a)?NaN:this.extractor(Dn(a,r)))}return new y(i,e instanceof y?e.offset:0)}param(e,n=0){return y.from(e).get(n)}any(...e){let n=lu(e);if(n.length===0)return this.__value.get(0);let r=ge(n,ky,Ay),i=r.time;if(i===void 0||isNaN(i))return NaN;let s=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=Dn(i,s);return this.extractor(a)}},En={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=>Ny(t.year,t.month,t.day),year:t=>t.year},My=Object.defineProperty,Ty=(t,e,n)=>e in t?My(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zl=(t,e,n)=>Ty(t,typeof e!="symbol"?e+"":e,n),pa=class{constructor(e){this.context=e,zl(this,"regular","regular"),zl(this,"extended","extended")}get _timezone(){return this.context.pine?.syminfo?.timezone||"UTC"}_dayKey(e){let n=Dn(e,this._timezone);return`${n.year}-${n.month}-${n.day}`}get isfirstbar(){let e=this.context.idx,n=this.context.marketData;return!Array.isArray(n)||!n[e]?!1:e===0?!0:this._dayKey(n[e].openTime)!==this._dayKey(n[e-1].openTime)}get islastbar(){let e=this.context.idx,n=this.context.marketData;return!Array.isArray(n)||!n[e]?!1:e===n.length-1?!0:this._dayKey(n[e].openTime)!==this._dayKey(n[e+1].openTime)}get isfirstbar_regular(){return this.isfirstbar}get islastbar_regular(){return this.islastbar}get ismarket(){return!0}get ispremarket(){return!1}get ispostmarket(){return!1}};function T(t,e,n){let r=n.value;return typeof r!="function"||(n.value=function(...i){return this&&this.context&&this.context.isSecondaryContext?null:r.apply(this,i)}),n}var cu=Object.defineProperty,Py=Object.getOwnPropertyDescriptor,Dy=(t,e,n)=>e in t?cu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,uu=(t,e,n,r)=>{for(var i=r>1?void 0:r?Py(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&cu(e,n,i),i},gr=(t,e,n)=>Dy(t,typeof e!="symbol"?e+"":e,n),Oy=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Ry={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},Ly=["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"],Fy={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 Vy(t){return ge(t,Ly,Fy)}var dt=class t{get __value(){return NaN}param(e,n=0){return y.from(e).get(n)}any(e){if(e instanceof t)return!0;let n=y.from(e).get(0);return n instanceof t||n==null?!0:typeof n=="number"?n!==n:n===""||typeof n=="object"&&n._deleted===!0}},sr={freq_all:"all",freq_once_per_bar:"once_per_bar",freq_once_per_bar_close:"once_per_bar_close"},$i=class{constructor(e){this.context=e,gr(this,"_firedKeys",new Set),gr(this,"_fallbackCounter",0),gr(this,"_fallbackLastExecTick",-1)}get freq_all(){return sr.freq_all}get freq_once_per_bar(){return sr.freq_once_per_bar}get freq_once_per_bar_close(){return sr.freq_once_per_bar_close}param(e,n,r){return y.from(e).get(0)}any(e,n,r){let i=y.from(e).get(0),s=n?y.from(n).get(0):sr.freq_once_per_bar,a=typeof s=="string"&&s.startsWith("alert.freq_")?s.slice(11):s,o;if(r&&typeof r=="object"&&r.__callsiteId)o=r.__callsiteId;else{let p=this.context._execTick||0;p!==this._fallbackLastExecTick&&(this._fallbackCounter=0,this._fallbackLastExecTick=p),o=`alert_${this._fallbackCounter++}`}let l=this.context.idx,c=this.context.pine?.barstate?.isrealtime??l===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!c)return;let u=`${o}:${l}`;if(a===sr.freq_once_per_bar){if(this._firedKeys.has(u))return;this._firedKeys.add(u)}else if(a===sr.freq_once_per_bar_close){if(!(this.context.pine?.barstate?.isconfirmed??!0)||this._firedKeys.has(u))return;this._firedKeys.add(u)}this.context.alerts.push({type:"alert",id:o,message:i,freq:a,bar_index:l,time:this.context.data.openTime?.data?.[l]??0})}};uu([T],$i.prototype,"any",1);var ji=class{constructor(e){this.context=e,gr(this,"_acCounter",0),gr(this,"_acLastExecTick",-1),gr(this,"_acFiredKeys",new Set)}extractPlotOptions(e){let n={};for(let r in e)n[r]=y.from(e[r]).get(0);return n}indicator(...e){let n=e.map(s=>s instanceof y?s.get(0):s),r=Vy(n),i={title:"",shorttitle:"",overlay:!1,format:"inherit",precision:10,scale:"points",max_bars_back:0,timeframe:"",timeframe_gaps:!0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,max_polylines_count:50,dynamic_requests:!1,behind_chart:!0};return this.context.indicator={...i,...r,...this.context._propOverrides??{}},this.context.indicator}get bar_index(){return this.context.idx}na(e){let n=y.from(e).get(0);return n==null||n===""||typeof n=="number"&&isNaN(n)||typeof n=="object"&&n._deleted===!0}nz(e,n=0){let r=y.from(e).get(0),i=y.from(n).get(0);return r==null||typeof r=="number"&&isNaN(r)?i:r}fixnan(e){let n=y.from(e);for(let r=0;r<n.length;r++){let i=n.get(r);if(i!=null&&!(typeof i=="number"&&isNaN(i)))return i}return NaN}alertcondition(e,n,r){let i=y.from(e).get(0),s=this.context.idx,a=this.context._execTick||0;a!==this._acLastExecTick&&(this._acCounter=0,this._acLastExecTick=a);let o=`alertcondition_${this._acCounter++}`;if(!i)return;let l=this.context.pine?.barstate?.isrealtime??s===this.context.length-1;if((this.context._alertMode||"realtime")==="realtime"&&!l)return;let c=`${o}:${s}`;if(this._acFiredKeys.has(c))return;this._acFiredKeys.add(c);let u=n?y.from(n).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,n){}timestamp(...e){let n=e.map(i=>i instanceof y?i.get(0):i),r=ge(n,Oy,Ry);if(r.year!==void 0){let i=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,i,s,a,o,l,c)}if(r.dateString!==void 0){let i=r.dateString.trim();if(/[Zz]$/.test(i)||/[+-]\\d{2}:?\\d{2}$/.test(i))return new Date(i).getTime();let s=i.includes("T")?i+"Z":i.replace(/\\s+/,"T")+"Z",a=new Date(s);if(isNaN(a.getTime())&&(a=new Date(`${i} UTC`)),!isNaN(a.getTime())){let o=this.context.pine?.syminfo?.timezone||"UTC";return this._timestampFromComponents(o,a.getUTCFullYear(),a.getUTCMonth()+1,a.getUTCDate(),a.getUTCHours(),a.getUTCMinutes(),a.getUTCSeconds())}return new Date(i).getTime()}return NaN}_timestampFromComponents(e,n,r,i,s,a,o){let l=new Date(Date.UTC(n,r-1,i,s,a,o));n>=0&&n<100&&l.setUTCFullYear(n);let c=e.trim();if(c==="UTC"||c==="GMT"||c==="Etc/UTC")return l.getTime();let u=c.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(u){let p=u[1]==="+"?1:-1,h=parseInt(u[2],10),d=parseInt(u[3]||"0",10),f=p*(h*60+d)*60*1e3;return l.getTime()-f}try{return this._timestampFromIANA(e,n,r,i,s,a,o)}catch{return l.getTime()}}_timestampFromIANA(e,n,r,i,s,a,o){let l=new Date(Date.UTC(n,r-1,i,s,a,o));n>=0&&n<100&&l.setUTCFullYear(n);let c=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!1}).formatToParts(l),u=S=>parseInt(c.find(v=>v.type===S)?.value||"0",10),p=u("year"),h=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),_=u("second"),x=new Date(Date.UTC(p,h-1,d,f,m,_));p>=0&&p<100&&x.setUTCFullYear(p);let w=x.getTime()-l.getTime();return l.getTime()-w}bool(e){let n=y.from(e).get(0);return!isNaN(n)&&n!==0}int(e){let n=y.from(e).get(0);if(typeof n!="number")throw new Error(`Cannot call "int" with argument "x"="${n}". An argument of "literal string" type was used but a "simple int" is expected.`);return Math.trunc(n)}float(e){let n=y.from(e).get(0);if(typeof n!="number")throw new Error(`Cannot call "float" with argument "x"="${n}". An argument of "literal string" type was used but a "const float" is expected.`);return n}string(e){let n=y.from(e).get(0);return n==null||typeof n=="number"&&isNaN(n)?"":n.toString()}Type(e,n){let r=Object.keys(e),i={},s={},a=this.context?.pineVersion;for(let l of r){let c=e[l];c instanceof y&&(c=c.data),Array.isArray(c)?(i[l]=c[0],s[l]=c[1]):i[l]=c}let o={__name__:n,new:function(...l){let c={},u=null;if(l.length>0){let p=l[l.length-1];if(p&&typeof p=="object"&&!(p instanceof y)&&!Array.isArray(p)&&!(p instanceof Ht)){let h=Object.keys(p);h.length>0&&h.some(d=>r.includes(d))&&(u=p,l=l.slice(0,-1))}}for(let p=0;p<r.length;p++){let h=r[p];if(u&&h in u?c[h]=u[h]:p<l.length?c[h]=l[p]:h in s&&(c[h]=y.from(s[h]).get(0)),/(^|\\s)string$/.test(i[h]??"")){let d=c[h];(d==null||typeof d=="number"&&isNaN(d))&&(c[h]="")}if(a>=6&&/(^|\\s)bool$/.test(i[h]??"")){let d=c[h];(d==null||typeof d=="number"&&isNaN(d))&&(c[h]=!1)}}return new Ht(c,this.context,o)},copy:function(l){return new Ht(l.__def__,this.context,o)},_fieldDefaults:s,_definitionKeys:r};return o}};uu([T],ji.prototype,"alertcondition",1);var ps=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]);function hu(t,e){if(!ps.has(e))return;let n=t?.data?.[e];if(n!=null)return y.from(n).get(0)}var By=[["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"]],$y={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"},jy=t=>!!t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,"__varId")||Object.prototype.hasOwnProperty.call(t,"__inputId"));function mt(t){let e,n;for(;t.length&&jy(t[t.length-1]);){let i=t[t.length-1];i.__inputId!==void 0?e=i.__varId??e:e??(e=i.__varId),n??(n=i.__inputId),t=t.slice(0,-1)}let r=ge(t,By,$y);return e!==void 0&&(r.__varId=e),n!==void 0&&(r.__inputId=n),r}function yt(t,e){return e.__inputId&&t.inputs&&t.inputs[e.__inputId]!==void 0?t.inputs[e.__inputId]: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 Wy(t){return(...e)=>{let n=mt(e),r=yt(t,n);if(typeof r=="string"&&typeof n.defval=="number"){let i=hu(t,r);if(i!==void 0)return i}return r}}function Uy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function qy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function zy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Hy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Ky(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Gy(t){return(e,n=0)=>y.from(e).get(n)}function Yy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Xy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Zy(t){return(...e)=>{let n=mt(e),r=yt(t,n);if(typeof r=="string"){let i=hu(t,r);return i!==void 0?i:n.defval}return r}}function Qy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function Jy(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function eg(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function tg(t){return(...e)=>{let n=mt(e);return yt(t,n)}}function ng(t){return(...e)=>{let n=mt(e);return yt(t,n)}}var rg=Object.defineProperty,ig=(t,e,n)=>e in t?rg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xe=(t,e,n)=>ig(t,typeof e!="symbol"?e+"":e,n),sg={any:Wy,bool:Uy,color:qy,enum:zy,float:Hy,int:Ky,param:Gy,price:Yy,session:Xy,source:Zy,string:Qy,symbol:Jy,text_area:eg,time:tg,timeframe:ng},da=class{constructor(e){this.context=e,Xe(this,"any"),Xe(this,"bool"),Xe(this,"color"),Xe(this,"enum"),Xe(this,"float"),Xe(this,"int"),Xe(this,"param"),Xe(this,"price"),Xe(this,"session"),Xe(this,"source"),Xe(this,"string"),Xe(this,"symbol"),Xe(this,"text_area"),Xe(this,"time"),Xe(this,"timeframe"),Object.entries(sg).forEach(([n,r])=>{this[n]=r(e)})}};function ag(t){return e=>Math.abs(y.from(e).get(0))}function og(t){return e=>Math.acos(y.from(e).get(0))}function lg(t){return e=>Math.asin(y.from(e).get(0))}function cg(t){return e=>Math.atan(y.from(e).get(0))}function ug(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function hg(t){return e=>Math.ceil(y.from(e).get(0))}function pg(t){return e=>Math.cos(y.from(e).get(0))}function dg(t){return()=>Math.E}function fg(t){return e=>Math.exp(y.from(e).get(0))}function mg(t){return e=>Math.floor(y.from(e).get(0))}function yg(t){return e=>Math.log(y.from(e).get(0))}function gg(t){return e=>Math.log(y.from(e).get(0))}function _g(t){return e=>Math.log10(y.from(e).get(0))}function xg(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.max(...n)}}function bg(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.min(...n)}}function vg(t){return(e,n,r)=>typeof e=="string"?e:e instanceof y?n?new y(e.data,e.offset+n):e:!Array.isArray(e)&&typeof e=="object"?e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,n||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],n||0)))}function wg(t){return()=>1.618033988749895}function Sg(t){return()=>Math.PI}function Eg(t){return(e,n)=>Math.pow(y.from(e).get(0),y.from(n).get(0))}var pu=0x5deece66dn,Ng=0xbn,du=(1n<<48n)-1n,Hl=t=>(BigInt(Math.trunc(t))^pu)&du,Kl=t=>t*pu+Ng&du;function Cg(t){let e=Kl(t),n=Kl(e),r=Number(e>>22n),i=Number(n>>21n);return[(r*2**27+i)/2**53,n]}function Ig(t){return(...e)=>{let n=typeof e[e.length-1]=="string"?e.pop():void 0,r=e.length>0?y.from(e[0]).get(0):0,i=e.length>1?y.from(e[1]).get(0):1,s=e.length>2?y.from(e[2]).get(0):NaN,a;if(!s||Number.isNaN(s))a=Math.random();else{t.taState||(t.taState={});let o=n||`random_${s}`;t.taState[o]||(t.taState[o]={bar:t.idx,committed:Hl(s),tentative:Hl(s)});let l=t.taState[o];t.idx!==l.bar&&(l.committed=l.tentative,l.bar=t.idx),[a,l.tentative]=Cg(l.tentative)}return r+(i-r)*a}}var Gl=t=>Number.isNaN(t)?NaN:Math.sign(t)*Math.round(Math.abs(t));function kg(t){return(e,n)=>{let r=y.from(e).get(0),i=n==null?0:y.from(n).get(0);if(!i)return Gl(r);let s=10**i,a=Math.abs(r)*s*s;return!Number.isFinite(a)||a>=Number.MAX_SAFE_INTEGER?Gl(r*s)/s:Math.sign(r)*Math.round(Math.round(a)/s)/s}}function Ag(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Mg(t){return()=>.6180339887498948}function Tg(t){return e=>Math.sign(y.from(e).get(0))}function Pg(t){return e=>Math.sin(y.from(e).get(0))}function Dg(t){return e=>Math.sqrt(y.from(e).get(0))}function Og(t){return(e,n)=>{let r=y.from(n).get(0),i=y.from(e),s=0,a=0;for(let o=0;a<r&&o<=t.idx;o++){let l=i.get(o);l==null||Number.isNaN(l)||(s+=l,a++)}return a<r?NaN:s}}function Rg(t){return e=>Math.tan(y.from(e).get(0))}function Lg(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(180/Math.PI)}}function Fg(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(Math.PI/180)}}function Vg(t){return(e,n)=>e&&n}function Bg(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10:r===i}}function $g(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!0:r>i:r>=i}}function jg(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!1:r>i:r>i}}function Wg(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r!="number"||typeof i!="number"?r/i:isNaN(r)||isNaN(i)?NaN:Math.trunc(r/i)}}function Ug(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!0:r<i:r<=i}}function qg(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)<1e-10?!1:r<i:r<i}}function zg(t){return(e,n)=>{let r=y.from(e).get(0),i=y.from(n).get(0);return typeof r=="number"&&typeof i=="number"?isNaN(r)||isNaN(i)?NaN:Math.abs(r-i)>=1e-10:r!==i}}function Hg(t){return(e,n)=>e||n}var Kg=Object.defineProperty,Gg=(t,e,n)=>e in t?Kg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,te=(t,e,n)=>Gg(t,typeof e!="symbol"?e+"":e,n),Yg={abs:ag,acos:og,asin:lg,atan:cg,avg:ug,ceil:hg,cos:pg,e:dg,exp:fg,floor:mg,ln:yg,log:gg,log10:_g,max:xg,min:bg,param:vg,phi:wg,pi:Sg,pow:Eg,random:Ig,round:kg,round_to_mintick:Ag,rphi:Mg,sign:Tg,sin:Pg,sqrt:Dg,sum:Og,tan:Rg,todegrees:Lg,toradians:Fg,__and:Vg,__eq:Bg,__ge:$g,__gt:jg,__idiv:Wg,__le:Ug,__lt:qg,__neq:zg,__or:Hg},fa=class{constructor(e){this.context=e,te(this,"_cache",{}),te(this,"abs"),te(this,"acos"),te(this,"asin"),te(this,"atan"),te(this,"avg"),te(this,"ceil"),te(this,"cos"),te(this,"e"),te(this,"exp"),te(this,"floor"),te(this,"ln"),te(this,"log"),te(this,"log10"),te(this,"max"),te(this,"min"),te(this,"param"),te(this,"phi"),te(this,"pi"),te(this,"pow"),te(this,"random"),te(this,"round"),te(this,"round_to_mintick"),te(this,"rphi"),te(this,"sign"),te(this,"sin"),te(this,"sqrt"),te(this,"sum"),te(this,"tan"),te(this,"todegrees"),te(this,"toradians"),te(this,"__and"),te(this,"__eq"),te(this,"__ge"),te(this,"__gt"),te(this,"__idiv"),te(this,"__le"),te(this,"__lt"),te(this,"__neq"),te(this,"__or"),Object.entries(Yg).forEach(([n,r])=>{this[n]=r(e)})}};function Xg(t){return t!=null&&!Array.isArray(t)&&typeof t.getFootprintData=="function"}var Zg=Object.defineProperty,Qg=(t,e,n)=>e in t?Zg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nn=(t,e,n)=>Qg(t,typeof e!="symbol"?e+"":e,n),Wi=class{constructor(e){Nn(this,"downPrice"),Nn(this,"upPrice"),Nn(this,"buyVolume"),Nn(this,"sellVolume"),Nn(this,"totalVolume"),Nn(this,"deltaVolume"),Nn(this,"buyImbalance"),Nn(this,"sellImbalance"),this.downPrice=e.downPrice,this.upPrice=e.upPrice,this.buyVolume=e.buyVolume,this.sellVolume=e.sellVolume,this.totalVolume=e.totalVolume,this.deltaVolume=e.delta,this.buyImbalance=e.buyImbalance,this.sellImbalance=e.sellImbalance}up_price(){return this.upPrice}down_price(){return this.downPrice}buy_volume(){return this.buyVolume}sell_volume(){return this.sellVolume}total_volume(){return this.totalVolume}delta(){return this.deltaVolume}has_buy_imbalance(){return this.buyImbalance}has_sell_imbalance(){return this.sellImbalance}};function Lo(t){return t instanceof dt?NaN:t instanceof y?t.get(0):typeof t=="function"?t():t}var Jg=Object.defineProperty,e0=(t,e,n)=>e in t?Jg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ft=(t,e,n)=>e0(t,typeof e!="symbol"?e+"":e,n),$r=1e-10,t0=.01,n0=2e3;function r0(t){return Math.floor(t+1e-6)}function fu(t,e){return Math.floor(t/e)}function Yl(t,e,n){return fu(Math.round(t/e),n)}var Ui=class t{constructor(e,n,r,i,s,a,o){Ft(this,"rowList"),Ft(this,"buyVolume"),Ft(this,"sellVolume"),Ft(this,"totalVolume"),Ft(this,"deltaVolume"),Ft(this,"pocIndex"),Ft(this,"vahIndex"),Ft(this,"valIndex"),Ft(this,"_rowSize"),Ft(this,"_firstRowIndex"),Ft(this,"_context"),this._context=e,this.rowList=n,this._rowSize=r,this._firstRowIndex=i,this.buyVolume=s.buy,this.sellVolume=s.sell,this.totalVolume=s.total,this.deltaVolume=s.delta,this.pocIndex=a,this.valIndex=o.lo,this.vahIndex=o.hi}static build(e,n,r,i){let s=M=>e.precision(M),{ticksPerRow:a,mintick:o}=r,l=a*o,c=new Map,u=new Map,p=1/0,h=-1/0;for(let M of n){if(!M||!Number.isFinite(M.price))continue;let W=Number.isFinite(M.buyVolume)?M.buyVolume:0,k=Number.isFinite(M.sellVolume)?M.sellVolume:0,V=Yl(M.price,o,a);c.set(V,(c.get(V)??0)+W),u.set(V,(u.get(V)??0)+k),V<p&&(p=V),V>h&&(h=V)}if(!Number.isFinite(p))return null;i&&Number.isFinite(i.low)&&Number.isFinite(i.high)&&i.low<=i.high&&(p=Math.min(p,Yl(i.low,o,a)),h=Math.max(h,p,fu(Math.round(i.high/o)-1,a)));let d=h-p+1;if(d>n0)return null;let f=new Array(d),m=new Array(d),_=new Array(d),x=0,w=0;for(let M=0;M<d;M++){let W=c.get(p+M)??0,k=u.get(p+M)??0;f[M]=W,m[M]=k,_[M]=W+k,x+=W,w+=k}let S=_[0];for(let M=1;M<d;M++)_[M]>S&&(S=_[M]);let v=(d-1)/2,E=-1;for(let M=0;M<d;M++)_[M]+$r<S||(E<0||Math.abs(M-v)<Math.abs(E-v)-$r)&&(E=M);let C=x+w,I=Number.isNaN(r.vaPercent)?0:r.vaPercent,F=C>0?C*I/100+t0:0,$=E,j=E,A=_[E];for(;$>0||j<d-1;){let M=j<d-1,W=$>0,k=M?_[j+1]:-1/0,V=W?_[$-1]:-1/0,Q;W?M?Math.abs(k-V)<=$r?Q=j+1-E<=E-($-1):Q=k>V:Q=!1:Q=!0;let De=Q?k:V;if(A+De>F)break;A+=De,Q?j++:$--}let ue=Math.max(r.imbalancePercent/100,1),D=new Array(d);for(let M=0;M<d;M++){let W=f[M],k=m[M],V=M>0&&W>0&&W+$r>=ue*m[M-1],Q=M<d-1&&k>0&&k+$r>=ue*f[M+1],De=s((p+M)*l),Te=s((p+M+1)*l);D[M]=new Wi({downPrice:De,upPrice:Te,buyVolume:s(W),sellVolume:s(k),totalVolume:s(W+k),delta:s(W-k),buyImbalance:V,sellImbalance:Q})}return new t(e,D,l,p,{buy:s(x),sell:s(w),total:s(C),delta:s(x-w)},E,{lo:$,hi:j})}buy_volume(){return this.buyVolume}sell_volume(){return this.sellVolume}total_volume(){return this.totalVolume}delta(){return this.deltaVolume}poc(){return this.rowList[this.pocIndex]}vah(){return this.rowList[this.vahIndex]}val(){return this.rowList[this.valIndex]}rows(){return new Y([...this.rowList],H.any,this._context)}get_row_by_price(e){let n=Lo(e);if(typeof n!="number"||!Number.isFinite(n))return NaN;let r=r0(n/this._rowSize)-this._firstRowIndex;return r<0||r>=this.rowList.length?NaN:this.rowList[r]}},i0=[["ticks_per_row"],["ticks_per_row","va_percent"],["ticks_per_row","va_percent","imbalance_percent"]],s0={ticks_per_row:"series",va_percent:"series",imbalance_percent:"series"},a0=70,o0=300;function mu(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"?t[0]:t}function js(t){let e=mu(t);return e instanceof y?e.get(0):typeof e=="number"?e:NaN}function l0(t){return t.cache.__footprint||(t.cache.__footprint={bars:new Map,built:new Map,requestKey:null,loadedVersion:-1,warned:!1}),t.cache.__footprint}function Ws(t,e){if(e<0)throw new ye(`Invalid value of the \'${t}\' argument (${e}) in the \'request.footprint\' function. It must be >= 0.`,"request.footprint")}function ma(t,e,n){e.warned||(e.warned=!0,t.warn(n,"request.footprint"))}async function Xl(t,e,n){let r=t.marketData??[],i=r[0],s=r[r.length-1],a=n===void 0,o=a?i?.openTime:n,l=a?s?.closeTime??t.eDate:void 0,c=a?r.length:void 0,u=[];try{u=await t.source.getFootprintData(t.tickerId,t.timeframe,c,o,l)??[]}catch(p){ma(t,e,`request.footprint(): footprint data could not be loaded (${p instanceof Error?p.message:String(p)})`)}for(let p of u)!p||!Number.isFinite(p.openTime)||(e.bars.set(p.openTime,p),e.built.delete(p.openTime));e.loadedVersion=t.dataVersion}function c0(t){return async(...e)=>{let n=ge(e.map(mu),i0,s0),r=Math.trunc(js(n.ticks_per_row)),i=n.va_percent===void 0?a0:js(n.va_percent),s=n.imbalance_percent===void 0?o0:js(n.imbalance_percent),a=l0(t),o=`${r}|${i}|${s}`;if(a.requestKey===null)a.requestKey=o;else if(a.requestKey!==o)throw new ye("The script executes too many `request.footprint()` function calls.","request.footprint");if(Ws("ticks_per_row",r),Ws("va_percent",i),Ws("imbalance_percent",s),!(r>0))return NaN;if(!Xg(t.source))return ma(t,a,"request.footprint(): the market data source does not provide footprint data \\u2014 returning na"),NaN;let l=t.pine?.syminfo?.mintick;if(!(typeof l=="number"&&l>0))return ma(t,a,"request.footprint(): syminfo.mintick is unavailable, so rows cannot be sized \\u2014 returning na"),NaN;let c=y.from(t.data.openTime).get(0);a.loadedVersion===-1?await Xl(t,a,void 0):t.dataVersion>a.loadedVersion&&await Xl(t,a,c);let u=a.bars.get(c);if(!u)return NaN;if(!a.built.has(c)){let p={low:y.from(t.data.low).get(0),high:y.from(t.data.high).get(0)};a.built.set(c,Ui.build(t,u.levels??[],{ticksPerRow:r,mintick:l,vaPercent:Math.min(i,100),imbalancePercent:s},p))}return a.built.get(c)??NaN}}function u0(t){return(e,n,r)=>{t.params[r]||(t.params[r]=[]);let i;if(e instanceof y)i=e.get(n||0);else if(Array.isArray(e)){let s=e.some(o=>o instanceof y),a=e.every(o=>!(o instanceof y)&&!Array.isArray(o));(s||a)&&e.length>=1?i=e.map(o=>o instanceof y?o.get(0):o):i=y.from(e).get(n||0)}else i=e;return t.params[r].length===0?t.params[r].push(i):t.params[r][t.params[r].length-1]=i,t._requestParamSources||(t._requestParamSources={}),t._requestParamSources[r]=e,[i,r]}}var h0=new Set(["heikinashi","standard"]);function zr(t){if(typeof t=="string"&&t.startsWith("={"))try{let{symbol:e,...n}=JSON.parse(t.slice(1));if(typeof e=="string")return{symbol:e,modifiers:n}}catch{}return{symbol:t,modifiers:{}}}function Us(t,e){let n=Object.keys(e).filter(i=>e[i]!==void 0);if(n.length===0)return t;let r=n.map(i=>[i,e[i]]);return r.push(["symbol",t]),r.sort(([i],[s])=>i<s?-1:i>s?1:0),"="+JSON.stringify(Object.fromEntries(r))}function Wn(t){if(typeof t!="string")return{symbol:t,modifier:null};let e=t.lastIndexOf(";");if(e<=0||e===t.length-1)return{symbol:zr(t).symbol,modifier:null};let n=t.slice(e+1).toLowerCase();return h0.has(n)?{symbol:zr(t.slice(0,e)).symbol,modifier:n}:{symbol:zr(t).symbol,modifier:null}}function yu(t){if(typeof t!="string")return t;let{symbol:e,modifier:n}=Wn(t);return n?`${e};${n}`:e}function Pn(t){return Wn(t).symbol}function gu(t,e){let{modifier:n}=Wn(t);return`${n?t.slice(0,t.lastIndexOf(";")):t};${e}`}function Zl(t,e,n,r,i=!1,s=!1){for(let a=0;a<n.length;a++)if(n[a]<=t&&t<r[a])return i||s||e>=r[a]?a:a-1;return-1}function Ql(t,e,n,r,i=!1,s,a=!1){for(let o=n.length-1;o>=0;o--){if(r[o]<=e&&n[o]>=t){let l=s&&e>s;if(a&&i)for(let c=0;c<n.length;c++){if(n[c]>=t&&n[c]<e)return c;if(n[c]>=e)break}if(l&&i&&!a)for(let c=0;c<n.length;c++){if(n[c]>=t&&n[c]<e)return c;if(n[c]>=e)break}return o}if(r[o]<t)break}return-1}var Jl=[["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"]],p0={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function Fo(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function d0(t,e){return t.map(n=>Fo(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function ar(t){return Fo(t)?t[0]:t}function f0(t,e,n,r){let i=e[e.length-1].indexOf(t);if(i>=0&&i<n.length&&n[i]!==void 0)return n[i];if(Fo(r))return r[1]}function ya(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(ya):t}function m0(t){return async(...e)=>{let n=[],r=d0(e,n),i=ge(r,Jl,p0),s=ar(i.symbol),a=ar(i.timeframe),o=ar(i.expression),l=ar(i.gaps),c=ar(i.lookahead),u=s instanceof y?s.get(0):s,p=typeof t.tickerId=="string"&&t.tickerId.includes(":")?t.tickerId.split(":")[1]:t.tickerId,h=typeof p=="string"?Wn(p):{symbol:p,modifier:null},d=h.modifier==="standard"?null:h.modifier,f=yu(u===""?t.tickerId:u),m=typeof f=="string"&&f.includes(":")?f.split(":")[1]:f,_=a instanceof y?a.get(0):a,x=_===""?t.timeframe:typeof _=="string"?_:String(_??""),w=o,S=f0("expression",Jl,n,i.expression),v=l,E=c,C=v===!0||v==="gaps_on",I=E===!0||E==="lookahead_on",F=(()=>{let qe=ar(i.calc_bars_count);return typeof qe=="number"&&qe>0?qe:void 0})();if(t.isSecondaryContext){let qe=ya(w);return Array.isArray(qe)?[qe]:qe}let $=ze(t.timeframe),j=ze(x);if(!$||!j)throw new Error(`Invalid value of the \'timeframe\' argument (\'${j?t.timeframe:x}\') in the \'security\' function.`);let A=pt($),ue=pt(j),D=typeof m=="string"?Wn(m):{symbol:m,modifier:null},M=D.modifier==="standard"?null:D.modifier,W=!m||m===""||D.symbol===h.symbol&&M===d;if(Sr($)===Sr(j)&&W){let qe=ya(w);return Array.isArray(qe)?[qe]:qe}let k=A>ue,V=y.from(t.data.openTime).get(0),Q=y.from(t.data.closeTime).get(0),De=t.idx===t.length-1&&Q>Date.now(),Te=`${m}_${x}_${S}`,st=`${Te}_prevIdx`;if(t.cache[Te]){let qe=t.cache[Te];t.dataVersion>qe.dataVersion&&(await qe.pineTS.updateTail(qe.context),qe.dataVersion=t.dataVersion);let Vr=qe.context,xi=k?Ql(V,Q,Vr.data.openTime.data,Vr.data.closeTime.data,I,t.eDate,C):Zl(V,Q,Vr.data.openTime.data,Vr.data.closeTime.data,I,De);if(xi==-1)return NaN;let rr=Vr.params[S][xi];if(!k&&C){let $l=t.cache[st];return $l!==void 0&&$l===xi?NaN:(t.cache[st]=xi,Array.isArray(rr)?[rr]:rr)}return Array.isArray(rr)?[rr]:rr}let md=Math.max(1e3*60*60*24*30,2*ue*1e3),Fl=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),yd=F?void 0:Fl?Fl-md:void 0,gd=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),_i=new Rn(t.source,m,x,F,yd,gd);_i.markAsSecondary();let Vl=typeof S=="string"?S:"",_d=Vl.match(/p\\d+$/)?.[0]??Vl,Bl=t._ltfTruncatedBodies?.[_d],nr=Bl?await _i.runPretranspiled(Bl):await _i.run(t.pineTSCode);t.cache[Te]={pineTS:_i,context:nr,dataVersion:t.dataVersion};let Ls=k?Ql(V,Q,nr.data.openTime.data,nr.data.closeTime.data,I,t.eDate,C):Zl(V,Q,nr.data.openTime.data,nr.data.closeTime.data,I,De);if(Ls==-1)return NaN;let Fs=nr.params[S][Ls];return!k&&C?(t.cache[st]=Ls,NaN):Array.isArray(Fs)?[Fs]:Fs}}var ec=[["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"]],y0={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function Vo(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function g0(t,e){return t.map(n=>Vo(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function or(t){return Vo(t)?t[0]:t}function _0(t,e,n,r){let i=e[e.length-1].indexOf(t);if(i>=0&&i<n.length&&n[i]!==void 0)return n[i];if(Vo(r))return r[1]}function lr(t){return typeof t=="number"?H.float:typeof t=="boolean"?H.bool:typeof t=="string"?H.string:H.any}var _u={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 ga(t,e){if(!(t instanceof y))return null;let n=e?.data;if(!n)return null;for(let r of Object.keys(_u))if(t===n[r])return r;return null}function x0(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof Ht))return null;let n=t._udt;if(!n||!n._fieldDefaults||!Array.isArray(n._definitionKeys))return null;let r=n._definitionKeys;if(r.length===0)return null;let i=[];for(let s of r){if(!(s in n._fieldDefaults))return null;let a=n._fieldDefaults[s],o=ga(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:r,udt:n}}function b0(t,e){if(t===void 0)return null;if(Array.isArray(t)){let r=[];for(let i of t){let s=ga(i,e);if(s===null)return null;r.push(s)}return r.length>0?{kind:"tuple",builtinNames:r}:null}let n=ga(t,e);return n!==null?{kind:"series",builtinNames:[n]}:x0(t,e)}async function tc(t,e,n,r,i,s){let a=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),o=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),l=new Rn(t.source,e,n,r,a,o);l.markAsSecondary(),await l.ready();let c=l.openTime,u=l.closeTime,p=l.data,h=i.builtinNames.map(f=>_u[f]),d;if(i.kind==="series")d=p.map(f=>h[0](f));else if(i.kind==="tuple")d=p.map(f=>h.map(m=>m(f)));else{let f=i.fieldNames,m=i.udt;d=p.map(_=>{let x={};for(let w=0;w<f.length;w++)x[f[w]]=h[w](_);return new Ht(x,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function v0(t){return async(...e)=>{let n=[],r=g0(e,n),i=ge(r,ec,y0),s=or(i.symbol),a=or(i.timeframe),o=or(i.expression),l=s instanceof y?s.get(0):s,c=yu(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??""),d=o,f=_0("expression",ec,n,i.expression);or(i.ignore_invalid_symbol);let m=or(i.ignore_invalid_timeframe),_=(()=>{let W=or(i.calc_bars_count);return typeof W=="number"&&W>0?W:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(W=>new Y([W],lr(W),t))]:new Y([d],lr(d),t);let x=ze(t.timeframe),w=ze(h);if(!x||!w){if(m)return NaN;throw new Error(`Invalid value of the \'timeframe\' argument (\'${w?t.timeframe:h}\') in the \'security_lower_tf\' function.`)}let S=pt(x);if(pt(w)>S){if(m)return NaN;throw new Error(`Timeframe ${h} is not lower than or equal to chart timeframe ${t.timeframe}`)}if(Sr(w)===Sr(x))return Array.isArray(d)?[d.map(W=>new Y([W],lr(W),t))]:new Y([d],lr(d),t);let v=`${u}_${h}_${f}_lower`,E=t._requestParamSources?.[f],C=b0(E,t);if(!t.cache[v])if(C!==null){let W=await tc(t,u,h,_,C,f);t.cache[v]={pineTS:null,context:W,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:C}}}else{let W=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(),V=new Rn(t.source,u,h,_,W,k);V.markAsSecondary();let Q=typeof f=="string"?f:"",De=Q.match(/p\\d+$/)?.[0]??Q,Te=t._ltfTruncatedBodies?.[De],st;Te?st=await V.runPretranspiled(Te):st=await V.run(t.pineTSCode),t.cache[v]={pineTS:V,context:st,dataVersion:t.dataVersion}}let I=t.cache[v];if(t.dataVersion>I.dataVersion)if(I._fastPath){let W=await tc(t,u,h,_,I._fastPathArgs.builtinExpr,f);I.context=W,I.dataVersion=t.dataVersion}else await I.pineTS.updateTail(I.context),I.dataVersion=t.dataVersion;let F=I.context,$=y.from(t.data.openTime).get(0),j=y.from(t.data.closeTime).get(0),A=F.data.openTime.data,ue=F.data.closeTime.data,D=F.params[f];if(!D)return Array.isArray(d)?[d.map(()=>new Y([],H.float,t))]:new Y([],H.float,t);let M=[];for(let W=0;W<A.length;W++){let k=A[W];if(!(ue[W]<=$)){if(k>=j)break;k>=$&&k<j&&M.push(D[W])}}if(M.length>0&&Array.isArray(M[0])){let W=M[0].length,k=[];for(let V=0;V<W;V++){let Q=M.map(Te=>Te[V]),De=Q.length>0?lr(Q[0]):H.float;k.push(new Y(Q,De,t))}return[k]}else{let W=M.length>0?lr(M[0]):H.float;return new Y(M,W,t)}}}var w0=Object.defineProperty,S0=(t,e,n)=>e in t?w0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,jr=(t,e,n)=>S0(t,typeof e!="symbol"?e+"":e,n),E0={footprint:c0,param:u0,security:m0,security_lower_tf:v0},_a=class{constructor(e){this.context=e,jr(this,"_cache",{}),jr(this,"footprint"),jr(this,"param"),jr(this,"security"),jr(this,"security_lower_tf"),Object.entries(E0).forEach(([n,r])=>{this[n]=r(e)})}};function N0(t){return e=>{t.taState||(t.taState={});let n=e||"accdist";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.volume,0);if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=s-a,c=0;l!==0&&(c=(i-a-(s-i))/l*o);let u=r.prevCumulativeSum+c;return r.currentCumulativeSum=u,t.precision(u)}}function C0(t){return(e,n,r,i,...s)=>{let a=typeof s[s.length-1]=="string"?s.pop():void 0,o=y.from(n).get(0),l=y.from(r).get(0),c=y.from(i).get(0),u=s.length>0&&!!y.from(s[0]).get(0);t.taState||(t.taState={});let p=a||`alma_${o}_${l}_${c}_${u}`;t.taState[p]||(t.taState[p]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0,weightsKey:"",weights:[]});let h=t.taState[p],d=`${o}_${l}_${c}_${u}`;if(h.weightsKey!==d){let w=u?Math.floor(l*(o-1)):l*(o-1),S=o/c,v=[],E=0;for(let C=0;C<o;C++){let I=Math.exp(-Math.pow(C-w,2)/(2*S*S));v.push(I),E+=I}for(let C=0;C<v.length;C++)v[C]/=E;h.weights=v,h.weightsKey=d}t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevWindow=[...h.currentWindow],h.prevCallCount=h.currentCallCount),h.lastIdx=t.idx);let f=y.from(e).get(0),m=[...h.prevWindow];for(m.unshift(f);m.length>o;)m.pop();let _=h.prevCallCount+1;if(m.length<o&&(_>=o||t.idx>=o-1)){let w=y.from(e);for(;m.length<o;)m.push(w.get(m.length))}if(h.currentWindow=m,h.currentCallCount=_,m.length<o)return NaN;let x=0;for(let w=0;w<o;w++)x+=h.weights[w]*m[o-1-w];return t.precision(x)}}function I0(t){return(e,n)=>{let r=y.from(e).get(0);t.taState||(t.taState={});let i=n||`atr_${r}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevAtr:null,prevInitSum:0,prevInitCount:0,currentAtr:null,currentInitSum:0,currentInitCount:0});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevAtr=s.currentAtr,s.prevInitSum=s.currentInitSum,s.prevInitCount=s.currentInitCount),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return NaN;let c=t.idx>0?t.get(t.data.close,1):null,u;if(c!==null&&!isNaN(c)){let m=a-o,_=Math.abs(a-c),x=Math.abs(o-c);u=Math.max(m,_,x)}else u=a-o;let p=s.prevInitCount,h=s.prevInitSum,d=s.prevAtr;if(p<r){if(h+=u,p++,s.currentInitSum=h,s.currentInitCount=p,p===r){let m=h/r;return s.currentAtr=m,t.precision(m)}return NaN}let f=(d*(r-1)+u)/r;return s.currentAtr=f,t.precision(f)}}function k0(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"barssince";t.taState[r]||(t.taState[r]={lastIdx:-1,prevLastTrueIndex:null,currentLastTrueIndex:null});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevLastTrueIndex=i.currentLastTrueIndex),i.lastIdx=t.idx);let s=y.from(e).get(0),a=i.prevLastTrueIndex;return s&&(a=t.idx),i.currentLastTrueIndex=a,a===null?NaN:t.idx-a}}function A0(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`bb_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,[[NaN,NaN,NaN]];let u=[...l.prevWindow],p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){let x=u.pop();p-=x}if(u.length<s&&t.idx>=s-1){let x=y.from(e);for(;u.length<s;){let w=x.get(u.length);if(isNaN(w))break;u.push(w),p+=w}}if(l.currentWindow=u,l.currentSum=p,u.length<s)return[[NaN,NaN,NaN]];let h=p/s,d=0;for(let x=0;x<s;x++)d+=Math.pow(u[x]-h,2);let f=Math.sqrt(d/s),m=h+a*f,_=h-a*f;return[[t.precision(h),t.precision(m),t.precision(_)]]}}function M0(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`bbw_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevSum:0,currentWindow:[],currentSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevSum=l.currentSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentWindow=[...l.prevWindow],l.currentSum=l.prevSum,NaN;let u=[...l.prevWindow],p=l.prevSum;for(u.unshift(c),p+=c;u.length>s;){let w=u.pop();p-=w}if(u.length<s&&t.idx>=s-1){let w=y.from(e);for(;u.length<s;){let S=w.get(u.length);if(isNaN(S))break;u.push(S),p+=S}}if(l.currentWindow=u,l.currentSum=p,u.length<s)return NaN;let h=p/s,d=0;for(let w=0;w<s;w++){let S=u[w]-h;d+=S*S}let f=d/s,m=Math.sqrt(f),_=a*m;if(h===0)return t.precision(0);let x=2*_/h*100;return t.precision(x)}}function T0(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`cci_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow],c=a.prevSum,u=_=>_==null||Number.isNaN(_)?0:_;for(l.unshift(o),c+=u(o);l.length>i;){let _=l.pop();c-=u(_)}let p=a.prevCallCount+1;if(l.length<i&&(p>=i||t.idx>=i-1)){let _=y.from(e);for(;l.length<i;){let x=_.get(l.length);if(isNaN(x))break;l.push(x),c+=x}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=p,l.length<i||l.some(_=>_==null||Number.isNaN(_)))return NaN;let h=c/i,d=0;for(let _=0;_<i;_++)d+=Math.abs(l[_]-h);let f=d/i;if(f===0)return 0;let m=(o-h)/(.015*f);return t.precision(m)}}function P0(t){return(e,n=1,r)=>{typeof n=="string"&&(r=n,n=1);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`change_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let p=y.from(e);for(;l.length<i+1;)l.push(p.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=o-l[i];return t.precision(u)}}function D0(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`cmo_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevGainsWindow:[],prevLossesWindow:[],prevGainsSum:0,prevLossesSum:0,prevLength:void 0,currentGainsWindow:[],currentLossesWindow:[],currentGainsSum:0,currentLossesSum:0,currentLength:void 0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevGainsWindow=[...a.currentGainsWindow],a.prevLossesWindow=[...a.currentLossesWindow],a.prevGainsSum=a.currentGainsSum,a.prevLossesSum=a.currentLossesSum,a.prevLength=a.currentLength),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1);if(isNaN(o)||isNaN(l))return NaN;let c=o-l,u=c>=0?c:0,p=c>=0?0:-c,h,d,f,m;if(a.prevLength!==void 0&&a.prevLength!==i){h=[],d=[],f=0,m=0;let w=y.from(e);for(let S=0;S<i;S++){let v=w.get(S)-w.get(S+1);if(isNaN(v))break;h.push(v>=0?v:0),d.push(v>=0?0:-v),f+=h[S],m+=d[S]}}else h=[...a.prevGainsWindow],d=[...a.prevLossesWindow],f=a.prevGainsSum,m=a.prevLossesSum,h.unshift(u),d.unshift(p),f+=u,m+=p;if(a.currentLength=i,h.length<i)return a.currentGainsWindow=h,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m,NaN;if(h.length>i){let w=h.pop(),S=d.pop();f-=w,m-=S}a.currentGainsWindow=h,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m;let _=f+m;if(_===0)return t.precision(0);let x=100*(f-m)/_;return t.precision(x)}}function O0(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e),a=0,o=!1;for(let u=0;u<i;u++){let p=s.get(u);if(isNaN(p)){o=!0;break}a+=p}if(o)return NaN;let l=0;for(let u=0;u<i;u++){let p=s.get(u);l+=p*(u+1)}if(a===0)return NaN;let c=-l/a;return t.precision(c)}}var sn=t=>t==null||typeof t=="number"&&Number.isNaN(t);function Un(t,e,n,r){t.taState||(t.taState={});let i=t.taState[e];i||(i=t.taState[e]={lastIdx:-1,prev:{entries:[],sum:0,calls:0,callIdx:-1,exhausted:!1,length:NaN},current:{entries:[],sum:0,calls:0,callIdx:-1,exhausted:!1,length:NaN}}),t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prev={...i.current,entries:[...i.current.entries]}),i.lastIdx=t.idx);let s=i.prev,a=s.calls+1,o=[...s.entries],l=s.sum,c=s.exhausted&&s.callIdx===t.idx-1&&s.length===r,u=n(0);for(sn(u)||(o.unshift({v:u,n:a}),l+=u);o.length>r;)l-=o.pop().v;let p=s.length!==r;if(o.length<r&&!c&&(a>=r||t.idx>=r-1)){let h=o.length?a-o[o.length-1].n+1:1;for(;o.length<r&&h<=t.idx;h++){let d=n(h);sn(d)||o.push({v:d,n:a-h})}c=o.length<r,p=!0}return p&&(l=o.reduce((h,d)=>h+d.v,0)),i.current={entries:o,sum:l,calls:a,callIdx:t.idx,exhausted:c,length:r},o.length<r?void 0:{values:o.map(h=>h.v),sum:l}}function R0(t){return(e,n,r,i)=>{let s=y.from(r).get(0),a=y.from(e),o=y.from(n),l=i||`correlation_${s}`,c=(x,w)=>{let S=Un(t,`${l}_${x}`,w,s);if(!S)return NaN;let v=0;for(let E of S.values)v+=E;return v/s},u=c("x",x=>a.get(x)),p=c("y",x=>o.get(x)),h=c("xy",x=>a.get(x)*o.get(x)),d=c("xx",x=>a.get(x)*a.get(x)),f=c("yy",x=>o.get(x)*o.get(x));if([u,p,h,d,f].some(x=>Number.isNaN(x)))return NaN;let m=d-u*u,_=f-p*p;return m<=0||_<=0?t.precision(0):t.precision((h-u*p)/Math.sqrt(m*_))}}function xu(t,e,n){if(!e)return;t.taState||(t.taState={});let r=t.taState[e];return r||(r=t.taState[e]={lastIdx:-1,shared:!1,prev:n(),current:n()}),t.idx>r.lastIdx?(r.lastIdx>=0&&(r.prev={...r.current}),r.lastIdx=t.idx):r.current.callIdx===t.idx&&(r.shared=!0),r.shared?void 0:r}function bu(t,e,n,r,i){let s=(l,c)=>i?l>c:l<c,a=xu(t,e,()=>({count:0,callIdx:-1,length:NaN})),o;if(a&&a.prev.callIdx===t.idx-1&&a.prev.length===r){let l=n.get(0),c=n.get(1);o=sn(l)||sn(c)?a.prev.count:s(l,c)?a.prev.count+1:0}else{o=0;for(let l=0;l<t.idx&&o<r;l++){let c=n.get(l),u=n.get(l+1);if(!(sn(c)||sn(u))){if(!s(c,u))break;o++}}}return a&&(a.current={count:o,callIdx:t.idx,length:r}),o>=r}function Bo(t,e,n,r){let i=n.get(0),s=r.get(0),a=xu(t,e,()=>({a:NaN,b:NaN,callIdx:-1})),o=NaN,l=NaN;if(a&&a.prev.callIdx===t.idx-1)o=a.prev.a,l=a.prev.b;else for(let c=1;c<=t.idx;c++){let u=n.get(c),p=r.get(c);if(!sn(u)&&!sn(p)){o=u,l=p;break}}if(a){let c=!sn(i)&&!sn(s);a.current={a:c?i:o,b:c?s:l,callIdx:t.idx}}return[i,s,o,l]}function L0(t){return(e,n,r)=>{let[i,s,a,o]=Bo(t,r,y.from(e),y.from(n));if(isNaN(i)||isNaN(s)||isNaN(a)||isNaN(o))return!1;let l=i>s&&a<=o,c=i<s&&a>=o;return l||c}}function F0(t){return(e,n,r)=>{let[i,s,a,o]=Bo(t,r,y.from(e),y.from(n));return a<=o&&i>s}}function V0(t){return(e,n,r)=>{let[i,s,a,o]=Bo(t,r,y.from(e),y.from(n));return a>=o&&i<s}}function B0(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"cum";t.taState[r]||(t.taState[r]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevCumulativeSum=i.currentCumulativeSum),i.lastIdx=t.idx);let s=y.from(e).get(0);if(isNaN(s))return i.currentCumulativeSum=i.prevCumulativeSum,NaN;let a=i.prevCumulativeSum+s;return i.currentCumulativeSum=a,t.precision(a)}}function $0(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`dev_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevSum:0,prevCallCount:0,currentWindow:[],currentSum:0,currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevSum=a.currentSum,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow],c=a.prevSum,u=m=>m==null||Number.isNaN(m)?0:m;for(l.unshift(o),c+=u(o);l.length>i;){let m=l.pop();c-=u(m)}let p=a.prevCallCount+1;if(l.length<i&&(p>=i||t.idx>=i-1)){let m=y.from(e);for(;l.length<i;){let _=m.get(l.length);l.push(_),c+=u(_)}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=p,l.length<i||l.some(m=>m==null||Number.isNaN(m)))return NaN;let h=c/i,d=0;for(let m=0;m<i;m++)d+=Math.abs(l[m]-h);let f=d/i;return t.precision(f)}}function j0(t){return(e,n,r)=>{let i=y.from(e).get(0),s=y.from(n).get(0);t.taState||(t.taState={});let a=r||`dmi_${i}_${s}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevTrInitSum:0,prevPlusInitSum:0,prevMinusInitSum:0,prevInitCount:0,prevSmoothedTR:NaN,prevSmoothedPlus:NaN,prevSmoothedMinus:NaN,prevDxInitSum:0,prevAdxInitCount:0,prevADX:NaN,currentTrInitSum:0,currentPlusInitSum:0,currentMinusInitSum:0,currentInitCount:0,currentSmoothedTR:NaN,currentSmoothedPlus:NaN,currentSmoothedMinus:NaN,currentDxInitSum:0,currentAdxInitCount:0,currentADX:NaN});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevTrInitSum=o.currentTrInitSum,o.prevPlusInitSum=o.currentPlusInitSum,o.prevMinusInitSum=o.currentMinusInitSum,o.prevInitCount=o.currentInitCount,o.prevSmoothedTR=o.currentSmoothedTR,o.prevSmoothedPlus=o.currentSmoothedPlus,o.prevSmoothedMinus=o.currentSmoothedMinus,o.prevDxInitSum=o.currentDxInitSum,o.prevAdxInitCount=o.currentAdxInitCount,o.prevADX=o.currentADX),o.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN,NaN]];let p=t.idx>0?t.get(t.data.high,1):NaN,h=t.idx>0?t.get(t.data.low,1):NaN,d=t.idx>0?t.get(t.data.close,1):NaN;if(isNaN(p))return[[NaN,NaN,NaN]];let f=Math.max(l-c,Math.abs(l-d),Math.abs(c-d)),m=l-p,_=h-c,x=m>_&&m>0?m:0,w=_>m&&_>0?_:0,S=o.prevInitCount,v=o.prevTrInitSum,E=o.prevPlusInitSum,C=o.prevMinusInitSum,I=o.prevSmoothedTR,F=o.prevSmoothedPlus,$=o.prevSmoothedMinus;if(S++,S<=i)v+=f,E+=x,C+=w,S===i&&(I=v/i,F=E/i,$=C/i);else{let Q=1/i;I=Q*f+(1-Q)*I,F=Q*x+(1-Q)*F,$=Q*w+(1-Q)*$}if(o.currentInitCount=S,o.currentTrInitSum=v,o.currentPlusInitSum=E,o.currentMinusInitSum=C,o.currentSmoothedTR=I,o.currentSmoothedPlus=F,o.currentSmoothedMinus=$,S<i)return[[NaN,NaN,NaN]];let j=I===0?0:100*F/I,A=I===0?0:100*$/I,ue=j+A,D=ue===0?0:100*Math.abs(j-A)/ue,M=o.prevAdxInitCount,W=o.prevDxInitSum,k=o.prevADX,V=NaN;if(M++,M<=s)W+=D,M===s&&(k=W/s,V=k);else{let Q=1/s;k=Q*D+(1-Q)*k,V=k}return o.currentAdxInitCount=M,o.currentDxInitSum=W,o.currentADX=k,[[t.precision(j),t.precision(A),t.precision(V)]]}}function W0(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`ema_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevEma:null,prevInitSum:0,prevInitCount:0,currentEma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevEma=a.currentEma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return NaN;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevEma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentEma=d,t.precision(d)}return NaN}let p=2/(i+1),h=o*p+u*(1-p);return a.currentEma=h,t.precision(h)}}function U0(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);return bu(t,r,s,i,!1)}}function q0(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.high);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`highest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.findIndex(d=>d===void 0||isNaN(d)),p=u===-1?l:l.slice(0,u);if(p.length===0)return NaN;let h=Math.max(...p);return t.precision(h)}}function z0(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.high);let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=-1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);if(c===void 0||isNaN(c))break;(isNaN(o)||c>=a)&&(a=c,o=-l)}return isNaN(o)?0:o}}function H0(t){return(e,n,r)=>{let i=y.from(n).get(0),s=Math.floor(i/2),a=Math.floor(Math.sqrt(i)),o=t.pine.ta.wma,l=o(e,s,r?`${r}_wma1`:void 0),c=o(e,i,r?`${r}_wma2`:void 0),u=isNaN(l)||isNaN(c);t.taState||(t.taState={});let p=r||`hma_raw_${i}`;t.taState[p]||(t.taState[p]={lastIdx:-1,prevValues:[],currentValues:[]});let h=t.taState[p];t.idx>h.lastIdx&&(h.lastIdx>=0&&(h.prevValues=[...h.currentValues]),h.lastIdx=t.idx);let d=2*l-c,f=[...h.prevValues];f.unshift(d),f.length>a+1&&f.pop(),h.currentValues=f;let m=r?`${r}_hma_final`:`hma_final_${i}`;t.taState[m]||(t.taState[m]={lastIdx:-1,prevWindow:[],currentWindow:[]});let _=t.taState[m];t.idx>_.lastIdx&&(_.lastIdx>=0&&(_.prevWindow=[..._.currentWindow]),_.lastIdx=t.idx);let x=[..._.prevWindow];if(u){if(!x.length)return NaN;for(x.unshift(x[0]);x.length>a;)x.pop();return _.currentWindow=x,NaN}if(x.unshift(d),x.length<a)return _.currentWindow=x,NaN;for(;x.length>a;)x.pop();_.currentWindow=x;let w=0,S=0;for(let E=0;E<a;E++){let C=a-E;w+=x[E]*C,S+=C}let v=w/S;return t.precision(v)}}function K0(t){return e=>{let n=t.get(t.data.close,0),r=t.get(t.data.high,0),i=t.get(t.data.low,0),s=t.get(t.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s))return NaN;let a=r-i;if(a===0)return t.precision(0);let o=(2*n-r-i)/a*s;return t.precision(o)}}function G0(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0));let c,u=t.get(t.data.high,0),p=t.get(t.data.low,0);if(l){let v=t.get(t.data.close,1);isNaN(v)?c=NaN:c=Math.max(u-p,Math.abs(u-v),Math.abs(p-v))}else c=u-p;let h=y.from(e).get(0);t.taState||(t.taState={});let d=s||`kc_${a}_${o}_${l}`;t.taState[d]||(t.taState[d]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let f=t.taState[d];t.idx>f.lastIdx&&(f.lastIdx>=0&&(f.basisState={...f.currentBasisState},f.rangeState={...f.currentRangeState}),f.lastIdx=t.idx);let m=(v,E,C,I)=>{if(isNaN(C))return Object.assign(E,v),E.prevEma!==null?E.prevEma:NaN;let F=v.initCount,$=v.initSum,j=v.prevEma;if(F<I){if($+=C,F++,E.initSum=$,E.initCount=F,E.prevEma=j,F===I){let D=$/I;return E.prevEma=D,D}return NaN}let A=2/(I+1),ue=C*A+j*(1-A);return E.prevEma=ue,E.initSum=$,E.initCount=F,ue},_=m(f.basisState,f.currentBasisState,h,a),x=m(f.rangeState,f.currentRangeState,c,a);if(isNaN(_)||isNaN(x))return[[NaN,NaN,NaN]];let w=_+x*o,S=_-x*o;return[[t.precision(_),t.precision(w),t.precision(S)]]}}function Y0(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=!0;typeof i=="string"?s=i:i!==void 0&&(l=y.from(i).get(0)),t.taState||(t.taState={});let c=s||`kcw_${a}_${o}_${l}`;t.taState[c]||(t.taState[c]={lastIdx:-1,basisState:{prevEma:null,initSum:0,initCount:0},rangeState:{prevEma:null,initSum:0,initCount:0},currentBasisState:{prevEma:null,initSum:0,initCount:0},currentRangeState:{prevEma:null,initSum:0,initCount:0}});let u=t.taState[c];t.idx>u.lastIdx&&(u.lastIdx>=0&&(u.basisState={...u.currentBasisState},u.rangeState={...u.currentRangeState}),u.lastIdx=t.idx);let p=(S,v,E,C)=>{if(isNaN(E))return Object.assign(v,S),v.prevEma!==null?v.prevEma:NaN;let I=S.initCount,F=S.initSum,$=S.prevEma;if(I<C){if(F+=E,I++,v.initSum=F,v.initCount=I,v.prevEma=$,I===C){let ue=F/C;return v.prevEma=ue,ue}return NaN}let j=2/(C+1),A=E*j+$*(1-j);return v.prevEma=A,v.initSum=F,v.initCount=I,A},h,d=t.get(t.data.high,0),f=t.get(t.data.low,0);if(l){let S=t.get(t.data.close,1);isNaN(S)?h=NaN:h=Math.max(d-f,Math.abs(d-S),Math.abs(f-S))}else h=d-f;let m=y.from(e).get(0),_=p(u.basisState,u.currentBasisState,m,a),x=p(u.rangeState,u.currentRangeState,h,a);if(isNaN(_)||isNaN(x))return NaN;if(_===0)return t.precision(0);let w=2*x*o/_;return t.precision(w)}}function X0(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`linreg_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevWindow=[...l.currentWindow],l.prevCallCount=l.currentCallCount),l.lastIdx=t.idx);let c=y.from(e).get(0),u=[...l.prevWindow];for(u.unshift(c);u.length>s;)u.pop();let p=l.prevCallCount+1;if(u.length<s&&(p>=s||t.idx>=s-1)){let v=y.from(e);for(;u.length<s;)u.push(v.get(u.length))}if(l.currentWindow=u,l.currentCallCount=p,u.length<s)return NaN;let h=0,d=0,f=0,m=0,_=s;for(let v=0;v<s;v++){let E=s-1-v,C=u[v];h+=E,d+=C,f+=E*C,m+=E*E}let x=_*m-h*h;if(x===0)return NaN;let w=(_*f-h*d)/x,S=(d-w*h)/_+w*(s-1-a);return t.precision(S)}}function Z0(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.low);let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`lowest_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i;)l.pop();let c=a.prevCallCount+1;if(l.length<i&&(c>=i||t.idx>=i-1)){let d=y.from(e);for(;l.length<i;)l.push(d.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<i)return NaN;let u=l.findIndex(d=>d===void 0||isNaN(d)),p=u===-1?l:l.slice(0,u);if(p.length===0)return NaN;let h=Math.min(...p);return t.precision(h)}}function Q0(t){return(e,n,r)=>{typeof n=="string"&&r===void 0&&(r=n,n=e,e=t.data.low);let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=1/0,o=NaN;for(let l=0;l<i;l++){let c=s.get(l);if(c===void 0||isNaN(c))break;(isNaN(o)||c<=a)&&(a=c,o=-l)}return isNaN(o)?0:o}}function J0(t){return(e,n,r,i,s)=>{let a=y.from(n).get(0),o=y.from(r).get(0),l=y.from(i).get(0),c=s||`macd_${a}_${o}_${l}`,u=`${c}_fast`,p=`${c}_slow`,h=`${c}_signal`,d=t.pine.ta.ema(e,a,u),f=t.pine.ta.ema(e,o,p),m=NaN;!isNaN(d)&&!isNaN(f)&&(m=d-f);let _=NaN;isNaN(m)||(_=t.pine.ta.ema(m,l,h));let x=NaN;return!isNaN(m)&&!isNaN(_)&&(x=m-_),[[t.precision(m),t.precision(_),t.precision(x)]]}}function e_(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"max";t.taState[r]||(t.taState[r]={lastIdx:-1,prevMax:NaN,currentMax:NaN});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevMax=i.currentMax),i.lastIdx=t.idx);let s=y.from(e).get(0),a;return isNaN(s)?a=i.prevMax:isNaN(i.prevMax)?a=s:a=Math.max(i.prevMax,s),i.currentMax=a,t.precision(a)}}function t_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e),a=Un(t,r||`median_${i}`,u=>s.get(u),i);if(!a)return NaN;let o=a.values.slice().sort((u,p)=>u-p),l=Math.floor(i/2),c=i%2===0?(o[l-1]+o[l])/2:o[l];return t.precision(c)}}function n_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`mfi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevUpperWindow:[],prevLowerWindow:[],prevUpperSum:0,prevLowerSum:0,currentUpperWindow:[],currentLowerWindow:[],currentUpperSum:0,currentLowerSum:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevUpperWindow=[...a.currentUpperWindow],a.prevLowerWindow=[...a.currentLowerWindow],a.prevUpperSum=a.currentUpperSum,a.prevLowerSum=a.currentLowerSum),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(e).get(1),c=t.get(t.data.volume,0);if(isNaN(o)||isNaN(c))return NaN;let u=isNaN(l)?NaN:o-l,p=c*(u<=0?0:o),h=c*(u>=0?0:o),d=[...a.prevUpperWindow],f=[...a.prevLowerWindow],m=a.prevUpperSum,_=a.prevLowerSum;if(d.unshift(p),f.unshift(h),m+=p,_+=h,d.length<i)return a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=_,NaN;if(d.length>i){let w=d.pop(),S=f.pop();m-=w,_-=S}if(a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=_,_===0)return t.precision(100);if(m===0)return t.precision(0);let x=100-100/(1+m/_);return t.precision(x)}}function r_(t){return(e,n)=>{t.taState||(t.taState={});let r=n||"min";t.taState[r]||(t.taState[r]={lastIdx:-1,prevMin:NaN,currentMin:NaN});let i=t.taState[r];t.idx>i.lastIdx&&(i.lastIdx>=0&&(i.prevMin=i.currentMin),i.lastIdx=t.idx);let s=y.from(e).get(0),a;return isNaN(s)?a=i.prevMin:isNaN(i.prevMin)?a=s:a=Math.min(i.prevMin,s),i.currentMin=a,t.precision(a)}}function i_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i-1)return NaN;let a=new Map;for(let c=0;c<i;c++){let u=s.get(c);isNaN(u)||a.set(u,(a.get(u)||0)+1)}if(a.size===0)return NaN;let o=NaN,l=-1;for(let[c,u]of a.entries())u>l?(l=u,o=c):u===l&&c<o&&(o=c);return o}}function s_(t){return(e,n,r)=>{let i=y.from(n).get(0);return t.pine.ta.change(e,i,r)}}function a_(t){return e=>{t.taState||(t.taState={});let n=e||"nvi";t.taState[n]||(t.taState[n]={lastIdx:-1,committedNVI:1,tentativeNVI:1});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedNVI=r.tentativeNVI),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o,h=r.committedNVI;if(!(l===0||c===0)&&u<p){let d=(l-c)/c;h=h+d*h}return r.tentativeNVI=h,t.precision(h)}}function o_(t){return()=>{t.taState||(t.taState={});let e="obv";t.taState[e]||(t.taState[e]={lastIdx:-1,committedOBV:0,tentativeOBV:0});let n=t.taState[e];t.idx>n.lastIdx&&(n.lastIdx>=0&&(n.committedOBV=n.tentativeOBV),n.lastIdx=t.idx);let r=t.get(t.data.close,0),i=t.get(t.data.volume,0),s=t.get(t.data.close,1);if(isNaN(s))return n.tentativeOBV=0,t.precision(0);let a=n.committedOBV;return r>s?a+=i:r<s&&(a-=i),n.tentativeOBV=a,t.precision(a)}}function l_(t){return(e,n,r)=>e instanceof y?n?new y(e.data,e.offset+n):e:(t.params[r]||(t.params[r]=[]),Array.isArray(e)?new y(e,n||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],n||0)))}function c_(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let f=0;f<s;f++){let m=o.get(f);if(isNaN(m))return NaN;l.push(m)}l.sort((f,m)=>f-m);let c=a/100*s-.5;c<0&&(c=0),c>s-1&&(c=s-1);let u=Math.floor(c),p=Math.ceil(c);if(u===p)return t.precision(l[u]);let h=c-u,d=l[u]+h*(l[p]-l[u]);return t.precision(d)}}function u_(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e);if(t.idx<s-1)return NaN;let l=[];for(let u=0;u<s;u++){let 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 h_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);if(t.idx<i)return NaN;let a=s.get(0),o=0;if(a!=null)for(let l=1;l<=i;l++){let c=s.get(l);c!=null&&c<=a&&o++}return t.precision(o/i*100)}}function p_(t,e,n){let r=new Array(t.length).fill(NaN);for(let i=e+n;i<t.length;i++){let s=t[i-n];if(s===void 0||isNaN(s))continue;let a=!0;for(let o=1;o<=e;o++){let l=t[i-n-o];if(l===void 0||isNaN(l))break;if(l>s){a=!1;break}}if(a)for(let o=1;o<=n;o++){let l=t[i-n+o];if(l===void 0||isNaN(l))break;if(l>=s){a=!1;break}}a&&(r[i]=s)}return r}function d_(t){return(e,n,r,i)=>{typeof r=="string"&&(r=n,n=e,e=t.data.high);let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=p_(o,s,a),c=t.idx;return t.precision(l[c])}}function f_(t,e,n){let r=new Array(t.length).fill(NaN);for(let i=e+n;i<t.length;i++){let s=t[i-n];if(s===void 0||isNaN(s))continue;let a=!0;for(let o=1;o<=e;o++){let l=t[i-n-o];if(l===void 0||isNaN(l))break;if(l<s){a=!1;break}}if(a)for(let o=1;o<=n;o++){let l=t[i-n+o];if(l===void 0||isNaN(l))break;if(l<=s){a=!1;break}}a&&(r[i]=s)}return r}function m_(t){return(e,n,r,i)=>{typeof r=="string"&&(r=n,n=e,e=t.data.low);let s=y.from(n).get(0),a=y.from(r).get(0),o=y.from(e).toArray(),l=f_(o,s,a),c=t.idx;return t.precision(l[c])}}var y_=["Traditional","Fibonacci","Woodie","Classic","DM","Camarilla"];function nc(t,{high:e,low:n,close:r},i){let s=e-n,a=(e+n+r)/3;switch(t){case"Traditional":return[a,a*2-n,a*2-e,a+s,a-s,a*2+(e-2*n),a*2-(2*e-n),a*3+(e-3*n),a*3-(3*e-n),a*4+(e-4*n),a*4-(4*e-n)];case"Fibonacci":return[a,a+.382*s,a-.382*s,a+.618*s,a-.618*s,a+s,a-s,NaN,NaN,NaN,NaN];case"Woodie":{let o=(e+n+2*i)/4,l=e+2*(o-n),c=n-2*(e-o);return[o,2*o-n,2*o-e,o+s,o-s,l,c,l+s,c-s,NaN,NaN]}case"Classic":return[a,2*a-n,2*a-e,a+s,a-s,a+2*s,a-2*s,a+3*s,a-3*s,NaN,NaN];case"DM":{let o=r<i?e+2*n+r:r>i?2*e+n+r:e+n+2*r;return[o/4,o/2-n,o/2-e,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN]}case"Camarilla":{let o=e/n*r;return[a,r+s*1.1/12,r-s*1.1/12,r+s*1.1/6,r-s*1.1/6,r+s*1.1/4,r-s*1.1/4,r+s*1.1/2,r-s*1.1/2,o,r-(o-r)]}}return new Array(11).fill(NaN)}function g_(t){return(e,n,...r)=>{let i=typeof r[r.length-1]=="string"?r.pop():void 0,s=y.from(e).get(0),a=y.from(n).get(0)===!0,o=r.length>0&&y.from(r[0]).get(0)===!0;if(!y_.includes(s))throw new ye(`Invalid argument \'${s}\' for \'type\' in the \'ta.pivot_point_levels\' function. Possible values: [\'Camarilla\', \'Traditional\', \'DM\', \'Classic\', \'Fibonacci\', \'Woodie\']`,"ta.pivot_point_levels");if(o&&s==="Woodie")throw new ye(\'The `developing` parameter of the `ta.pivot_point_levels()` cannot be `true` when `type` is "Woodie".\',"ta.pivot_point_levels");t.taState||(t.taState={});let l=i||`pivot_point_levels_${s}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prev:{period:null,levels:null},current:{period:null,levels:null}});let c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prev=c.current),c.lastIdx=t.idx);let u={open:y.from(t.data.open).get(0),high:y.from(t.data.high).get(0),low:y.from(t.data.low).get(0),close:y.from(t.data.close).get(0)},p=c.prev.period,h=c.prev.levels;a||!p?(a&&p&&(h=nc(s,p,s==="Woodie"?u.open:p.open)),p={...u}):p={open:p.open,high:Math.max(p.high,u.high),low:Math.min(p.low,u.low),close:u.close},c.current={period:p,levels:h};let d=o?nc(s,p,p.open):h??new Array(11).fill(NaN);return new Y(d.map(f=>t.precision(f)),H.float,t)}}function __(t){return e=>{t.taState||(t.taState={});let n=e||"pvi";t.taState[n]||(t.taState[n]={lastIdx:-1,committedPVI:1,tentativePVI:1});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.committedPVI=r.tentativePVI),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=t.get(t.data.volume,1),l=isNaN(i)?0:i,c=isNaN(s)?0:s,u=isNaN(a)?0:a,p=isNaN(o)?0:o,h=r.committedPVI;if(!(l===0||c===0)&&u>p){let d=(l-c)/c;h=h+d*h}return r.tentativePVI=h,t.precision(h)}}function x_(t){return e=>{t.taState||(t.taState={});let n=e||"pvt";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.close,1),a=t.get(t.data.volume,0),o=r.prevCumulativeSum;if(!isNaN(i)&&!isNaN(s)&&!isNaN(a)&&s!==0){let l=(i-s)/s*a;o+=l}return r.currentCumulativeSum=o,t.precision(o)}}function b_(t){return(e,n,r)=>{let i=y.from(n).get(0);if(!(i>=1))return NaN;t.taState||(t.taState={});let s=r||`range_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=a.currentWindow,a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=d=>d==null||isNaN(d),l=y.from(e),c=[...a.prevWindow];if(a.prevCallCount===0)for(let d=1;d<=t.idx&&c.length<i;d++){let f=l.get(d);o(f)||c.unshift(f)}let u=l.get(0);for(o(u)||c.push(u);c.length>i;)c.shift();if(a.currentWindow=c,a.currentCallCount=a.prevCallCount+1,c.length<i)return NaN;let p=Number.MIN_VALUE,h=1/0;for(let d of c)d>p&&(p=d),d<h&&(h=d);return t.precision(p-h)}}function v_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`rci_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCount:0,currentWindow:[],currentCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=a.currentWindow,a.prevCount=a.currentCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=a.prevWindow.slice();if(l.push(o??NaN),l.length>i&&l.shift(),a.currentWindow=l,a.currentCount=a.prevCount+1,i<2||a.currentCount<=i||l.some(m=>Number.isNaN(m)))return NaN;let c=l.map((m,_)=>_).sort((m,_)=>l[m]-l[_]),u=new Array(i);for(let m=0;m<i;){let _=m;for(;_+1<i&&l[c[_+1]]===l[c[m]];)_++;let x=(m+_)/2+1;for(let w=m;w<=_;w++)u[c[w]]=x;m=_+1}let p=(i+1)/2,h=0,d=0,f=0;for(let m=0;m<i;m++){let _=m+1-p,x=u[m]-p;h+=_*x,d+=_*_,f+=x*x}return f===0?NaN:t.precision(h/Math.sqrt(d*f)*100)}}function w_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e);return bu(t,r,s,i,!0)}}function S_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`rma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevRma:null,prevInitSum:0,prevInitCount:0,currentRma:null,currentInitSum:0,currentInitCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevRma=a.currentRma,a.prevInitSum=a.currentInitSum,a.prevInitCount=a.currentInitCount),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||Number.isNaN(o))return a.currentRma=a.prevRma,a.currentInitSum=a.prevInitSum,a.currentInitCount=a.prevInitCount,NaN;let l=a.prevInitCount,c=a.prevInitSum,u=a.prevRma;if(l<i){if(c+=o,l++,a.currentInitSum=c,a.currentInitCount=l,l===i){let d=c/i;return a.currentRma=d,t.precision(d)}return NaN}let p=1/i,h=o*p+u*(1-p);return a.currentRma=h,t.precision(h)}}function E_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`roc_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>i+1;)l.pop();let c=a.prevCallCount+1;if(l.length<i+1&&(c>=i+1||t.idx>=i)){let h=y.from(e);for(;l.length<i+1;)l.push(h.get(l.length))}if(a.currentWindow=l,a.currentCallCount=c,l.length<=i)return NaN;let u=l[i],p=(o-u)/u*100;return t.precision(p)}}function N_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`rsi_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevPrevValue:null,prevAvgGain:0,prevAvgLoss:0,prevInitGains:[],prevInitLosses:[],currentPrevValue:null,currentAvgGain:0,currentAvgLoss:0,currentInitGains:[],currentInitLosses:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevPrevValue=a.currentPrevValue,a.prevAvgGain=a.currentAvgGain,a.prevAvgLoss=a.currentAvgLoss,a.prevInitGains=[...a.currentInitGains],a.prevInitLosses=[...a.currentInitLosses]),a.lastIdx=t.idx);let o=y.from(e).get(0);if(o==null||isNaN(o))return a.currentPrevValue=NaN,a.currentInitGains=[...a.prevInitGains],a.currentInitLosses=[...a.prevInitLosses],a.currentAvgGain=a.prevAvgGain,a.currentAvgLoss=a.prevAvgLoss,NaN;let l=a.prevPrevValue;if(l===null||isNaN(l))return a.currentPrevValue=o,a.currentInitGains=[...a.prevInitGains],a.currentInitLosses=[...a.prevInitLosses],a.currentAvgGain=a.prevAvgGain,a.currentAvgLoss=a.prevAvgLoss,NaN;let c=a.prevAvgGain,u=a.prevAvgLoss,p=[...a.prevInitGains],h=[...a.prevInitLosses],d=o-l,f=d>0?d:0,m=d<0?-d:0;if(p.length<i){if(p.push(f),h.push(m),a.currentInitGains=p,a.currentInitLosses=h,a.currentPrevValue=o,p.length===i){c=p.reduce((w,S)=>w+S,0)/i,u=h.reduce((w,S)=>w+S,0)/i,a.currentAvgGain=c,a.currentAvgLoss=u;let x=u===0?100:100-100/(1+c/u);return t.precision(x)}return NaN}c=(c*(i-1)+f)/i,u=(u*(i-1)+m)/i,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;let _=u===0?100:100-100/(1+c/u);return t.precision(_)}}function C_(t){return(e,n,r,i)=>{let s=y.from(e).get(0),a=y.from(n).get(0),o=y.from(r).get(0);t.taState||(t.taState={});let l=i||`sar_${s}_${a}_${o}`;t.taState[l]||(t.taState[l]={lastIdx:-1,prevResult:NaN,prevMaxMin:NaN,prevAcceleration:NaN,prevIsBelow:!1,prevBarIndex:0,currentResult:NaN,currentMaxMin:NaN,currentAcceleration:NaN,currentIsBelow:!1,currentBarIndex:0});let c=t.taState[l];t.idx>c.lastIdx&&(c.lastIdx>=0&&(c.prevResult=c.currentResult,c.prevMaxMin=c.currentMaxMin,c.prevAcceleration=c.currentAcceleration,c.prevIsBelow=c.currentIsBelow,c.prevBarIndex=c.currentBarIndex),c.lastIdx=t.idx);let u=c.prevResult,p=c.prevMaxMin,h=c.prevAcceleration,d=c.prevIsBelow,f=c.prevBarIndex,m=t.get(t.data.high,0),_=t.get(t.data.low,0),x=t.get(t.data.close,0),w=t.get(t.data.close,1),S=t.get(t.data.high,1),v=t.get(t.data.low,1),E=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(m)||isNaN(_)||isNaN(x))return c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,NaN;let I=!1;return f===1&&(x>w?(d=!0,p=m,u=v):(d=!1,p=_,u=S),I=!0,h=s),f>=1&&(u=u+h*(p-u),d?u>_&&(I=!0,d=!1,u=Math.max(m,p),p=_,h=s):u<m&&(I=!0,d=!0,u=Math.min(_,p),p=m,h=s),I||(d?m>p&&(p=m,h=Math.min(h+a,o)):_<p&&(p=_,h=Math.min(h+a,o))),d?(u=Math.min(u,v),f>1&&(u=Math.min(u,C))):(u=Math.max(u,S),f>1&&(u=Math.max(u,E)))),f++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function I_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e),a=Un(t,r||`sma_${i}`,o=>s.get(o),i);return a?t.precision(a.sum/i):NaN}}function k_(t){return(e,n,...r)=>{let i=typeof r[r.length-1]=="string"?r.pop():void 0,s=y.from(n).get(0),a=r.length===0||!!y.from(r[0]).get(0),o=y.from(e),l=Un(t,i||`stdev_${s}_${a}`,d=>o.get(d),s);if(!l)return NaN;let c=l.sum/s,u=0;for(let d of l.values)u+=Math.pow(d-c,2);let p=a?s:s-1,h=Math.sqrt(u/p);return t.precision(h)}}function A_(t){return(e,n,r,i,s)=>{let a=y.from(i).get(0);t.taState||(t.taState={});let o=s||`stoch_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],prevStoch:NaN,currentHighWindow:[],currentLowWindow:[],currentStoch:NaN});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevHighWindow=[...l.currentHighWindow],l.prevLowWindow=[...l.currentLowWindow],l.prevStoch=l.currentStoch),l.lastIdx=t.idx);let c=y.from(e).get(0),u=y.from(n).get(0),p=y.from(r).get(0),h=[...l.prevHighWindow],d=[...l.prevLowWindow];h.unshift(u),d.unshift(p),h.length>a&&(h.pop(),d.pop()),l.currentHighWindow=h,l.currentLowWindow=d;let f=S=>Number.isNaN(S)?(l.currentStoch=l.prevStoch,l.prevStoch):(l.currentStoch=S,t.precision(S));if(h.length<a)return f(NaN);let m=(S,v)=>{let E=NaN;for(let C=0;C<a;C++){let I=S[C];if(Number.isNaN(I))break;(Number.isNaN(E)||(v?I>E:I<E))&&(E=I)}return E},_=m(h,!0),x=m(d,!1),w=_-x;return w===0?c===x?f(NaN):(l.currentStoch=NaN,NaN):f(100*(c-x)/w)}}function M_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`supertrend_${y.from(e).get(0)}_${i}`;t.taState[s]||(t.taState[s]={factor:y.from(e).get(0),lastIdx:-1,prevTrSum:0,prevAtrValue:NaN,prevAtrCount:0,prevLowerBand:NaN,prevUpperBand:NaN,prevSuperTrend:NaN,prevDirection:NaN,currentTrSum:0,currentAtrValue:NaN,currentAtrCount:0,currentLowerBand:NaN,currentUpperBand:NaN,currentSuperTrend:NaN,currentDirection:NaN});let a=t.taState[s],o=a.factor;t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevTrSum=a.currentTrSum,a.prevAtrValue=a.currentAtrValue,a.prevAtrCount=a.currentAtrCount,a.prevLowerBand=a.currentLowerBand,a.prevUpperBand=a.currentUpperBand,a.prevSuperTrend=a.currentSuperTrend,a.prevDirection=a.currentDirection),a.lastIdx=t.idx);let l=t.get(t.data.high,0),c=t.get(t.data.low,0),u=t.get(t.data.close,0);if(isNaN(l)||isNaN(c)||isNaN(u))return[[NaN,NaN]];let p=(l+c)/2,h=t.idx>0?t.get(t.data.close,1):NaN,d;isNaN(h)?d=l-c:d=Math.max(l-c,Math.abs(l-h),Math.abs(c-h));let f=a.prevAtrCount,m=a.prevTrSum,_=a.prevAtrValue;f++,f<=i?(m+=d,f===i&&(_=m/i)):_=(_*(i-1)+d)/i;let x=_;if(a.currentAtrCount=f,a.currentTrSum=m,a.currentAtrValue=_,isNaN(x))return[[NaN,NaN]];let w=p+o*x,S=p-o*x,v=isNaN(a.prevLowerBand)?0:a.prevLowerBand,E=isNaN(a.prevUpperBand)?0:a.prevUpperBand;isNaN(a.prevLowerBand)||S>v||h<v||(S=v),isNaN(a.prevUpperBand)||w<E||h>E||(w=E);let C,I,F=a.prevSuperTrend;return f===i?C=1:F===a.prevUpperBand?C=u>w?-1:1:C=u<S?1:-1,I=C===-1?S:w,a.currentLowerBand=S,a.currentUpperBand=w,a.currentSuperTrend=I,a.currentDirection=C,[[t.precision(I),C]]}}function T_(t){return(e,n)=>{let r=[1,2,2,1],i=6;t.taState||(t.taState={});let s=n||"swma";t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],currentWindow:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=[...a.prevWindow];for(l.unshift(o);l.length>4;)l.pop();if(l.length<4&&t.idx>=3){let u=y.from(e);for(;l.length<4;)l.push(u.get(l.length))}if(a.currentWindow=l,l.length<4)return NaN;let c=0;for(let u=0;u<4;u++)c+=r[u]*l[3-u];return c/=i,t.precision(c)}}function P_(t){return(e,n)=>{let r=!0;typeof e=="string"||e!==void 0&&(r=y.from(e).get(0));let i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.close,1);if(isNaN(a))return r?t.precision(i-s):NaN;let o=Math.max(i-s,Math.abs(i-a),Math.abs(s-a));return t.precision(o)}}function D_(t){return(e,n,r,i)=>{let s=y.from(n).get(0),a=y.from(r).get(0);t.taState||(t.taState={});let o=i||`tsi_${s}_${a}`;t.taState[o]||(t.taState[o]={lastIdx:-1,prevSource:NaN,prevEma1PcValue:NaN,prevEma1PcCount:0,prevEma1PcSum:0,prevEma2PcValue:NaN,prevEma2PcCount:0,prevEma2PcSum:0,prevEma1AbsValue:NaN,prevEma1AbsCount:0,prevEma1AbsSum:0,prevEma2AbsValue:NaN,prevEma2AbsCount:0,prevEma2AbsSum:0,currentSource:NaN,currentEma1PcValue:NaN,currentEma1PcCount:0,currentEma1PcSum:0,currentEma2PcValue:NaN,currentEma2PcCount:0,currentEma2PcSum:0,currentEma1AbsValue:NaN,currentEma1AbsCount:0,currentEma1AbsSum:0,currentEma2AbsValue:NaN,currentEma2AbsCount:0,currentEma2AbsSum:0});let l=t.taState[o];t.idx>l.lastIdx&&(l.lastIdx>=0&&(l.prevSource=l.currentSource,l.prevEma1PcValue=l.currentEma1PcValue,l.prevEma1PcCount=l.currentEma1PcCount,l.prevEma1PcSum=l.currentEma1PcSum,l.prevEma2PcValue=l.currentEma2PcValue,l.prevEma2PcCount=l.currentEma2PcCount,l.prevEma2PcSum=l.currentEma2PcSum,l.prevEma1AbsValue=l.currentEma1AbsValue,l.prevEma1AbsCount=l.currentEma1AbsCount,l.prevEma1AbsSum=l.currentEma1AbsSum,l.prevEma2AbsValue=l.currentEma2AbsValue,l.prevEma2AbsCount=l.currentEma2AbsCount,l.prevEma2AbsSum=l.currentEma2AbsSum),l.lastIdx=t.idx);let c=y.from(e).get(0);if(isNaN(c))return l.currentSource=NaN,NaN;let u=isNaN(l.prevSource)?NaN:c-l.prevSource;if(l.currentSource=c,isNaN(u))return NaN;let p=Math.abs(u),h=2/(a+1),d=2/(s+1),f=2/(a+1),m=2/(s+1),_=l.prevEma1PcCount,x=l.prevEma1PcSum,w=l.prevEma1PcValue;_++,_<=a?(x+=u,_===a&&(w=x/a)):w=u*h+w*(1-h);let S=l.prevEma1AbsCount,v=l.prevEma1AbsSum,E=l.prevEma1AbsValue;if(S++,S<=a?(v+=p,S===a&&(E=v/a)):E=p*f+E*(1-f),isNaN(w)||isNaN(E))return l.currentEma1PcCount=_,l.currentEma1PcSum=x,l.currentEma1PcValue=w,l.currentEma1AbsCount=S,l.currentEma1AbsSum=v,l.currentEma1AbsValue=E,NaN;let C=l.prevEma2PcCount,I=l.prevEma2PcSum,F=l.prevEma2PcValue;C++,C<=s?(I+=w,C===s&&(F=I/s)):F=w*d+F*(1-d);let $=l.prevEma2AbsCount,j=l.prevEma2AbsSum,A=l.prevEma2AbsValue;if($++,$<=s?(j+=E,$===s&&(A=j/s)):A=E*m+A*(1-m),l.currentEma1PcCount=_,l.currentEma1PcSum=x,l.currentEma1PcValue=w,l.currentEma1AbsCount=S,l.currentEma1AbsSum=v,l.currentEma1AbsValue=E,l.currentEma2PcCount=C,l.currentEma2PcSum=I,l.currentEma2PcValue=F,l.currentEma2AbsCount=$,l.currentEma2AbsSum=j,l.currentEma2AbsValue=A,isNaN(F)||isNaN(A))return NaN;if(A===0)return t.precision(0);let ue=F/A;return t.precision(ue)}}function O_(t){return(e,n,r,i)=>{t.taState||(t.taState={});let s=i||"valuewhen";t.taState[s]||(t.taState[s]={lastIdx:-1,prevValues:[],currentValues:[]});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevValues=[...a.currentValues]),a.lastIdx=t.idx);let o=y.from(e).get(0),l=y.from(n).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;let p=u.length-1-c;if(p<0)return NaN;let h=u[p];return typeof h=="number"?t.precision(h):h}}function R_(t){return(e,n,...r)=>{let i=typeof r[r.length-1]=="string"?r.pop():void 0,s=y.from(n).get(0),a=r.length===0||!!y.from(r[0]).get(0),o=y.from(e),l=Un(t,i||`variance_${s}_${a}`,f=>o.get(f),s);if(!l)return NaN;let c=0,u=0;for(let f of l.values)c+=f,u+=f*f;let p=c/s,h=u/s-p*p,d=a?h:h*s/(s-1);return t.precision(d)}}function L_(t){return(...e)=>{let n=typeof e[e.length-1]=="string"?e.pop():void 0,r=e.length>0?e[0]:t.data.hlc3,i=e.length>=2,s=e.length>=3;t.taState||(t.taState={});let a=n||`vwap_${e.length}`;t.taState[a]||(t.taState[a]={lastIdx:-1,prevCumulativePV:0,prevCumulativeVolume:0,prevCumulativePPV:0,prevStarted:!1,prevLastSessionDate:null,currentCumulativePV:0,currentCumulativeVolume:0,currentCumulativePPV:0,currentStarted:!1,currentLastSessionDate:null});let o=t.taState[a];t.idx>o.lastIdx&&(o.lastIdx>=0&&(o.prevCumulativePV=o.currentCumulativePV,o.prevCumulativeVolume=o.currentCumulativeVolume,o.prevCumulativePPV=o.currentCumulativePPV,o.prevStarted=o.currentStarted,o.prevLastSessionDate=o.currentLastSessionDate),o.lastIdx=t.idx);let l=y.from(r).get(0),c=y.from(t.data.volume).get(0),u=o.prevCumulativePV,p=o.prevCumulativeVolume,h=o.prevCumulativePPV,d=o.prevStarted,f=o.prevLastSessionDate,m;if(i)m=!!y.from(e[1]).get(0);else{let v=y.from(t.data.openTime).get(0),E=t.pine?.syminfo?.timezone||"UTC",C=Dn(v,E),I=`${C.year}-${String(C.month).padStart(2,"0")}-${String(C.day).padStart(2,"0")}`;m=f!==I,f=I}m&&(u=0,p=0,h=0,d=!0),d&&(u+=l*c,p+=c,h+=l*l*c),o.currentCumulativePV=u,o.currentCumulativeVolume=p,o.currentCumulativePPV=h,o.currentStarted=d,o.currentLastSessionDate=f;let _=d&&p!==0?u/p:NaN;if(!s)return isNaN(_)?NaN:t.precision(_);let x=y.from(e[2]).get(0),w=h/p-_*_,S=Math.sqrt(Math.max(w,0));return[[t.precision(_),t.precision(_+x*S),t.precision(_-x*S)]]}}function F_(t){return(e,n,r)=>{let i=y.from(n).get(0),s=y.from(e),a=y.from(t.data.volume),o=r||`vwma_${i}`,l=Un(t,`${o}_sv`,h=>s.get(h)*a.get(h),i),c=Un(t,`${o}_v`,h=>a.get(h),i);if(!l||!c)return NaN;let u=0,p=0;for(let h=0;h<i;h++)u+=l.values[h],p+=c.values[h];return t.precision(u/p)}}function V_(t){return e=>{t.taState||(t.taState={});let n=e||"wad";t.taState[n]||(t.taState[n]={lastIdx:-1,prevCumulativeSum:0,currentCumulativeSum:0});let r=t.taState[n];t.idx>r.lastIdx&&(r.lastIdx>=0&&(r.prevCumulativeSum=r.currentCumulativeSum),r.lastIdx=t.idx);let i=t.get(t.data.close,0),s=t.get(t.data.high,0),a=t.get(t.data.low,0),o=t.get(t.data.close,1);if(isNaN(i)||isNaN(s)||isNaN(a))return r.currentCumulativeSum=r.prevCumulativeSum,t.precision(r.prevCumulativeSum);let l=0;if(!isNaN(o)){let u=Math.max(s,o),p=Math.min(a,o),h=i-o;h>0?l=i-p:h<0&&(l=i-u)}let c=r.prevCumulativeSum+l;return r.currentCumulativeSum=c,t.precision(c)}}function B_(t){return(e,n,r)=>{let i=y.from(n).get(0);t.taState||(t.taState={});let s=r||`wma_${i}`;t.taState[s]||(t.taState[s]={lastIdx:-1,prevWindow:[],prevCallCount:0,currentWindow:[],currentCallCount:0});let a=t.taState[s];t.idx>a.lastIdx&&(a.lastIdx>=0&&(a.prevWindow=[...a.currentWindow],a.prevCallCount=a.currentCallCount),a.lastIdx=t.idx);let o=y.from(e).get(0),l=o==null||Number.isNaN(o),c=[...a.prevWindow];for(c.unshift(l?c.length?c[0]:NaN:o);c.length>i;)c.pop();let u=a.prevCallCount+1;if(c.length<i&&(u>=i||t.idx>=i-1)){let f=y.from(e);for(;c.length<i;)c.push(f.get(c.length));for(let m=c.length-2;m>=0;m--)Number.isNaN(c[m])&&(c[m]=c[m+1])}if(a.currentWindow=c,a.currentCallCount=u,c.length<i||l||c.some(f=>Number.isNaN(f)))return NaN;let p=0,h=0;for(let f=0;f<i;f++){let m=i-f;p+=c[f]*m,h+=m}let d=p/h;return t.precision(d)}}function $_(t){return(e,n)=>{let r=y.from(e).get(0);t.taState||(t.taState={});let i=n||`wpr_${r}`;t.taState[i]||(t.taState[i]={lastIdx:-1,prevHighWindow:[],prevLowWindow:[],currentHighWindow:[],currentLowWindow:[]});let s=t.taState[i];t.idx>s.lastIdx&&(s.lastIdx>=0&&(s.prevHighWindow=[...s.currentHighWindow],s.prevLowWindow=[...s.currentLowWindow]),s.lastIdx=t.idx);let a=t.get(t.data.high,0),o=t.get(t.data.low,0),l=t.get(t.data.close,0);if(isNaN(a)||isNaN(o)||isNaN(l))return s.currentHighWindow=[...s.prevHighWindow],s.currentLowWindow=[...s.prevLowWindow],NaN;let c=[...s.prevHighWindow],u=[...s.prevLowWindow];if(c.unshift(a),u.unshift(o),c.length>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]);let d=p-h;if(d===0)return t.precision(0);let f=(p-l)/d*-100;return t.precision(f)}}function j_(t){return e=>{let n=t.get(t.data.close,0),r=t.get(t.data.open,0),i=t.get(t.data.high,0),s=t.get(t.data.low,0),a=t.get(t.data.volume,0);if(isNaN(n)||isNaN(r)||isNaN(i)||isNaN(s)||isNaN(a))return NaN;let o=i-s;if(o===0)return t.precision(0);let l=(n-r)/o*a;return t.precision(l)}}var W_=Object.defineProperty,U_=(t,e,n)=>e in t?W_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,U=(t,e,n)=>U_(t,typeof e!="symbol"?e+"":e,n),q_={accdist:N0,alma:C0,atr:I0,barssince:k0,bb:A0,bbw:M0,cci:T0,change:P0,cmo:D0,cog:O0,correlation:R0,cross:L0,crossover:F0,crossunder:V0,cum:B0,dev:$0,dmi:j0,ema:W0,falling:U0,highest:q0,highestbars:z0,hma:H0,iii:K0,kc:G0,kcw:Y0,linreg:X0,lowest:Z0,lowestbars:Q0,macd:J0,max:e_,median:t_,mfi:n_,min:r_,mode:i_,mom:s_,nvi:a_,obv:o_,param:l_,percentile_linear_interpolation:c_,percentile_nearest_rank:u_,percentrank:h_,pivothigh:d_,pivotlow:m_,pivot_point_levels:g_,pvi:__,pvt:x_,range:b_,rci:v_,rising:w_,rma:S_,roc:E_,rsi:N_,sar:C_,sma:I_,stdev:k_,stoch:A_,supertrend:M_,swma:T_,tr:P_,tsi:D_,valuewhen:O_,variance:R_,vwap:L_,vwma:F_,wad:V_,wma:B_,wpr:$_,wvad:j_},xa=class{constructor(e){this.context=e,U(this,"accdist"),U(this,"alma"),U(this,"atr"),U(this,"barssince"),U(this,"bb"),U(this,"bbw"),U(this,"cci"),U(this,"change"),U(this,"cmo"),U(this,"cog"),U(this,"correlation"),U(this,"cross"),U(this,"crossover"),U(this,"crossunder"),U(this,"cum"),U(this,"dev"),U(this,"dmi"),U(this,"ema"),U(this,"falling"),U(this,"highest"),U(this,"highestbars"),U(this,"hma"),U(this,"iii"),U(this,"kc"),U(this,"kcw"),U(this,"linreg"),U(this,"lowest"),U(this,"lowestbars"),U(this,"macd"),U(this,"max"),U(this,"median"),U(this,"mfi"),U(this,"min"),U(this,"mode"),U(this,"mom"),U(this,"nvi"),U(this,"obv"),U(this,"param"),U(this,"percentile_linear_interpolation"),U(this,"percentile_nearest_rank"),U(this,"percentrank"),U(this,"pivothigh"),U(this,"pivotlow"),U(this,"pivot_point_levels"),U(this,"pvi"),U(this,"pvt"),U(this,"range"),U(this,"rci"),U(this,"rising"),U(this,"rma"),U(this,"roc"),U(this,"rsi"),U(this,"sar"),U(this,"sma"),U(this,"stdev"),U(this,"stoch"),U(this,"supertrend"),U(this,"swma"),U(this,"tr"),U(this,"tsi"),U(this,"valuewhen"),U(this,"variance"),U(this,"vwap"),U(this,"vwma"),U(this,"wad"),U(this,"wma"),U(this,"wpr"),U(this,"wvad"),Object.entries(q_).forEach(([n,r])=>{this[n]=r(e)})}};function z_(t){if(t.length===0)return{};if(typeof t[0]=="object"&&t[0]!==null)return t[0];let e={};typeof t[0]=="string"&&(e.title=t[0]);let n=null;for(let r=1;r<t.length;r++){let i=t[r];typeof i=="string"?e.shorttitle===void 0&&(e.shorttitle=i):typeof i=="object"&&i!==null&&(n=i)}return n&&Object.assign(e,n),e}function Hr(t,e,n){if(!n||n<=0||!Number.isFinite(t)||t===e)return t;let r=t/n,i=1e-9;return t>e?Math.ceil(r-i)*n:Math.floor(r+i)*n}function qi(t,e,n,r){return Math.abs(t)*e*r*n/100}function H_(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of ds(n)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*r}return n.initial_capital+n.netprofit+i}function K_(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of n.opentrades){let a=Math.sign(s.size)===1?n.config.margin_long??100:n.config.margin_short??100;i+=qi(s.size,e,a,r)}return i}function $o(t,e,n,r){let i=t.strategy,s=i.config.default_qty_type||"fixed",a=i.config.default_qty_value||1;if(typeof s=="function"&&(s=s()),typeof a=="function"&&(a=a()),e!=null&&!Number.isNaN(e))return ba(t,Math.abs(e));let o;switch(s){case"fixed":o=a;break;case"cash":o=a/r;break;case"percent_of_equity":{o=i.equity*a/100/r;break}default:o=a}return ba(t,o)}function vu(t,e,n){let r=i=>typeof i=="number"&&Number.isFinite(i);return r(t)?t:r(e)?e:n}function wu(t){let e=Number(t.strategy?.config?.backtest_fill_limits_assumption??0);return!Number.isFinite(e)||e<=0?0:e*(t.pine?.syminfo?.mintick??.01)}function Su(t){let e=t.pine?.syminfo?.mincontract;return typeof e=="number"&&e>0?e:1e-6}function ba(t,e){if(!Number.isFinite(e)||e<=0)return 0;let n=Su(t),r=Math.floor(e/n*(1+1e-10)),i=Math.min(10,Math.max(0,Math.ceil(-Math.log10(n))));return Number((r*n).toFixed(i))}function va(t,e,n){let r=Su(t);return Math.min(e,Math.max(r,ba(t,e*n/100)))}function G_(t){if(!t.strategy)return;let e=t.strategy,{pending_orders:n}=e,r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.pointvalue??1;for(let u of e.opentrades){let p=Math.abs(u.size),h=u.size>0,d=u.commission??0,f=h?(u.entry_price-s)*p*l:(i-u.entry_price)*p*l,m=h?(i-u.entry_price)*p*l:(u.entry_price-s)*p*l,_=Math.max(0,f)+d,x=Math.max(0,m-d);_>(u.max_drawdown??0)&&(u.max_drawdown=_),x>(u.max_runup??0)&&(u.max_runup=x)}Er(t,r);let c=wu(t);for(let u of n){if(u.status!=="pending"||(u.category??"entry")==="exit"||u.bar>=t.idx)continue;let p=!1,h=r;switch(u.type){case"market":p=!0,h=r;break;case"limit":if(u.limit!==void 0){let d=mn(u.direction);(d===1&&s<=u.limit-c||d===-1&&i>=u.limit+c)&&(p=!0,h=u.limit)}break;case"stop":if(u.stop!==void 0){let d=mn(u.direction);(d===1&&i>=u.stop||d===-1&&s<=u.stop)&&(p=!0,h=u.stop)}break;case"stop-limit":if(u.stop!==void 0&&u.limit!==void 0){let d=mn(u.direction),f;u._stopTriggered?f=r:(d===1?i>=u.stop:s<=u.stop)&&(u._stopTriggered=!0,f=d===1?Math.max(r,u.stop):Math.min(r,u.stop)),f!==void 0&&((d===1?f<=u.limit:f>=u.limit)?(p=!0,h=f):(d===1?s<=u.limit-c:i>=u.limit+c)&&(p=!0,h=u.limit))}break}p&&Eu(t,u,h,o,r)}e.pending_orders=n.filter(u=>u.status==="pending"),Er(t,a),Iu(t)}function Eu(t,e,n,r,i){let s=t.strategy;if(Z_(s,e)){e.status="cancelled";return}let a=mn(e.direction);(e.type==="market"||e.type==="stop")&&(n=zi(t,a,n));let o=a===1?s.config.margin_long??100:s.config.margin_short??100;{let l=s.position_size,c=Math.sign(l),u=c!==0&&c!==a,p=u?Math.max(0,e.qty-Math.abs(l)):e.qty;if(p>0){let h=t.pine?.syminfo?.pointvalue??1,d=0;c===a&&(d=K_(t,i));let f=s.equity-d;if(qi(p,n,o,h)>f){let m=Math.min(Math.abs(l),e.qty);u&&m>0?($n(t,m,n,r,{exitId:e.id,exitComment:e.comment}),e.status="filled",e.fill_price=n,e.fill_bar=t.idx,e.fill_time=r):e.status="cancelled";return}}}J_(t,e,n,r),e.status="filled",e.fill_price=n,e.fill_bar=t.idx,e.fill_time=r}function Y_(t){let e=t.strategy;if(!e||e.pending_orders.length===0)return;let n=e.config.process_orders_on_close===!0,r=y.from(t.data.close).get(0),i=y.from(t.data.openTime).get(0),s=a=>a.category==="exit"&&a.type==="market"&&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;for(let a of e.pending_orders)if(!(a.status!=="pending"||a.bar!==t.idx))if(s(a)){if(!n&&!a.immediately)continue;let o=e.opentrades.filter(p=>!a.from_entry||p.entry_id===a.from_entry);if(a._intended_trade_ids){let p=new Set(a._intended_trade_ids);o=o.filter(h=>p.has(h.id))}if(o.length===0){a.status="cancelled";continue}let l=o.reduce((p,h)=>p+Math.abs(h.size),0),c=l;a.qty&&a.qty>0?c=Math.min(a.qty,l):a.qty_percent&&a.qty_percent>0&&(c=va(t,l,a.qty_percent));let u=zi(t,-Math.sign(o[0].size),r);wa(t,a.from_entry,c,u,i,{exitId:a.id,exitComment:a.comment}),a.status="filled",a.fill_price=u,a.fill_bar=t.idx,a.fill_time=i}else n&&(a.category??"entry")==="entry"&&a.type==="market"&&(Er(t,r),Eu(t,a,r,i,r));e.pending_orders=e.pending_orders.filter(a=>a.status==="pending"),Er(t,r),Iu(t)}function mn(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function Nu(t,e,n,r){let i=e.config.commission_type??"percent",s=e.config.commission_value??0;if(!s||s===0)return 0;let a=t.pine?.syminfo?.pointvalue??1;switch(i){case"percent":return Math.abs(n)*r*a*(s/100);case"cash_per_contract":return Math.abs(n)*s;case"cash_per_order":return s;default:return 0}}function zi(t,e,n){let r=t.strategy.config.slippage??0;if(!r||r===0)return n;let i=t.pine?.syminfo?.mintick??.01,s=r*i;return e===1?n+s:n-s}function Cu(t){let e=Math.abs(t.position_size);e>t.max_contracts_held_all&&(t.max_contracts_held_all=e),t.position_size>t.max_contracts_held_long&&(t.max_contracts_held_long=t.position_size),-t.position_size>t.max_contracts_held_short&&(t.max_contracts_held_short=-t.position_size)}function X_(t,e){let n=t.config.pyramiding??1,r=0;for(let i of t.opentrades)Math.sign(i.size)===e&&r++;return r>=n}function Z_(t,e){if(t.risk_halted)return!0;let n=t.risk_rules,r=e.direction;if(n.allow_entry_in&&(n.allow_entry_in==="long"&&r===-1||n.allow_entry_in==="short"&&r===1))return!0;if(n.max_position_size!==void 0){let i=t.position_size+r*e.qty;if(Math.abs(i)>n.max_position_size)return!0}return!1}function Q_(t){if(t.risk_halted)return;let e=t.risk_rules;if(e.max_drawdown){let n=e.max_drawdown.type==="percent_of_equity"?e.max_drawdown.value/100*t.equity_peak:e.max_drawdown.value;if(t.max_drawdown>=n){t.risk_halted=!0;return}}if(e.max_intraday_loss){let n=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>=n){t.risk_halted=!0;return}}if(e.max_cons_loss_days){let n=0;for(let r=t.closedtrades.length-1;r>=0&&(t.closedtrades[r].profit??0)<0;r--)n++;n>=e.max_cons_loss_days.count&&(t.risk_halted=!0)}}function vi(t,e,n,r,i,s,a,o){let l=t.strategy,c=l.opentrades.length+l.closedtrades.length,u=l.config.commission_type??"percent",p=o&&u==="cash_per_order",h=Nu(t,l,r,i),d=p?h/2:h,f={id:`trade_${c}`,entry_id:e,entry_comment:a??e,entry_price:i,_bracket_entry:i,entry_bar_index:t.idx,entry_time:s,size:n*r,commission:d,max_drawdown:0,max_runup:0,status:"open"};f._entry_qty=Math.abs(f.size),l.opentrades.push(f),l._first_entry_price===void 0&&(l._first_entry_price=i),(l._ledger_entries??(l._ledger_entries=[])).push({entry_id:e,entry_price:i,entry_time:s,entry_bar_index:t.idx,entry_comment:f.entry_comment,qty:r,commission:d}),d>0&&(l.netprofit-=d,l.grossloss+=d);let m=y.from(t.data.high).get(0),_=y.from(t.data.low).get(0),x=t.pine?.syminfo?.mintick??.01,w=n===1?_:m,S=n===1?m:_;for(let $ of l.pending_orders){if(($.category??"entry")!=="exit"||$.from_entry&&$.from_entry!==e)continue;let j;$.stop!==void 0?j=$.stop:$.loss!==void 0&&(j=n===1?i-$.loss*x:i+$.loss*x);let A;$.limit!==void 0?A=$.limit:$.profit!==void 0&&(A=n===1?i+$.profit*x:i-$.profit*x),n===1?(j!==void 0&&j>w&&(w=j),A!==void 0&&A<S&&(S=A)):(j!==void 0&&j<w&&(w=j),A!==void 0&&A>S&&(S=A))}let v=t.pine?.syminfo?.pointvalue??1,E=n===1?(i-w)*r*v:(w-i)*r*v,C=n===1?(S-i)*r*v:(i-S)*r*v;f.max_drawdown=Math.max(0,E)+d,f.max_runup=Math.max(0,C-d);let I=l.position_size,F=I+f.size;if(I===0)l.position_size=F,l.position_avg_price=i,l.position_entry_name=e;else if(Math.sign(I)===Math.sign(F)){let $=Math.abs(I)*l.position_avg_price+r*i,j=Math.abs(F);l.position_avg_price=$/j,l.position_size=F}Cu(l)}function J_(t,e,n,r){let i=t.strategy,s=mn(e.direction),a=i.position_size,o=Math.sign(a);if(o===1&&s===-1||o===-1&&s===1){let l=Math.min(Math.abs(a),e.qty),c=e.qty-l,u=c>0;if($n(t,l,n,r,{exitId:e.id,exitComment:e.comment,isImplicitReversal:u}),c>0){let p=e._base_qty;p!==void 0&&c>p+1e-9?(vi(t,e.id,s,p,n,r,e.comment,!0),vi(t,e.id,s,c-p,n,r,e.comment,!0)):vi(t,e.id,s,c,n,r,e.comment,!0)}}else vi(t,e.id,s,e.qty,n,r,e.comment)}function ex(t,e,n){let r=[],i=n,s=t._ledger_entries??[];for(let a of s){if(i<=1e-9)break;if(a.entry_id!==e.entry_id||a.qty<=1e-9)continue;let o=Math.min(a.qty,i),l=a.qty>0?a.commission*(o/a.qty):0;r.push({qty:o,entry_price:a.entry_price,entry_time:a.entry_time,entry_bar_index:a.entry_bar_index,entry_comment:a.entry_comment,commission:l}),a.qty-=o,a.commission-=l,i-=o}if(t._ledger_entries=s.filter(a=>a.qty>1e-9),i>1e-9){let a=Math.abs(e.size);r.push({qty:i,entry_price:e.entry_price,entry_time:e.entry_time,entry_bar_index:e.entry_bar_index,entry_comment:e.entry_comment,commission:a>0?(e.commission??0)*(i/a):0})}return r}function $n(t,e,n,r,i){let s=t.strategy,a=t.pine?.syminfo?.pointvalue??1,o=e,l=[...s.opentrades];s.opentrades=[];for(let h of l){if(o<=0){s.opentrades.push(h);continue}let d=Math.abs(h.size),f=Math.min(d,o),m=Math.sign(h.size),_=x=>{let w=s.config.commission_type??"percent",S=i?.isImplicitReversal&&w==="cash_per_order",v=Nu(t,s,x,n),E=S?v/2:v,C=ex(s,h,x);for(let I of C){let F=E*(I.qty/x),$=(m===1?n-I.entry_price:I.entry_price-n)*I.qty*a,j={id:`trade_${s.opentrades.length+s.closedtrades.length+l.length}`,entry_id:h.entry_id,entry_comment:I.entry_comment,entry_price:I.entry_price,_bracket_entry:h._bracket_entry,entry_bar_index:I.entry_bar_index,entry_time:I.entry_time,size:m*I.qty,commission:I.commission+F,max_drawdown:h.max_drawdown,max_runup:h.max_runup,status:"closed",exit_price:n,exit_bar_index:t.idx,exit_time:r,exit_id:i?.exitId??h.exit_id,exit_comment:i?.exitComment??h.exit_comment,profit:$-I.commission-F};i?.triggerKind==="loss"&&(j.max_runup=0),i?.triggerKind==="profit"&&(j.max_drawdown=I.commission),s.netprofit+=$-F,s.grossloss-=I.commission,j.profit>0?(s.grossprofit+=j.profit,s.wintrades++,s.wintrades_total_profit+=j.profit):j.profit<0?(s.grossloss+=Math.abs(j.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(j.profit)):s.eventrades++,s.closedtrades.push(j)}};if(f>=d-1e-9)h.status="closed",h.exit_price=n,h.exit_bar_index=t.idx,h.exit_time=r,_(d),o-=f;else{_(f);let x=(h.commission??0)*(f/d);h.size=m*(d-f),h.commission=(h.commission??0)-x,s.opentrades.push(h),o=0}}Q_(s);let c=s.position_size,u=Math.sign(c)*e,p=c-u;if(Math.abs(p)<1e-9&&(p=0),s.position_size=p,Cu(s),p===0)s.position_avg_price=NaN,s.position_entry_name="";else if(s.opentrades.length>0){let h=0,d=0;for(let f of ds(s))h+=f.qty*f.entry_price,d+=f.qty;s.position_avg_price=h/d,s.position_entry_name=s.opentrades[0].entry_id}}function ds(t){let e=t._ledger_entries??[],n=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:n})):t.opentrades.map(r=>({qty:Math.abs(r.size),entry_price:r.entry_price,commission:r.commission??0,dir:Math.sign(r.size)}))}function Er(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of ds(n)){let a=s.dir===1?e-s.entry_price:s.entry_price-e;i+=a*s.qty*r}n.openprofit=i,n.equity=n.initial_capital+n.netprofit+i}function tx(t,e,n){let r=t.strategy,i=t.pine?.syminfo?.pointvalue??1,s=r.initial_capital+r.netprofit,a=0;for(let f of ds(r))a+=f.commission;let o=s+a;o>r.equity_peak&&(r.equity_peak=o),s<r.equity_trough&&(r.equity_trough=s);let l=r.position_size,c=r.position_avg_price,u=0,p=0;if(l!==0&&Number.isFinite(c)){let f=l>0?n:e,m=l>0?e:n;u=l*(c-f)*i,p=l*(m-c)*i}let 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)){let f=100*h/r.equity_peak;f>r.max_drawdown_percent_value&&(r.max_drawdown_percent_value=f)}let d=s-r.equity_trough+p;if(d>r.max_runup&&(r.max_runup=d,r.equity_at_runup_peak=s+p,r.equity_at_runup_peak>0)){let f=100*d/r.equity_at_runup_peak;f>r.max_runup_percent_value&&(r.max_runup_percent_value=f)}}function wa(t,e,n,r,i,s,a){let o=t.strategy;if(a!==void 0){let h=[],d=[];for(let m of o.opentrades)m.id===a?h.push(m):d.push(m);if(h.length===0)return;let f=Math.abs(h[0].size);o.opentrades=[...h,...d],$n(t,Math.min(n,f),r,i,s);return}if(!e||e===""){$n(t,n,r,i,s);return}let l=[],c=[];for(let h of o.opentrades)h.entry_id===e?l.push(h):c.push(h);let u=l.reduce((h,d)=>h+Math.abs(d.size),0);if(u===0)return;let p=Math.min(n,u);o.opentrades=[...l,...c],$n(t,p,r,i,s)}function nx(t,e="intrabar"){if(!t.strategy)return;let n=t.strategy;if(n.pending_orders.length===0)return;let r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=y.from(t.data.close).get(0),o=y.from(t.data.openTime).get(0),l=t.pine?.syminfo?.mintick??.01,c=wu(t);for(let u of n.pending_orders){if(u.status!=="pending"||(u.category??"entry")!=="exit")continue;let p=n.opentrades.filter(D=>!u.from_entry||D.entry_id===u.from_entry);if(u._intended_trade_ids){let D=new Set(u._intended_trade_ids);p=p.filter(M=>D.has(M.id))}if(p.length===0){e==="intrabar"&&(u.status="cancelled");continue}let h=p.reduce((D,M)=>D+Math.abs(M.size),0),d=Math.sign(p[0].size);if(u.type==="market"&&u.profit===void 0&&u.loss===void 0&&u.limit===void 0&&u.stop===void 0&&u.trail_price===void 0&&u.trail_points===void 0){if(e==="open"||u.bar>=t.idx)continue;let D=u.immediately?a:r;D=zi(t,-d,D);let M=h;u.qty&&u.qty>0?M=Math.min(u.qty,h):u.qty_percent&&u.qty_percent>0&&(M=va(t,h,u.qty_percent)),wa(t,u.from_entry,M,D,o,{exitId:u.id,exitComment:u.comment}),u.status="filled",u.fill_price=D,u.fill_bar=t.idx,u.fill_time=o;continue}if(p=p.filter(D=>!D._exits_filled?.has(u.id)),p.length===0){e==="intrabar"&&(u.status="cancelled");continue}h=p.reduce((D,M)=>D+Math.abs(M.size),0);let f=new Map(p.map(D=>[D,Math.abs(D.size)])),m=0;for(let D of p)m+=Math.abs(D.size)*D.entry_price;let _=m/h,x=d===1,w=u.limit,S=u.stop;!u._isPersistent&&!u._coversOpenTrade&&(S!==void 0&&((x?S<_:S>_)||(S=void 0)),w!==void 0&&((x?w>_:w<_)||(w=void 0))),u._attachedAtReversal&&!u._isPersistent&&(u.limit!==void 0&&(w=void 0),u.stop!==void 0&&(S=void 0));let v=!1;if(e==="intrabar"&&!u.trail_armed&&(u.trail_price!==void 0||u.trail_points!==void 0)){let D;u.trail_price!==void 0?D=u.trail_price:u.trail_points!==void 0&&(D=x?_+u.trail_points*l:_-u.trail_points*l),D!==void 0&&(x?i>=D:s<=D)&&(u.trail_armed=!0,u.trail_peak=x?i:s,v=!0)}let E=Math.abs(i-r)<=Math.abs(r-s),C=x?E:!E,I=[],F=[],$=n._mc_exit_lock,j=$&&$.bar===t.idx;for(let D of p){if(j&&D.id!==$.tradeId)continue;let M=D._bracket_entry??D.entry_price,W=Math.abs(D.size),k=w;k===void 0&&u.profit!==void 0&&(k=x?M+u.profit*l:M-u.profit*l);let V=S;V===void 0&&u.loss!==void 0&&(V=x?M-u.loss*l:M+u.loss*l);let Q=k!==void 0&&(e==="open"?x?r>=k:r<=k:x?i>=k+c:s<=k-c),De=V!==void 0&&(e==="open"?x?r<=V:r>=V:x?s<=V:i>=V),Te=null;if(Q&&De?Te=C?"profit":"loss":Q?Te="profit":De&&(Te="loss"),Te==="loss"){let st=x?r<=V:r>=V;!x&&st&&D.entry_bar_index===t.idx?Q&&(Te="profit"):F.push({qty:W,price:st?r:V,kind:"loss",tradeId:D.id})}if(Te==="profit"){let st=x?r>=k+c:r<=k-c;I.push({qty:W,price:st?r:k,kind:"profit",tradeId:D.id})}}I.sort((D,M)=>x?D.price-M.price:M.price-D.price),F.sort((D,M)=>x?M.price-D.price:D.price-M.price);let A=null;if(e==="intrabar"&&!j&&u.trail_armed&&u.trail_offset!==void 0){let D=()=>{x?u.trail_peak=Math.max(u.trail_peak??-1/0,i):u.trail_peak=Math.min(u.trail_peak??1/0,s)},M=()=>x?u.trail_peak-u.trail_offset*l:u.trail_peak+u.trail_offset*l,W=k=>{A={qty:1/0,price:k,kind:"trailing"}};if(v){let k=M();C?(x?s<=k:i>=k)&&W(k):(x?a<=k:a>=k)&&W(k)}else if(C){D();let k=M();(x?s<=k:i>=k)&&W(k)}else{let k=M();if(x?s<=k:i>=k)W(k);else{D();let V=M();(x?a<=V:a>=V)&&W(V)}}}let ue=C?[...I,...F,...A?[A]:[]]:[...F,...A?[A]:[],...I];if(ue.length>0){let D=h;if(u.qty&&u.qty>0)D=Math.min(u.qty,h);else if(u.qty_percent&&u.qty_percent>0){let V=p.reduce((Q,De)=>Q+(De._entry_qty??Math.abs(De.size)),0);D=Math.min(h,va(t,V,u.qty_percent))}let M=()=>n.opentrades.filter(V=>!u.from_entry||V.entry_id===u.from_entry).reduce((V,Q)=>V+Math.abs(Q.size),0),W=NaN,k=!1;for(let V of ue){if(D<=1e-9)break;let Q=M();if(Q<=1e-9)break;let De=Math.min(V.qty===1/0?Q:V.qty,D,Q),Te=V.kind==="profit"?V.price:zi(t,-d,V.price),st=V.kind==="profit"?u.comment_profit??u.comment:V.kind==="loss"?u.comment_loss??u.comment:u.comment_trailing??u.comment;wa(t,u.from_entry,De,Te,o,{triggerKind:V.kind,exitId:u.id,exitComment:st},V.tradeId),D-=De,W=Te,k=!0}k&&(M()<=1e-9||D<=1e-9)&&(u.status="filled",u.fill_price=W,u.fill_bar=t.idx,u.fill_time=o);for(let[V,Q]of f)Math.abs(V.size)<Q&&(V._exits_filled??(V._exits_filled=new Set)).add(u.id)}}n.pending_orders=n.pending_orders.filter(u=>u.status==="pending"),Er(t,a)}function rx(t){let e=t.strategy;if(!e)return;let n=e._pending_close_mc;if(n&&(e._pending_close_mc=null,!(e.opentrades.length===0||Math.sign(e.position_size)!==n.dir)&&($n(t,Math.min(n.qty,Math.abs(e.position_size)),n.price,n.time,{exitId:"Margin call",exitComment:"Margin call"}),Math.abs(e.position_size)>1e-9))){for(let r of e.pending_orders)r.status==="pending"&&(r.category??"entry")==="entry"&&!r._isReversalEntry&&mn(r.direction)===n.dir&&(r.status="cancelled");e.pending_orders=e.pending_orders.filter(r=>r.status==="pending")}}function ix(t){let e=t.strategy,n=Math.sign(e?.position_size??0);if(n===0)return!1;let r=y.from(t.data.open).get(0),i=y.from(t.data.high).get(0),s=y.from(t.data.low).get(0),a=Math.abs(i-r)<=Math.abs(r-s);return n===1?!a:a}function qs(t,e="extreme"){let n=t.strategy;if(!n||n.opentrades.length===0)return;let r=Math.sign(n.position_size);if(r===0)return;let i=r===1?n.config.margin_long??100:n.config.margin_short??100,s=y.from(t.data.open).get(0),a=y.from(t.data.high).get(0),o=y.from(t.data.low).get(0),l=y.from(t.data.close).get(0),c=y.from(t.data.openTime).get(0),u=t.pine?.syminfo?.pointvalue??1,p=e==="open"?s:e==="close"?l:r===1?o:a,h=Math.abs(n.position_size),d=H_(t,p),f=qi(h,p,i,u);if(d<f){let m=f-d,_=i/100,x=m/(p*u*_),w=Math.min(h,4*x),S=[...n.opentrades],v=S[0],E=Math.abs(v.size),C=v.entry_price;if($n(t,w,p,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&w>=E-1e-9&&Math.abs(n.position_size)>1e-9){let F=qi(E,p,i,u),$=E*(p-C)*r*u,j=m-F+$;if(j>0){let A=y.from(t.data.close).get(0),ue=(M=>Math.trunc(M*1e6)/1e6)(j/(p*u*_)),D=Math.min(Math.abs(n.position_size),4*ue);D>1e-9&&(n._pending_close_mc={qty:D,price:A,time:c,dir:r})}}let I=S.find(F=>F.status==="open");n._mc_exit_lock={bar:t.idx,tradeId:I?.id??null}}}function sx(t){if(!t.strategy)return;let e=t.strategy,n=y.from(t.data.high).get(0),r=y.from(t.data.low).get(0),i=y.from(t.data.close).get(0);Er(t,i),tx(t,n,r);let s=y.from(t.data.openTime).get(0);if(Number.isFinite(s)){let a=new Date(s),o=a.getUTCFullYear()*12+a.getUTCMonth(),l=e._monthly_equity??(e._monthly_equity=[]);e._last_month_key===o&&l.length>0?l[l.length-1]=e.equity:(l.push(e.equity),e._last_month_key=o)}}function ax(t){let e=t?.strategy;if(!e)return;e.cagr=lx(t),cx(t);let n=e._monthly_equity??[],r=[e.initial_capital,...n],i=[];for(let d=1;d<r.length;d++){let f=r[d-1];f!==0&&Number.isFinite(f)&&Number.isFinite(r[d])&&i.push(r[d]/f-1)}if(i.length<2){e.sharpe_ratio=0,e.sortino_ratio=0;return}let s=(e.config.risk_free_rate??2)/100/12,a=i.length,o=i.reduce((d,f)=>d+f,0)/a,l=o-s,c=i.reduce((d,f)=>d+(f-o)**2,0)/a,u=Math.sqrt(c),p=i.reduce((d,f)=>d+Math.min(0,f-s)**2,0)/a,h=Math.sqrt(p);e.sharpe_ratio=u>0?l/u:0,e.sortino_ratio=h>0?l/h:0}var ox=1440*60*1e3;function lx(t){let e=t?.strategy;if(!e)return NaN;let n=t?.marketData;if(!Array.isArray(n)||n.length===0)return NaN;let r=n[0]?.openTime,i=n[n.length-1]?.openTime;if(!Number.isFinite(r)||!Number.isFinite(i))return NaN;let s=e.initial_capital??0,a=s+(e.netprofit??0),o=(i-r)/ox;if(o<1||!Number.isFinite(s)||!Number.isFinite(a)||s===0)return NaN;let l=o/365;return 100*(Math.pow(a/s,1/l)-1)}function cx(t){let e=t?.strategy;if(!e)return;let n=e._first_entry_price,r=t?.marketData,i=Array.isArray(r)&&r.length>0?r[r.length-1]?.close:NaN;if(!Number.isFinite(n)||!Number.isFinite(i)||n===0){e.buy_and_hold_pnl=NaN,e.buy_and_hold_per_gain=NaN,e.strategy_outperformance=NaN;return}let s=n,a=(i-s)/s;e.buy_and_hold_per_gain=a*100,e.buy_and_hold_pnl=(e.initial_capital??0)*a,e.strategy_outperformance=(e.netprofit??0)-e.buy_and_hold_pnl}function Iu(t){t.strategy}function ux(t,e){let n={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=n.initial_capital;t.strategy={config:n,opentrades:[],closedtrades:[],pending_orders:[],position_size:0,position_avg_price:NaN,position_entry_name:"",initial_capital:r,account_currency:n.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,cagr:NaN,buy_and_hold_pnl:NaN,buy_and_hold_per_gain:NaN,strategy_outperformance:NaN,_first_entry_price:void 0,_monthly_equity:[],_last_month_key:-1,wintrades:0,losstrades:0,eventrades:0,wintrades_total_profit:0,losstrades_total_loss:0,max_contracts_held_all:0,max_contracts_held_long:0,max_contracts_held_short:0,risk_rules:{},risk_halted:!1,_exit_call_history:new Map,_exit_fallback_counter:0,_exit_fallback_last_bar:-1}}function Kr(t){if(Array.isArray(t))return t.map(Kr);if(t instanceof Map){let e=new Map;return t.forEach((n,r)=>e.set(r,Kr(n))),e}if(t!==null&&typeof t=="object"){let e={};for(let n of Object.keys(t))e[n]=Kr(t[n]);return e}return t}function hx(t){if(!t)return null;let e={};for(let n of Object.keys(t))n==="config"||n==="closedtrades"||(e[n]=Kr(t[n]));return{fields:e,closedtradesLength:t.closedtrades.length}}function px(t,e){if(!(!t||!e)){for(let n of Object.keys(t))n==="config"||n==="closedtrades"||Object.prototype.hasOwnProperty.call(e.fields,n)||delete t[n];t.closedtrades.length>e.closedtradesLength&&(t.closedtrades.length=e.closedtradesLength);for(let n of Object.keys(e.fields))t[n]=Kr(e.fields[n])}}function dx(t){return(...e)=>{let n=z_(e);return t.strategy?t.strategy.config={...t.strategy.config,...n,...t._propOverrides??{}}:ux(t,n),t.strategy.config}}var fx=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],mx={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 yx(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let n=ge(e,fx,mx),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,i=v=>typeof v=="number"&&Number.isNaN(v)||typeof v=="object"&&v!==null&&"__value"in v,s=v=>i(v)?void 0:v,a=r(n.id),o=r(n.direction),l=s(r(n.qty)),c=s(r(n.limit)),u=s(r(n.stop)),p=r(n.oca_name),h=r(n.oca_type),d=r(n.comment),f=mn(o),m=y.from(t.data.close).get(0),_=$o(t,l,f,vu(u,c,m));if(_<=0)return;let x="market";c!==void 0&&u!==void 0?x="stop-limit":c!==void 0?x="limit":u!==void 0&&(x="stop");let w=y.from(t.data.openTime).get(0),S={id:a,direction:f,qty:_,type:x,limit:c,stop:u,bar:t.idx,time:w,status:"pending",oca_name:p,oca_type:h,comment:d};return t.strategy.pending_orders.push(S),S}}function gx(t){return(e,n)=>y.from(e).get(n||0)}function _x(t){return()=>{let e=(t.strategy?.opentrades??[]).slice(),n=h=>e[Number(h)],r=()=>{let h=t.marketData;return Array.isArray(h)&&t.idx>=0&&t.idx<h.length?h[t.idx]?.close??NaN:NaN},i={__value:e.length,valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},s=t.pine?.syminfo?.pointvalue??1,a=(h,d)=>{let f=t.strategy?.config,m=f?.commission_type??"percent",_=f?.commission_value??0;if(!_)return 0;let x=Math.abs(h.size);switch(m){case"percent":return x*d*s*(_/100);case"cash_per_contract":return x*_;case"cash_per_order":return _;default:return 0}},o=h=>Math.abs(h.size)*h.entry_price*s+(h.commission??0);i.profit=h=>{let d=n(h);if(!d)return NaN;let f=r();return Number.isFinite(f)?(Math.sign(d.size)===1?f-d.entry_price:d.entry_price-f)*Math.abs(d.size)*s-(d.commission??0)-a(d,f):NaN},i.profit_percent=h=>{let d=n(h);if(!d)return NaN;let f=i.profit(h);if(!Number.isFinite(f))return NaN;let m=o(d);return m>0?100*f/m:NaN},i.size=h=>n(h)?.size??NaN,i.commission=h=>n(h)?.commission??NaN,i.entry_price=h=>n(h)?.entry_price??NaN,i.entry_bar_index=h=>n(h)?.entry_bar_index??NaN,i.entry_id=h=>n(h)?.entry_id??"",i.entry_comment=h=>n(h)?.entry_comment??n(h)?.entry_id??"",i.entry_time=h=>n(h)?.entry_time??NaN,i.max_drawdown=h=>n(h)?.max_drawdown??0,i.max_drawdown_percent=h=>{let d=n(h);if(!d||!d.max_drawdown)return 0;let f=o(d);return f>0?100*d.max_drawdown/f:0},i.max_runup=h=>n(h)?.max_runup??0,i.max_runup_percent=h=>{let d=n(h);if(!d||!d.max_runup)return 0;let f=o(d);return f>0?100*d.max_runup/f:0};let l=t.strategy,c=l?.config?.margin_long??100,u=l?.config?.margin_short??100,p=c!==100||u!==100;if(!l||l.opentrades.length===0||!p)i.capital_held=NaN;else{let h=0;for(let d of l.opentrades){let f=Math.abs(d.size)*d.entry_price,m=d.size>0?c:u;h+=f*(m/100)}i.capital_held=h}return i}}function xx(t){return()=>{let e=(t.strategy?.closedtrades??[]).slice(),n=a=>e[Number(a)],r={__value:e.length,valueOf(){return e.length},toString(){return String(e.length)},[Symbol.toPrimitive](){return e.length}},i=t.pine?.syminfo?.pointvalue??1,s=a=>{let o=Math.abs(a.size)*a.entry_price*i,l=(a.commission??0)/2;return o+l};return r.profit=a=>n(a)?.profit??NaN,r.profit_percent=a=>{let o=n(a);if(!o||o.profit===void 0)return NaN;let l=s(o);return l>0?100*o.profit/l:NaN},r.size=a=>n(a)?.size??NaN,r.commission=a=>n(a)?.commission??NaN,r.entry_price=a=>n(a)?.entry_price??NaN,r.entry_bar_index=a=>n(a)?.entry_bar_index??NaN,r.entry_id=a=>n(a)?.entry_id??"",r.entry_comment=a=>n(a)?.entry_comment??n(a)?.entry_id??"",r.entry_time=a=>n(a)?.entry_time??NaN,r.exit_price=a=>n(a)?.exit_price??NaN,r.exit_bar_index=a=>n(a)?.exit_bar_index??NaN,r.exit_id=a=>n(a)?.exit_id??"",r.exit_comment=a=>n(a)?.exit_comment??n(a)?.exit_id??"",r.exit_time=a=>n(a)?.exit_time??NaN,r.max_drawdown=a=>n(a)?.max_drawdown??0,r.max_drawdown_percent=a=>{let o=n(a);if(!o||!o.max_drawdown)return 0;let l=s(o);return l>0?100*o.max_drawdown/l:0},r.max_runup=a=>n(a)?.max_runup??0,r.max_runup_percent=a=>{let o=n(a);if(!o||!o.max_runup)return 0;let l=s(o);return l>0?100*o.max_runup/l:0},r.first_index=0,r}}function bx(t){return()=>t.strategy?.netprofit??0}function vx(t){return()=>t.strategy?.position_size??0}function wx(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function Sx(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function Ex(t){return()=>"long"}function Nx(t){return()=>"short"}function Cx(t){return()=>"cash"}function Ix(t){return()=>"percent_of_equity"}function kx(t){return()=>"fixed"}function Ax(t){return()=>t.strategy?.openprofit??0}function Mx(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function Tx(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function Px(t){return()=>t.strategy?.grossprofit??0}function Dx(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function Ox(t){return()=>t.strategy?.grossloss??0}function Rx(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function Lx(t){return()=>t.strategy?.wintrades??0}function Fx(t){return()=>t.strategy?.losstrades??0}function Vx(t){return()=>t.strategy?.eventrades??0}function Bx(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function $x(t){return()=>{let e=t.strategy;if(!e||!e.closedtrades||e.closedtrades.length===0)return NaN;let n=0;for(let r of e.closedtrades){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.closedtrades.length}}function jx(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function Wx(t){return()=>{let e=t.strategy;if(!e||e.wintrades===0)return NaN;let n=0;for(let r of e.closedtrades)if((r.profit??0)>0){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.wintrades}}function Ux(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function qx(t){return()=>{let e=t.strategy;if(!e||e.losstrades===0)return NaN;let n=0;for(let r of e.closedtrades)if((r.profit??0)<0){let i=Math.abs(r.size)*r.entry_price;i>0&&(n+=100*(r.profit??0)/i)}return n/e.losstrades}}function zx(t){return()=>t.strategy?.max_drawdown??0}function Hx(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function Kx(t){return()=>t.strategy?.max_runup??0}function Gx(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function Yx(t){return()=>t.strategy?.max_contracts_held_all??0}function Xx(t){return()=>t.strategy?.max_contracts_held_long??0}function Zx(t){return()=>t.strategy?.max_contracts_held_short??0}function Qx(t){return()=>t.strategy?.position_entry_name??""}function Jx(t){return()=>t.strategy?.initial_capital??0}function eb(t){return()=>t.strategy?.account_currency??"USD"}function tb(t){return()=>{let e=t.strategy;if(!e||e.position_size===0)return NaN;let n=e.position_avg_price;if(!Number.isFinite(n))return NaN;let r=Math.sign(e.position_size),i=r===1?e.config.margin_long??100:e.config.margin_short??100;if(i>=100)return NaN;let s=Math.abs(e.position_size),a=t.pine?.syminfo?.pointvalue??1,o=((e.initial_capital??0)+(e.netprofit??0))/(a*s)-r*n,l=i/100-r,c=o/l,u=t.pine?.syminfo?.mintick??.01;return r===1?Math.floor(c/u)*u:Math.ceil(c/u)*u}}var nb=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],rb={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 ib(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let n=ge(e,nb,rb),r=A=>A==null||typeof A=="string"||typeof A=="number"||typeof A=="boolean"?A:typeof A=="function"?A():A instanceof y?A.get(0):Array.isArray(A)?A[A.length-1]:typeof A=="object"&&A.get!==void 0?A.get(0):A,i=A=>typeof A=="number"&&Number.isNaN(A)||typeof A=="object"&&A!==null&&"__value"in A,s=A=>i(A)?void 0:A,a=r(n.id),o=r(n.direction),l=s(r(n.qty)),c=s(r(n.limit)),u=s(r(n.stop)),p=r(n.oca_name),h=r(n.oca_type),d=r(n.comment),f=mn(o),m=t.strategy,_=m.position_size;for(let A of m.pending_orders)A.bar===t.idx&&A.category==="entry"&&A.type==="market"&&(_+=mn(A.direction)*A.qty);if(Math.sign(_)===f&&_!==0&&X_(m,f))return;let x=y.from(t.data.close).get(0),w="market";c!==void 0&&u!==void 0?w="stop-limit":c!==void 0?w="limit":u!==void 0&&(w="stop");let S=t.pine?.syminfo?.mintick??0,v=c!==void 0?Hr(c,x,S):void 0,E=u!==void 0?Hr(u,x,S):void 0,C=$o(t,l,f,vu(E,v,x)),I=_!==0&&Math.sign(_)!==f;if(C<=0&&!I)return;let F=I?Math.abs(_)+C:C,$=y.from(t.data.openTime).get(0),j={id:a,direction:f,qty:F,type:w,limit:v,stop:E,bar:t.idx,time:$,status:"pending",category:"entry",oca_name:p,oca_type:h,comment:d,_isReversalEntry:I,_base_qty:C};m.pending_orders=m.pending_orders.filter(A=>!(A.category==="entry"&&A.id===a&&A.status==="pending"&&A.bar<t.idx)),m.pending_orders.push(j)}}var sb=[["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"]],ab={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 ob(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let n=jt(e);if(n===void 0){let k=t.strategy;k._exit_fallback_last_bar!==t.idx&&(k._exit_fallback_counter=0,k._exit_fallback_last_bar=t.idx),n=`exit_raw_${k._exit_fallback_counter++}`}let r=ge(e,sb,ab),i=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,s=i(r.id),a=i(r.from_entry),o=i(r.qty),l=i(r.qty_percent),c=k=>typeof k=="number"&&Number.isNaN(k)||typeof k=="object"&&k!==null&&"__value"in k,u=k=>c(k)?void 0:k,p=u(i(r.profit)),h=u(i(r.limit)),d=u(i(r.loss)),f=u(i(r.stop)),m=u(i(r.trail_price)),_=i(r.trail_points),x=i(r.trail_offset),w=t.pine?.syminfo?.mintick??0,S=y.from(t.data.close).get(0),v=h!==void 0?Hr(h,S,w):void 0,E=f!==void 0?Hr(f,S,w):void 0,C=m!==void 0?Hr(m,S,w):void 0,I=a??"",F=!!(I?t.strategy.pending_orders.find(k=>k.category==="entry"&&k.id===I&&k.status==="pending"):t.strategy.pending_orders.find(k=>k.category==="entry"&&k.status==="pending"))?._isReversalEntry,$=t.strategy.opentrades.some(k=>!I||k.entry_id===I),j=t.strategy._exit_call_history,A=j.get(n),ue=A!==void 0&&A===t.idx-1;j.set(n,t.idx);let D={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:I,profit:p,loss:d,limit:v,stop:E,trail_price:C,trail_points:_,trail_offset:x,oca_name:i(r.oca_name),comment:i(r.comment),comment_profit:i(r.comment_profit),comment_loss:i(r.comment_loss),comment_trailing:i(r.comment_trailing),alert_message:i(r.alert_message),alert_profit:i(r.alert_profit),alert_loss:i(r.alert_loss),alert_trailing:i(r.alert_trailing),disable_alert:i(r.disable_alert),trail_armed:!1,trail_peak:NaN,_attachedAtReversal:F,_coversOpenTrade:$,_isPersistent:ue,_callsiteId:n},M=D.id,W=t.strategy.pending_orders;for(let k=W.length-1;k>=0;k--){let V=W[k];V.category==="exit"&&V.id===M&&(V.from_entry??"")===(D.from_entry??"")&&V.status==="pending"&&(V.trail_armed&&(D.trail_armed=!0,D.trail_peak=V.trail_peak),W.splice(k,1))}W.push(D)}}var lb=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],cb={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function ub(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let n=ge(e,lb,cb),r=n.id;if(r==null||!t.strategy.opentrades.some(o=>o.entry_id===r))return;let i=o=>(o.category??"entry")==="exit"&&(o.profit!==void 0||o.loss!==void 0||o.limit!==void 0||o.stop!==void 0||o.trail_price!==void 0||o.trail_points!==void 0),s=t.strategy.pending_orders;for(let o of s)i(o)&&(o.from_entry??"")===r&&o.status==="pending"&&(o.status="cancelled");t.strategy.pending_orders=s.filter(o=>o.status==="pending");let a={id:`Close entry(s) order ${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:n.qty_percent,comment:n.comment,alert_message:n.alert_message,immediately:n.immediately===!0,disable_alert:n.disable_alert,_intended_trade_ids:t.strategy.opentrades.filter(o=>o.entry_id===r).map(o=>o.id)};n.qty!==void 0&&(a.qty=Math.abs(Number(n.qty))),t.strategy.pending_orders.push(a)}}var hb=[["comment","alert_message","immediately","disable_alert"]],pb={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function db(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let n=ge(e,hb,pb);if(t.strategy.opentrades.length===0)return;let 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),i=t.strategy.pending_orders;for(let a of i)r(a)&&a.status==="pending"&&(a.status="cancelled");t.strategy.pending_orders=i.filter(a=>a.status==="pending");let s={id:"Close position order",direction:0,qty:0,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:"",comment:n.comment,alert_message:n.alert_message,immediately:n.immediately===!0,disable_alert:n.disable_alert,_intended_trade_ids:t.strategy.opentrades.map(a=>a.id)};t.strategy.pending_orders.push(s)}}var fb=[["id","immediately"]],mb={id:"string",immediately:"boolean"};function yb(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let n=ge(e,fb,mb).id;n!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===n)))}}function gb(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 _b(t){return{allow_entry_in:e=>{t.strategy&&(t.strategy.risk_rules.allow_entry_in=e)},max_cons_loss_days:(e,n)=>{t.strategy&&(t.strategy.risk_rules.max_cons_loss_days={count:e,alert_message:n})},max_drawdown:(e,n,r)=>{t.strategy&&(t.strategy.risk_rules.max_drawdown={value:e,type:n})},max_intraday_filled_orders:(e,n)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_filled_orders={count:e,alert_message:n})},max_intraday_loss:(e,n,r)=>{t.strategy&&(t.strategy.risk_rules.max_intraday_loss={value:e,type:n})},max_position_size:e=>{t.strategy&&(t.strategy.risk_rules.max_position_size=e)}}}function xb(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function bb(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function vb(t){return e=>t.strategy?$o(t,void 0,1,e):0}var wb={any:dx,order:yx,param:gx,opentrades:_x,closedtrades:xx,netprofit:bx,position_size:vx,position_avg_price:wx,equity:Sx,long:Ex,short:Nx,cash:Cx,percent_of_equity:Ix,fixed:kx,openprofit:Ax,openprofit_percent:Mx,netprofit_percent:Tx,grossprofit:Px,grossprofit_percent:Dx,grossloss:Ox,grossloss_percent:Rx,wintrades:Lx,losstrades:Fx,eventrades:Vx,avg_trade:Bx,avg_trade_percent:$x,avg_winning_trade:jx,avg_winning_trade_percent:Wx,avg_losing_trade:Ux,avg_losing_trade_percent:qx,max_drawdown:zx,max_drawdown_percent:Hx,max_runup:Kx,max_runup_percent:Gx,max_contracts_held_all:Yx,max_contracts_held_long:Xx,max_contracts_held_short:Zx,position_entry_name:Qx,initial_capital:Jx,account_currency:eb,margin_liquidation_price:tb,entry:ib,exit:ob,close:ub,close_all:db,cancel:yb,cancel_all:gb,convert_to_account:xb,convert_to_symbol:bb,default_entry_qty:vb},Sb={long:"long",short:"short",all:"all"},Eb={none:"none",cancel:"cancel",reduce:"reduce"},Nb={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},Sa=class{constructor(e){this.context=e,Object.entries(wb).forEach(([r,i])=>{this[r]=i(e)}),this.direction=()=>Sb,this.oca=()=>Eb,this.commission=()=>Nb;let n=_b(e);this.risk=()=>n}};function Cb(t,e){let n=e.trim();if(n==="UTC"||n==="GMT"||n==="Etc/UTC")return 0;let r=n.match(/^(?:UTC|GMT)([+-])(\\d{1,2})(?::(\\d{2}))?$/i);if(r){let a=r[1]==="+"?1:-1,o=parseInt(r[2],10),l=parseInt(r[3]||"0",10);return a*(o*60+l)}let i=Dn(t,e),s=new Date(Date.UTC(i.year,i.month-1,i.day,i.hour,i.minute,i.second));return Math.round((s.getTime()-t)/6e4)}function Ib(t,e){let n=e>=0?"+":"-",r=s=>String(Math.floor(Math.abs(s))).padStart(2,"0"),i=n+r(e/60)+":"+r(e%60);return`[${new Date(t+e*6e4).toISOString().slice(0,-1)}${i}]`}var Ea=class{constructor(e){this.context=e}logFormat(e,...n){return n.length===0?e:this.context.pine.str.format(e,...n)}param(e,n=0,r){return y.from(e).get(n)}_formatTimestamp(){let e=this.context.data.openTime.data[this.context.idx],n=this.context.chartTimezone||this.context.pine?.syminfo?.timezone||"UTC",r=Cb(e,n);return Ib(e,r)}warning(e,...n){this.context.isSecondaryContext||console.warn(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}error(e,...n){this.context.isSecondaryContext||console.error(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}info(e,...n){this.context.isSecondaryContext||console.log(`${this._formatTimestamp()} ${this.logFormat(e,...n)}`)}},Na=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}error(e){let n=y.from(e).get(0);throw new ye(typeof n=="string"?n:String(n??""),"runtime.error")}},kb=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Ab=["January","February","March","April","May","June","July","August","September","October","November","December"],Mb=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Tb=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],xt=(t,e)=>String(t).padStart(e,"0"),ku={"":"#,##0.###",integer:"#,##0",percent:"#,##0%",currency:"$#,##0.00"},Au=t=>t==null||typeof t=="number"&&Number.isNaN(t),ve=t=>Au(t)?"":String(t),Pb=/^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)$/;function Db(t){return typeof t=="number"?Number.isNaN(t)?"NaN":dr(t,ku[""],"halfEven"):t instanceof Y?"["+au(t).join(", ")+"]":String(t)}var Ca=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}tostring(e,n){if(typeof e!="number")return typeof e=="string"?e:String(e);if(!n)return iu(e);if(n==="mintick"){let r=this.context.pine?.syminfo?.mintick||.01,i=Math.max(0,-Math.floor(Math.log10(r)));return dr(e,i?"0."+"0".repeat(i):"0","halfUp")}return n==="percent"?dr(e,"0.00","halfUp")+"%":n==="volume"?sf(e):dr(e,n,"halfUp")}tonumber(e){let n=ve(e).replace(/^[\\u0000-\\u0020]+|[\\u0000-\\u0020]+$/g,"");return Pb.test(n)?Number(n):NaN}lower(e){return ve(e).toLowerCase()}upper(e){return ve(e).toUpperCase()}trim(e){return ve(e).trim()}repeat(e,n,r=""){return Array(n).fill(ve(e)).join(ve(r))}replace_all(e,n,r){return ve(e).replaceAll(ve(n),ve(r))}replace(e,n,r,i=0){let s=ve(e),a=ve(n),o=ve(r),l=Math.floor(Number(i))||0;if(a==="")return s;let c=0,u=0;for(;;){let 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,n){return ve(e).includes(ve(n))}endswith(e,n){return ve(e).endsWith(ve(n))}startswith(e,n){return ve(e).startsWith(ve(n))}pos(e,n){let r=ve(e).indexOf(ve(n));return r===-1?NaN:r}length(e){return ve(e).length}match(e,n){return ve(e).match(new RegExp(n))}split(e,n){return new Y(ve(e).split(ve(n)),H.string,this.context)}substring(e,n,r){return ve(e).substring(n,r)}format_time(e,n="yyyy-MM-dd\'T\'HH:mm:ssZ",r){let i=Au(e)?0:Number(e),s=r||this.context.pine?.syminfo?.timezone||"UTC",a=Dn(i,s),o=Date.UTC(a.year,a.month-1,a.day,a.hour,a.minute,a.second),l=Math.round((o-i)/6e4),c=Date.UTC(a.year,0,1),u=Math.floor((o-c)/864e5)+1,p=a.hour%12===0?12:a.hour%12,h="",d=0;for(;d<n.length;){let f=n[d];if(f==="\'"){if(n[d+1]==="\'"){h+="\'",d+=2;continue}let m=n.indexOf("\'",d+1);if(m===-1){h+=n.substring(d+1);break}h+=n.substring(d+1,m),d=m+1;continue}if(f>="a"&&f<="z"||f>="A"&&f<="Z"){let m=1;for(;n[d+m]===f;)m++;switch(d+=m,f){case"y":h+=m===2?xt(a.year%100,2):m>=4?xt(a.year,4):String(a.year);break;case"M":m>=4?h+=Ab[a.month-1]:m===3?h+=kb[a.month-1]:m===2?h+=xt(a.month,2):h+=String(a.month);break;case"d":h+=m===2?xt(a.day,2):String(a.day);break;case"D":h+=m>=3?xt(u,3):m===2?xt(u,2):String(u);break;case"E":h+=m>=4?Tb[a.dayOfWeek]:Mb[a.dayOfWeek];break;case"a":h+=a.hour<12?"AM":"PM";break;case"h":h+=m===2?xt(p,2):String(p);break;case"H":h+=m===2?xt(a.hour,2):String(a.hour);break;case"m":h+=m===2?xt(a.minute,2):String(a.minute);break;case"s":h+=m===2?xt(a.second,2):String(a.second);break;case"S":{let _=i-Math.floor(i/1e3)*1e3;h+=xt(_,3).substring(0,m);break}case"Z":{let _=l>=0?"+":"-",x=Math.abs(l);h+=`${_}${xt(Math.floor(x/60),2)}${xt(x%60,2)}`;break}default:h+=f.repeat(m)}continue}h+=f,d++}return h}format(e,...n){let r=ve(e),i="",s=!1,a=0;for(;a<r.length;){let o=r[a];if(o==="\'"){r[a+1]==="\'"?(i+="\'",a+=2):(s=!s,a++);continue}if(o!=="{"||s){i+=o,a++;continue}let l=["","",""],c=0,u=0,p=!1,h=a+1;for(;h<r.length;h++){let d=r[h];if(p)l[c]+=d,d==="\'"&&(p=!1);else if(d===","&&c<2)c++;else if(d==="{")u++,l[c]+=d;else if(d==="}"){if(u===0)break;u--,l[c]+=d}else d===" "?(c!==1||l[1].length>0)&&(l[c]+=d):(d==="\'"&&(p=!0),l[c]+=d)}if(h>=r.length)throw new Error("Unmatched braces in the pattern.");i+=this._formatArgument(l,r.slice(a,h+1),n),a=h+1}return i}_formatArgument([e,n,r],i,s){if(!/^[+-]?\\d+$/.test(e))throw new Error(`can\'t parse argument number: ${e}`);let a=Number(e);if(a<0)throw new Error(`negative argument number: ${e}`);let o=n.trim().toLowerCase();if(o!==""&&o!=="number"){if(o==="date"||o==="time"||o==="choice")return i;throw new Error(`unknown format type: ${n}`)}if(a>=s.length||s[a]===void 0)return`{${a}}`;let l=s[a];return o===""||typeof l!="number"?Db(l):Number.isNaN(l)?"NaN":dr(l,ku[r.trim().toLowerCase()]??r,"halfEven")}},Ob=Object.defineProperty,Rb=(t,e,n)=>e in t?Ob(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Lb=(t,e,n)=>Rb(t,typeof e!="symbol"?e+"":e,n),rc=t=>typeof t=="function"?t():t instanceof y?t.get(0):t,Ia=class{constructor(e){this.context=e,Lb(this,"_chart")}param(e,n=0,r){return y.from(e).get(n)}get chart(){return this._chart===void 0&&(this._chart=ze(this.context.timeframe)),this._chart}resolve(e,n,r){let i=rc(e);if(i==null||i===""||typeof i=="number"&&isNaN(i))return this.chart??{unit:"D",multiplier:1};let s=ze(i);if(!s)throw new ye(r(String(i)),n);return s}get periodString(){let e=this.chart;return e?Sr(e,this.context.pineVersion>=6):this.context.timeframe}get main_period(){return this.periodString}get period(){return this.periodString}get multiplier(){return this.chart?.multiplier??1}get isdwm(){let e=this.chart?.unit;return e==="D"||e==="W"||e==="M"}get isdaily(){return this.chart?.unit==="D"}get isweekly(){return this.chart?.unit==="W"}get ismonthly(){return this.chart?.unit==="M"}get isticks(){return!1}get isseconds(){return this.chart?.unit==="S"}get isminutes(){return this.chart?.unit===""}get isintraday(){return!this.isdwm}change(e){let n=this.resolve(e,"timeframe.change",s=>`Cannot parse resolution \'${s}\'. - Invalid format`),r=y.from(this.context.data.openTime).get(0),i=y.from(this.context.data.openTime).get(1);return isNaN(r)||isNaN(i)?!1:ni(r,n)!==ni(i,n)}from_seconds(e){let n=rc(e);return n==null||isNaN(n)?NaN:vy(n)}in_seconds(e){let n=this.resolve(e,"timeframe.in_seconds",r=>`Invalid value of the \'period\' argument (\'${r}\') in the \'timeframe.in_seconds()\' function.`);return pt(n)}},Fb=Object.defineProperty,Vb=Object.getOwnPropertyDescriptor,Qt=(t,e,n,r)=>{for(var i=r>1?void 0:r?Vb(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Fb(e,n,i),i},Bb=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],$b=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],jb={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"},Wb=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],Ub=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],qb=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],zb=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],ic=["color","offset","editable","show_last","title","display","force_overlay"],Hb=["price","title","color","linestyle","linewidth","editable","display"],Kb=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],Gb={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"},Yb={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"},Xb={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"},Zb={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"},Qb={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"},sc={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},Jb={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},e1={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},Wt=class{constructor(e){this.context=e}_resolvePlotKey(e,n){if(e){let r=this.context.plots[e];return!r||!n||r._callsiteId===n?e:e+n}return n||"plot"}extractPlotOptions(e){let n={};for(let r in e)n[r]=y.from(e[r]).get(0);return n}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,n=0,r){return y.from(e).get(n)}plotchar(...e){let n=jt(e),r=ge(e,$b,jb),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n);this.context.plots[l]||(this.context.plots[l]={data:[],options:{...o,style:"char"},title:s,_plotKey:l,_callsiteId:n});let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:{char:o.char,color:o.color,textcolor:o.textcolor,location:o.location,size:o.size,offset:o.offset}}),this.context.plots[l]}any(...e){let n=jt(e),r=ge(e,Bb,Gb),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n),c="color"in a;if(!this.context.plots[l]){let d=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,overlay:d},title:s,_plotKey:l,_callsiteId:n}}let u=y.from(i).get(0),p=o.color;typeof p=="function"&&(p=p());let 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){let n=jt(e),r=ge(e,Wb,Yb),{series:i,title:s,...a}=r,o=this.extractPlotOptions(a),l=this._resolvePlotKey(s,n);if(!this.context.plots[l]){let u=o.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[l]={data:[],options:{...o,style:"shape",shape:o.style,overlay:u},title:s,_plotKey:l,_callsiteId:n}}let c=y.from(i).get(0);return this.context.plots[l].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:c,options:o?.location==="absolute"||c?{text:o.text,textcolor:o.textcolor,color:o.color,offset:o.offset,shape:o.style,location:o.location,size:o.size}:void 0}),this.context.plots[l]}plotarrow(...e){let n=jt(e),r=ge(e,Ub,Xb),{series:i,title:s,...a}=r,o=y.from(i).get(0),l=this.extractPlotOptions(a),c=this._resolvePlotKey(s,n);if(!this.context.plots[c]){let u=l.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[c]={data:[],options:{...l,style:"shape",overlay:u},title:s,_plotKey:c,_callsiteId:n}}return this.context.plots[c].data.push({title:s,time:this.context.marketData[this.context.idx].openTime,value:o,options:typeof o=="number"&&!isNaN(o)&&o!==0?{text:void 0,textcolor:void 0,color:o>0?l.colorup:l.colordown,offset:l.offset,shape:o>0?"shape_arrow_up":"shape_arrow_down",location:o>0?"BelowBar":"AboveBar",height:l.maxheight}:void 0}),this.context.plots[c]}plotbar(...e){let n=jt(e),r=ge(e,qb,Zb),{open:i,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,n);if(!this.context.plots[p]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"bar",overlay:d},title:l,_plotKey:p,_callsiteId:n}}let h=[y.from(i).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){let n=jt(e),r=ge(e,zb,Qb),{open:i,high:s,low:a,close:o,title:l,...c}=r,u=this.extractPlotOptions(c),p=this._resolvePlotKey(l,n);if(!this.context.plots[p]){let d=u.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[p]={data:[],options:{...u,style:"candle",overlay:d},title:l,_plotKey:p,_callsiteId:n}}let h=[y.from(i).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){let n=jt(e),r=ge(e,ic,sc),{title:i,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,n);if(!this.context.plots[o]){let l=a.force_overlay??(this.context?.indicator?.overlay||!1);this.context.plots[o]={data:[],options:{...a,style:"background",overlay:l},title:i,_plotKey:o,_callsiteId:n}}this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}})}barcolor(...e){let n=jt(e),r=ge(e,ic,sc),{title:i,...s}=r,a=this.extractPlotOptions(s),o=this._resolvePlotKey(i,n);return this.context.plots[o]||(this.context.plots[o]={data:[],options:{...a,style:"barcolor"},title:i,_plotKey:o,_callsiteId:n}),this.context.plots[o].data.push({title:i,time:this.context.marketData[this.context.idx].openTime,value:a.color&&a.color!=="na"&&a?.color.toString()!=="NaN",options:{color:a.color}}),this.context.plots[o]}};Qt([T],Wt.prototype,"plotchar",1),Qt([T],Wt.prototype,"any",1),Qt([T],Wt.prototype,"plotshape",1),Qt([T],Wt.prototype,"plotarrow",1),Qt([T],Wt.prototype,"plotbar",1),Qt([T],Wt.prototype,"plotcandle",1),Qt([T],Wt.prototype,"bgcolor",1),Qt([T],Wt.prototype,"barcolor",1);var Hi=class{constructor(e){this.context=e}get style_dashed(){return"dashed"}get style_solid(){return"solid"}get style_dotted(){return"dotted"}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=jt(e),r=ge(e,Hb,Jb),{price:i,title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u}=r,p=[i,{title:s,color:a,linestyle:o,linewidth:l,editable:c,display:u,style:"hline"}];return n&&p.push({__callsiteId:n}),this.context.pine.plot.any(...p)}};Qt([T],Hi.prototype,"any",1);var Ki=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=jt(e),r=e.length>=6&&typeof e[2]=="number",i=!r&&e.length>=3&&e[2]!==null&&typeof e[2]=="object"&&"top_value"in e[2]?e[2]:null;if(r||i!==null){let s=e[0],a=e[1],o=i?y.from(i.top_value).get(0):e[2],l=i?y.from(i.bottom_value).get(0):e[3],c=i?y.from(i.top_color).get(0):e[4],u=i?y.from(i.bottom_color).get(0):e[5],p=i?i.title||void 0:e.length>6&&typeof e[6]=="string"?e[6]:void 0,h=s?._plotKey||s?.title,d=a?._plotKey||a?.title,f=p||"fill",m=this.context.plots[f];m&&n&&m._callsiteId!==n&&(f=n),this.context.plots[f]||(this.context.plots[f]={title:p||"Fill",plot1:h,plot2:d,data:[],options:{plot1:h,plot2:d,style:"fill",gradient:!0},_plotKey:f,_callsiteId:n}),this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{top_value:o,bottom_value:l,top_color:c,bottom_color:u}})}else{let s=ge(e,Kb,e1),{plot1:a,plot2:o,color:l,title:c,editable:u,show_last:p,fillgaps:h,display:d}=s,f=c||"fill",m=this.context.plots[f];m&&n&&m._callsiteId!==n&&(f=n);let _=y.from(l).get(0);if(!this.context.plots[f]){let x=a?._plotKey||a?.title,w=o?._plotKey||o?.title;this.context.plots[f]={title:c||"Fill",plot1:x,plot2:w,data:[],options:{plot1:x,plot2:w,color:_,editable:u,show_last:p,fillgaps:h,display:d,style:"fill"},_plotKey:f,_callsiteId:n}}this.context.plots[f].data.push({time:this.context.marketData[this.context.idx].openTime,value:null,options:{color:_}})}}};Qt([T],Ki.prototype,"any",1);var t1=Object.defineProperty,n1=(t,e,n)=>e in t?t1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,r1=(t,e,n)=>n1(t,typeof e!="symbol"?e+"":e,n),ka=class{constructor(e){this.context=e,r1(this,"point");let n=this.context,r=i=>i==null?i:typeof i=="object"&&Array.isArray(i.data)&&typeof i.get=="function"?i.get(0):typeof i=="function"?i():i;this.point={new(i,s,a){return new Ye(r(i),r(s),r(a)??NaN)},from_index(i,s){return new Ye(void 0,r(i),r(s))},from_time(i,s){return new Ye(r(i),void 0,r(s))},copy(i){return i.copy()},now(i){let s=n.idx,a=n.marketData[s]?.openTime;return new Ye(a,s,r(i))}}}param(e,n=0,r){return y.from(e).get(n)}bg_color(){return"#1e293b"}fg_color(){return"#d1d4dc"}is_standard(){let e=this.context?.chartStyle;return e==null||e==="standard"}is_heikinashi(){return this.context?.chartStyle==="heikinashi"}is_kagi(){return!1}is_linebreak(){return!1}is_pnf(){return!1}is_range(){return!1}is_renko(){return!1}},i1=Object.defineProperty,s1=(t,e,n)=>e in t?i1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Be=(t,e,n)=>s1(t,typeof e!="symbol"?e+"":e,n),a1=0,_r=class t{constructor(e,n,r="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",d=!1,f="none"){Be(this,"id"),Be(this,"x"),Be(this,"y"),Be(this,"text"),Be(this,"xloc"),Be(this,"yloc"),Be(this,"color"),Be(this,"style"),Be(this,"textcolor"),Be(this,"size"),Be(this,"textalign"),Be(this,"tooltip"),Be(this,"text_font_family"),Be(this,"force_overlay"),Be(this,"text_formatting"),Be(this,"_deleted"),Be(this,"_helper"),Be(this,"_createdAtBar",-1),this.id=a1++,this.x=e,this.y=n,this.text=r,this.xloc=i,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=d,this.text_formatting=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,n){this._helper?this._helper.set_xy(this,e,n):this._deleted||(this.x=e,this.y=n)}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,n){this._helper?this._helper.set_xloc(this,e,n):this._deleted||(this.x=e,this.xloc=n)}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._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_x(){return this._deleted?NaN:this.x}get_y(){return this._deleted?NaN:this.y}get_text(){return this._deleted?"":this.text}delete(){this._deleted=!0}copy(){return this._helper?this._helper.copy(this):this._clone()}_clone(){return new t(this.x,this.y,this.text,this.xloc,this.yloc,this.color,this.style,this.textcolor,this.size,this.textalign,this.tooltip,this.text_font_family,this.force_overlay,this.text_formatting)}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,text_formatting:this.text_formatting,_deleted:this._deleted}}},wi=t=>t!=null&&!(typeof t=="number"&&isNaN(t));function Gi(t,e){return e==="bt"?{x:wi(t.time)?t.time:NaN,xloc:e}:e==="bi"?{x:wi(t.index)?t.index:NaN,xloc:e}:wi(t.index)?{x:t.index,xloc:"bi"}:wi(t.time)?{x:t.time,xloc:"bt"}:{x:0,xloc:"bi"}}var Mu=Object.defineProperty,o1=Object.getOwnPropertyDescriptor,l1=(t,e,n)=>e in t?Mu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$e=(t,e,n,r)=>{for(var i=r>1?void 0:r?o1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Mu(e,n,i),i},c1=(t,e,n)=>l1(t,typeof e!="symbol"?e+"":e,n),u1=[["x","y","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay","text_formatting"],["point","text","xloc","yloc","color","style","textcolor","size","textalign","tooltip","text_font_family","force_overlay","text_formatting"]],h1={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",text_formatting:"string"},Pe=class{constructor(e){this.context=e,c1(this,"_labels",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__labels__||(this.context.plots.__labels__={title:"__labels__",data:[],options:{style:"label",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._labels=this._labels.filter(s=>!s._deleted);let n=this._labels.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__labels__.data=[{time:e,value:r,options:{style:"label"}}],i.length>0?this.context.plots.__labels_overlay__={title:"__labels_overlay__",data:[{time:e,value:i,options:{style:"label"}}],options:{style:"label",overlay:!0}}:delete this.context.plots.__labels_overlay__}_resolve(e){if(e==null)return e;if(e instanceof dt)return null;if(typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"){let n=e.get(0);return typeof n=="number"&&isNaN(n)?null:n}return typeof e=="function"?e():typeof e=="number"&&isNaN(e)?null:e}_createLabel(e,n,r="",i="bi",s="pr",a="",o="style_label_down",l="",c="normal",u="center",p="",h="default",d=!1,f="none"){let m=new _r(e,n,this._resolve(r),this._resolve(i),this._resolve(s),this._resolve(a),this._resolve(o),this._resolve(l),this._resolve(c),this._resolve(u),this._resolve(p),this._resolve(h),d,this._resolve(f)||"none");return m._helper=this,m._createdAtBar=this.context.idx,this._labels.push(m),this._enforceMaxCount(),m}_enforceMaxCount(){let e=this.context.indicator?.max_labels_count??50,n=this._labels.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._labels){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ge(e,u1,h1),r,i,s=n.xloc;if(n.point instanceof Ye){let a=n.point,o=Gi(a,s);r=o.x,s=s||o.xloc,i=a.price}else r=this._resolve(n.x),i=this._resolve(n.y);return this._createLabel(r,i,n.text,s,n.yloc,n.color,n.style,n.textcolor,n.size,n.textalign,n.tooltip,n.text_font_family,n.force_overlay,n.text_formatting)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof dt||typeof n=="number"&&isNaN(n))return null;if(n instanceof _r)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof _r)return r}return null}return this.new(...e)}set_x(e,n){e&&!e._deleted&&(e.x=n)}set_y(e,n){e&&!e._deleted&&(e.y=n)}set_xy(e,n,r){e&&!e._deleted&&(e.x=n,e.y=r)}set_text(e,n){e&&!e._deleted&&(e.text=n)}set_color(e,n){e&&!e._deleted&&(e.color=n)}set_textcolor(e,n){e&&!e._deleted&&(e.textcolor=n)}set_size(e,n){e&&!e._deleted&&(e.size=n)}set_style(e,n){e&&!e._deleted&&(e.style=n)}set_textalign(e,n){e&&!e._deleted&&(e.textalign=n)}set_tooltip(e,n){e&&!e._deleted&&(e.tooltip=n)}set_text_font_family(e,n){e&&!e._deleted&&(e.text_font_family=this._resolve(n))}set_text_formatting(e,n){e&&!e._deleted&&(e.text_formatting=this._resolve(n))}set_xloc(e,n,r){e&&!e._deleted&&(e.x=this._resolve(n),e.xloc=this._resolve(r))}set_yloc(e,n){e&&!e._deleted&&(e.yloc=n)}set_point(e,n){e&&!e._deleted&&n&&(e.x=Gi(n,e.xloc).x,e.y=n.price)}get_x(e){return e&&!e._deleted?e.x:NaN}get_y(e){return e&&!e._deleted?e.y:NaN}get_text(e){return e&&!e._deleted?e.text:""}copy(e){if(!e)return;let n=e._clone();return n._helper=this,n._createdAtBar=this.context.idx,this._labels.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0)}get all(){return this._labels.filter(e=>!e._deleted)}rollbackFromBar(e){this._labels=this._labels.filter(n=>n._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"}};$e([T],Pe.prototype,"new",1),$e([T],Pe.prototype,"set_x",1),$e([T],Pe.prototype,"set_y",1),$e([T],Pe.prototype,"set_xy",1),$e([T],Pe.prototype,"set_text",1),$e([T],Pe.prototype,"set_color",1),$e([T],Pe.prototype,"set_textcolor",1),$e([T],Pe.prototype,"set_size",1),$e([T],Pe.prototype,"set_style",1),$e([T],Pe.prototype,"set_textalign",1),$e([T],Pe.prototype,"set_tooltip",1),$e([T],Pe.prototype,"set_text_font_family",1),$e([T],Pe.prototype,"set_text_formatting",1),$e([T],Pe.prototype,"set_xloc",1),$e([T],Pe.prototype,"set_yloc",1),$e([T],Pe.prototype,"set_point",1),$e([T],Pe.prototype,"copy",1),$e([T],Pe.prototype,"delete",1);var p1=Object.defineProperty,d1=(t,e,n)=>e in t?p1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,at=(t,e,n)=>d1(t,typeof e!="symbol"?e+"":e,n),f1=0,fn=class t{constructor(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){at(this,"id"),at(this,"x1"),at(this,"y1"),at(this,"x2"),at(this,"y2"),at(this,"xloc"),at(this,"extend"),at(this,"color"),at(this,"style"),at(this,"width"),at(this,"force_overlay"),at(this,"_deleted"),at(this,"_helper"),at(this,"_createdAtBar",-1),this.id=f1++,this.x1=e,this.y1=n,this.x2=r,this.y2=i,this.xloc=s,this.extend=a,this.color=o,this.style=l,this.width=c,this.force_overlay=u,this._deleted=!1,this._helper=null}set_x1(e){this._helper?this._helper.set_x1(this,e):this._deleted||(this.x1=e)}set_y1(e){this._helper?this._helper.set_y1(this,e):this._deleted||(this.y1=e)}set_x2(e){this._helper?this._helper.set_x2(this,e):this._deleted||(this.x2=e)}set_y2(e){this._helper?this._helper.set_y2(this,e):this._deleted||(this.y2=e)}set_xy1(e,n){this._helper?this._helper.set_xy1(this,e,n):this._deleted||(this.x1=e,this.y1=n)}set_xy2(e,n){this._helper?this._helper.set_xy2(this,e,n):this._deleted||(this.x2=e,this.y2=n)}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,n,r){this._helper?this._helper.set_xloc(this,e,n,r):this._deleted||(this.x1=e,this.x2=n,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._deleted?NaN:this.x1}get_y1(){return this._deleted?NaN:this.y1}get_x2(){return this._deleted?NaN:this.x2}get_y2(){return this._deleted?NaN:this.y2}get_price(e){return this._helper?this._helper.get_price(this,e):NaN}delete(){this._helper?this._helper.delete(this):this._deleted=!0}copy(){return this._helper?this._helper.copy(this):this._clone()}_clone(){return new t(this.x1,this.y1,this.x2,this.y2,this.xloc,this.extend,this.color,this.style,this.width,this.force_overlay)}toPlotData(){return{id:this.id,x1:this.x1,y1:this.y1,x2:this.x2,y2:this.y2,xloc:this.xloc,extend:this.extend,color:this.color,style:this.style,width:this.width,force_overlay:this.force_overlay,_deleted:this._deleted}}},Tu=Object.defineProperty,m1=Object.getOwnPropertyDescriptor,y1=(t,e,n)=>e in t?Tu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,He=(t,e,n,r)=>{for(var i=r>1?void 0:r?m1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Tu(e,n,i),i},ac=(t,e,n)=>y1(t,typeof e!="symbol"?e+"":e,n),g1=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],_1={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"},Re=class{constructor(e){this.context=e,ac(this,"_lines",[]),ac(this,"linefills",null)}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__lines__||(this.context.plots.__lines__={title:"__lines__",data:[],options:{style:"drawing_line",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._lines=this._lines.filter(s=>!s._deleted);let n=this._lines.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__lines__.data=[{time:e,value:r,options:{style:"drawing_line"}}],i.length>0?this.context.plots.__lines_overlay__={title:"__lines_overlay__",data:[{time:e,value:i,options:{style:"drawing_line"}}],options:{style:"drawing_line",overlay:!0}}:delete this.context.plots.__lines_overlay__}_resolvePoint(e,n){return Gi(e,n)}_resolve(e){return e==null?e:e instanceof dt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n}_createLine(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){let p=new fn(e,n,r,i,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(),p}_enforceMaxCount(){let e=this.context.indicator?.max_lines_count??50,n=this._lines.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._lines){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ge(e,g1,_1),r,i,s,a,o=n.xloc;if(n.first_point instanceof Ye){let l=n.first_point,c=n.second_point,u=this._resolvePoint(l,o);r=u.x,i=l.price,o=o||u.xloc,c instanceof Ye?(s=this._resolvePoint(c,o).x,a=c.price):(s=0,a=NaN)}else r=this._resolve(n.x1),i=this._resolve(n.y1),s=this._resolve(n.x2),a=this._resolve(n.y2);return this._createLine(r,i,s,a,o,n.extend,n.color,n.style,n.width,n.force_overlay)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof dt||typeof n=="number"&&isNaN(n))return null;if(n instanceof fn)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof fn)return r}return null}return this.new(...e)}set_x1(e,n){e&&!e._deleted&&(e.x1=this._resolve(n))}set_y1(e,n){e&&!e._deleted&&(e.y1=this._resolve(n))}set_x2(e,n){e&&!e._deleted&&(e.x2=this._resolve(n))}set_y2(e,n){e&&!e._deleted&&(e.y2=this._resolve(n))}set_xy1(e,n,r){e&&!e._deleted&&(e.x1=this._resolve(n),e.y1=this._resolve(r))}set_xy2(e,n,r){e&&!e._deleted&&(e.x2=this._resolve(n),e.y2=this._resolve(r))}set_color(e,n){e&&!e._deleted&&(e.color=this._resolveColor(n))}set_width(e,n){e&&!e._deleted&&(e.width=this._resolve(n)||1)}set_style(e,n){e&&!e._deleted&&(e.style=this._resolve(n))}set_extend(e,n){e&&!e._deleted&&(e.extend=this._resolve(n))}set_xloc(e,n,r,i){e&&!e._deleted&&(e.x1=n,e.x2=r,e.xloc=i)}set_first_point(e,n){e&&!e._deleted&&n&&(e.x1=this._resolvePoint(n,e.xloc).x,e.y1=n.price)}set_second_point(e,n){e&&!e._deleted&&n&&(e.x2=this._resolvePoint(n,e.xloc).x,e.y2=n.price)}get_x1(e){return e&&!e._deleted?e.x1:NaN}get_y1(e){return e&&!e._deleted?e.y1:NaN}get_x2(e){return e&&!e._deleted?e.x2:NaN}get_y2(e){return e&&!e._deleted?e.y2:NaN}get_price(e,n){if(!e||e._deleted)return NaN;if(e.xloc!=="bi")return NaN;let r=e.x2-e.x1;return r===0?e.y1:e.y1+(n-e.x1)/r*(e.y2-e.y1)}copy(e){if(!e)return;let n=e._clone();return n._helper=this,n._createdAtBar=this.context.idx,this._lines.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0,e instanceof fn&&this.linefills?.deleteForLine(e))}get all(){return this._lines.filter(e=>!e._deleted)}rollbackFromBar(e){this._lines=this._lines.filter(n=>n._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"}};He([T],Re.prototype,"new",1),He([T],Re.prototype,"set_x1",1),He([T],Re.prototype,"set_y1",1),He([T],Re.prototype,"set_x2",1),He([T],Re.prototype,"set_y2",1),He([T],Re.prototype,"set_xy1",1),He([T],Re.prototype,"set_xy2",1),He([T],Re.prototype,"set_color",1),He([T],Re.prototype,"set_width",1),He([T],Re.prototype,"set_style",1),He([T],Re.prototype,"set_extend",1),He([T],Re.prototype,"set_xloc",1),He([T],Re.prototype,"set_first_point",1),He([T],Re.prototype,"set_second_point",1),He([T],Re.prototype,"copy",1),He([T],Re.prototype,"delete",1);var x1=Object.defineProperty,b1=(t,e,n)=>e in t?x1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ke=(t,e,n)=>b1(t,typeof e!="symbol"?e+"":e,n),v1=0,xr=class t{constructor(e,n,r,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",d="auto",f="center",m="center",_="wrap_none",x="default",w="format_none",S=!1){ke(this,"id"),ke(this,"left"),ke(this,"top"),ke(this,"right"),ke(this,"bottom"),ke(this,"xloc"),ke(this,"extend"),ke(this,"border_color"),ke(this,"border_style"),ke(this,"border_width"),ke(this,"bgcolor"),ke(this,"text"),ke(this,"text_color"),ke(this,"text_size"),ke(this,"text_halign"),ke(this,"text_valign"),ke(this,"text_wrap"),ke(this,"text_font_family"),ke(this,"text_formatting"),ke(this,"force_overlay"),ke(this,"_deleted"),ke(this,"_helper"),ke(this,"_createdAtBar",-1),this.id=v1++,this.left=e,this.top=n,this.right=r,this.bottom=i,this.xloc=s,this.extend=a,this.border_color=o,this.border_style=l,this.border_width=c,this.bgcolor=u,this.text=p,this.text_color=h,this.text_size=d,this.text_halign=f,this.text_valign=m,this.text_wrap=_,this.text_font_family=x,this.text_formatting=w,this.force_overlay=S,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,n){this._helper?this._helper.set_lefttop(this,e,n):this._deleted||(this.left=e,this.top=n)}set_rightbottom(e,n){this._helper?this._helper.set_rightbottom(this,e,n):this._deleted||(this.right=e,this.bottom=n)}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,n,r){this._helper?this._helper.set_xloc(this,e,n,r):this._deleted||(this.left=e,this.right=n,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._deleted?NaN:this.left}get_right(){return this._deleted?NaN:this.right}get_top(){return this._deleted?NaN:this.top}get_bottom(){return this._deleted?NaN: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 this._helper?this._helper.copy(this):this._clone()}_clone(){return new t(this.left,this.top,this.right,this.bottom,this.xloc,this.extend,this.border_color,this.border_style,this.border_width,this.bgcolor,this.text,this.text_color,this.text_size,this.text_halign,this.text_valign,this.text_wrap,this.text_font_family,this.text_formatting,this.force_overlay)}},Pu=Object.defineProperty,w1=Object.getOwnPropertyDescriptor,S1=(t,e,n)=>e in t?Pu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Se=(t,e,n,r)=>{for(var i=r>1?void 0:r?w1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Pu(e,n,i),i},E1=(t,e,n)=>S1(t,typeof e!="symbol"?e+"":e,n),N1=[["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"]],C1={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"},me=class{constructor(e){this.context=e,E1(this,"_boxes",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__boxes__||(this.context.plots.__boxes__={title:"__boxes__",data:[],options:{style:"drawing_box",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._boxes=this._boxes.filter(s=>!s._deleted);let n=this._boxes.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__boxes__.data=[{time:e,value:r,options:{style:"drawing_box"}}],i.length>0?this.context.plots.__boxes_overlay__={title:"__boxes_overlay__",data:[{time:e,value:i,options:{style:"drawing_box"}}],options:{style:"drawing_box",overlay:!0}}:delete this.context.plots.__boxes_overlay__}_resolvePoint(e,n){return Gi(e,n)}_resolve(e){return e==null?e:e instanceof dt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,n){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||n}_createBox(e,n,r,i,s="bi",a="none",o="#2962ff",l="style_solid",c=1,u="#2962ff",p="",h="#000000",d="auto",f="center",m="center",_="wrap_none",x="default",w="format_none",S=!1){let v=new xr(e,n,r,i,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(d)||"auto",this._resolve(f)||"center",this._resolve(m)||"center",this._resolve(_)||"wrap_none",this._resolve(x)||"default",this._resolve(w)||"format_none",S);return v._helper=this,v._createdAtBar=this.context.idx,this._boxes.push(v),this._enforceMaxCount(),v}_enforceMaxCount(){let e=this.context.indicator?.max_boxes_count??50,n=this._boxes.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._boxes){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}new(...e){let n=ge(e,N1,C1),r,i,s,a,o=n.xloc;if(n.top_left instanceof Ye){let l=n.top_left,c=n.bottom_right,u=this._resolvePoint(l,o);r=u.x,i=l.price,o=o||u.xloc,c instanceof Ye?(s=this._resolvePoint(c,o).x,a=c.price):(s=0,a=NaN)}else r=this._resolve(n.left),i=this._resolve(n.top),s=this._resolve(n.right),a=this._resolve(n.bottom);return this._createBox(r,i,s,a,o,n.extend,n.border_color,n.border_style,n.border_width,n.bgcolor,n.text,n.text_color,n.text_size,n.text_halign,n.text_valign,n.text_wrap,n.text_font_family,void 0,n.force_overlay)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof dt||typeof n=="number"&&isNaN(n))return null;if(n instanceof xr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof xr)return r}return null}return this.new(...e)}set_left(e,n){e&&!e._deleted&&(e.left=this._resolve(n))}set_right(e,n){e&&!e._deleted&&(e.right=this._resolve(n))}set_top(e,n){e&&!e._deleted&&(e.top=this._resolve(n))}set_bottom(e,n){e&&!e._deleted&&(e.bottom=this._resolve(n))}set_lefttop(e,n,r){e&&!e._deleted&&(e.left=this._resolve(n),e.top=this._resolve(r))}set_rightbottom(e,n,r){e&&!e._deleted&&(e.right=this._resolve(n),e.bottom=this._resolve(r))}set_top_left_point(e,n){e&&!e._deleted&&n&&(e.left=this._resolvePoint(n,e.xloc).x,e.top=n.price)}set_bottom_right_point(e,n){e&&!e._deleted&&n&&(e.right=this._resolvePoint(n,e.xloc).x,e.bottom=n.price)}set_xloc(e,n,r,i){e&&!e._deleted&&(e.left=this._resolve(n),e.right=this._resolve(r),e.xloc=this._resolve(i))}set_bgcolor(e,n){e&&!e._deleted&&(e.bgcolor=this._resolve(n))}set_border_color(e,n){e&&!e._deleted&&(e.border_color=this._resolve(n))}set_border_width(e,n){e&&!e._deleted&&(e.border_width=this._resolve(n)??1)}set_border_style(e,n){e&&!e._deleted&&(e.border_style=this._resolve(n))}set_extend(e,n){e&&!e._deleted&&(e.extend=this._resolve(n))}set_text(e,n){e&&!e._deleted&&(e.text=this._resolve(n)||"")}set_text_color(e,n){e&&!e._deleted&&(e.text_color=this._resolve(n))}set_text_size(e,n){e&&!e._deleted&&(e.text_size=this._resolve(n))}set_text_halign(e,n){e&&!e._deleted&&(e.text_halign=this._resolve(n))}set_text_valign(e,n){e&&!e._deleted&&(e.text_valign=this._resolve(n))}set_text_wrap(e,n){e&&!e._deleted&&(e.text_wrap=this._resolve(n))}set_text_font_family(e,n){e&&!e._deleted&&(e.text_font_family=this._resolve(n))}set_text_formatting(e,n){e&&!e._deleted&&(e.text_formatting=this._resolve(n))}get_left(e){return e&&!e._deleted?e.left:NaN}get_right(e){return e&&!e._deleted?e.right:NaN}get_top(e){return e&&!e._deleted?e.top:NaN}get_bottom(e){return e&&!e._deleted?e.bottom:NaN}copy(e){if(!e)return;let n=e._clone();return n._helper=this,n._createdAtBar=this.context.idx,this._boxes.push(n),this._enforceMaxCount(),n}delete(e){e&&(e._deleted=!0)}get all(){return this._boxes.filter(e=>!e._deleted)}rollbackFromBar(e){this._boxes=this._boxes.filter(n=>n._createdAtBar<e),this.syncToPlot()}};Se([T],me.prototype,"new",1),Se([T],me.prototype,"set_left",1),Se([T],me.prototype,"set_right",1),Se([T],me.prototype,"set_top",1),Se([T],me.prototype,"set_bottom",1),Se([T],me.prototype,"set_lefttop",1),Se([T],me.prototype,"set_rightbottom",1),Se([T],me.prototype,"set_top_left_point",1),Se([T],me.prototype,"set_bottom_right_point",1),Se([T],me.prototype,"set_xloc",1),Se([T],me.prototype,"set_bgcolor",1),Se([T],me.prototype,"set_border_color",1),Se([T],me.prototype,"set_border_width",1),Se([T],me.prototype,"set_border_style",1),Se([T],me.prototype,"set_extend",1),Se([T],me.prototype,"set_text",1),Se([T],me.prototype,"set_text_color",1),Se([T],me.prototype,"set_text_size",1),Se([T],me.prototype,"set_text_halign",1),Se([T],me.prototype,"set_text_valign",1),Se([T],me.prototype,"set_text_wrap",1),Se([T],me.prototype,"set_text_font_family",1),Se([T],me.prototype,"set_text_formatting",1),Se([T],me.prototype,"copy",1),Se([T],me.prototype,"delete",1);var I1=Object.defineProperty,k1=(t,e,n)=>e in t?I1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,cr=(t,e,n)=>k1(t,typeof e!="symbol"?e+"":e,n),A1=0,ri=class{constructor(e,n,r){cr(this,"id"),cr(this,"line1"),cr(this,"line2"),cr(this,"color"),cr(this,"_deleted"),cr(this,"_createdAtBar",-1),this.id=A1++,this.line1=e,this.line2=n,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(){let 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,n=!!(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:n,_deleted:this._deleted}}},Du=Object.defineProperty,M1=Object.getOwnPropertyDescriptor,T1=(t,e,n)=>e in t?Du(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zs=(t,e,n,r)=>{for(var i=r>1?void 0:r?M1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Du(e,n,i),i},P1=(t,e,n)=>T1(t,typeof e!="symbol"?e+"":e,n),br=class{constructor(e){this.context=e,P1(this,"_linefills",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__linefills__||(this.context.plots.__linefills__={title:"__linefills__",data:[],options:{style:"linefill",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._linefills=this._linefills.filter(s=>!s._deleted);let n=this._linefills.map(s=>s.toPlotData()),r=n.filter(s=>!s.force_overlay),i=n.filter(s=>s.force_overlay);this.context.plots.__linefills__.data=[{time:e,value:r,options:{style:"linefill"}}],i.length>0?this.context.plots.__linefills_overlay__={title:"__linefills_overlay__",data:[{time:e,value:i,options:{style:"linefill"}}],options:{style:"linefill",overlay:!0}}:delete this.context.plots.__linefills_overlay__}_resolve(e){return e==null?e:e instanceof dt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e){let n=this._resolve(e);return n==null?n:typeof n=="number"&&isNaN(n)?NaN:n}new(e,n,r){let i=this._resolve(e),s=this._resolve(n);if(!(i instanceof fn)||!(s instanceof fn))return null;let a=r&&typeof r=="object"&&!Array.isArray(r)&&"color"in r?r.color:r,o=this._resolveColor(a);if(i&&s){let c=i.id,u=s.id;for(let p of this._linefills){if(p._deleted)continue;let h=p.line1?.id,d=p.line2?.id;if(h===c&&d===u||h===u&&d===c)return p.color=o,p._createdAtBar=this.context.idx,p}}let l=new ri(i,s,o);return l._createdAtBar=this.context.idx,this._linefills.push(l),this._enforceMaxCount(),l}_enforceMaxCount(){let e=this.context.indicator?.max_lines_count??50,n=this._linefills.filter(r=>!r._deleted).length-e;for(let r of this._linefills){if(n<=0)break;r._deleted||(r._deleted=!0,n--)}}any(...e){if(e.length===1){let n=e[0];return n==null||n instanceof dt||typeof n=="number"&&isNaN(n)?null:n instanceof ri?n:null}return this.new(e[0],e[1],e[2])}set_color(e,n){e&&!e._deleted&&(e.color=this._resolveColor(n))}get_line1(e){return e?e.line1:void 0}get_line2(e){return e?e.line2:void 0}delete(e){e&&(e._deleted=!0)}deleteForLine(e){for(let n of this._linefills)!n._deleted&&(n.line1===e||n.line2===e)&&(n._deleted=!0)}get all(){return this._linefills.filter(e=>!e._deleted)}rollbackFromBar(e){this._linefills=this._linefills.filter(n=>n._createdAtBar<e),this.syncToPlot()}};zs([T],br.prototype,"new",1),zs([T],br.prototype,"set_color",1),zs([T],br.prototype,"delete",1);var D1=Object.defineProperty,O1=(t,e,n)=>e in t?D1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nt=(t,e,n)=>O1(t,typeof e!="symbol"?e+"":e,n),R1=0,vr=class{constructor(e,n=!1,r=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){Nt(this,"id"),Nt(this,"points"),Nt(this,"curved"),Nt(this,"closed"),Nt(this,"xloc"),Nt(this,"line_color"),Nt(this,"fill_color"),Nt(this,"line_style"),Nt(this,"line_width"),Nt(this,"force_overlay"),Nt(this,"_deleted"),Nt(this,"_createdAtBar",-1),this.id=R1++,this.points=e,this.curved=n,this.closed=r,this.xloc=i,this.line_color=s,this.fill_color=a,this.line_style=o,this.line_width=l,this.force_overlay=c,this._deleted=!1}delete(){this._deleted=!0}toPlotData(){return{id:this.id,points:this.points.map(e=>({time:e.time,index:e.index,price:e.price})),curved:this.curved,closed:this.closed,xloc:this.xloc,line_color:this.line_color,fill_color:this.fill_color,line_style:this.line_style,line_width:this.line_width,force_overlay:this.force_overlay,_deleted:this._deleted}}},Ou=Object.defineProperty,L1=Object.getOwnPropertyDescriptor,F1=(t,e,n)=>e in t?Ou(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oc=(t,e,n,r)=>{for(var i=r>1?void 0:r?L1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Ou(e,n,i),i},V1=(t,e,n)=>F1(t,typeof e!="symbol"?e+"":e,n),ii=class{constructor(e){this.context=e,V1(this,"_polylines",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__polylines__||(this.context.plots.__polylines__={title:"__polylines__",data:[],options:{style:"drawing_polyline",overlay:this.context.indicator?.overlay||!1}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._polylines=this._polylines.filter(n=>!n._deleted),this.context.plots.__polylines__.data=[{time:e,value:this._polylines.map(n=>n.toPlotData()),options:{style:"drawing_polyline"}}]}_resolve(e){return e==null?e:e instanceof dt?NaN:typeof e=="object"&&Array.isArray(e.data)&&typeof e.get=="function"?e.get(0):typeof e=="function"?e():e}_resolveColor(e,n){let r=this._resolve(e);return r==null?r:typeof r=="number"&&isNaN(r)?NaN:r||n}_extractPoints(e){let n=this._resolve(e),r=n&&n.array?n.array:n;return Array.isArray(r)?r.filter(i=>i instanceof Ye):[]}new(...e){let n,r=!1,i=!1,s="bi",a="#2962ff",o="",l="style_solid",c=1,u=!1,p=(x,w)=>Object.prototype.hasOwnProperty.call(x,w),h=x=>{p(x,"curved")&&(r=x.curved),p(x,"closed")&&(i=x.closed),p(x,"xloc")&&(s=x.xloc),p(x,"line_color")&&(a=x.line_color),p(x,"fill_color")&&(o=x.fill_color),p(x,"line_style")&&(l=x.line_style),p(x,"line_width")&&(c=x.line_width),p(x,"force_overlay")&&(u=x.force_overlay)},d=e.length>=1?e[e.length-1]:null,f=e.length>=2&&d&&typeof d=="object"&&!Array.isArray(d)&&!(d instanceof y)&&!(d instanceof Ye);if(e.length===1&&d&&typeof d=="object"&&!Array.isArray(d)&&"points"in d)n=d.points,h(d);else{let x=f?e.slice(0,-1):e;n=x[0],x.length>1&&(r=x[1]),x.length>2&&(i=x[2]),x.length>3&&(s=x[3]),x.length>4&&(a=x[4]),x.length>5&&(o=x[5]),x.length>6&&(l=x[6]),x.length>7&&(c=x[7]),x.length>8&&(u=x[8]),f&&h(d)}let m=this._extractPoints(n),_=new vr(m,this._resolve(r)??!1,this._resolve(i)??!1,this._resolve(s)||"bi",this._resolveColor(a,"#2962ff"),this._resolveColor(o,""),this._resolve(l)||"style_solid",this._resolve(c)||1,this._resolve(u)??!1);return _._createdAtBar=this.context.idx,this._polylines.push(_),this._enforceMaxCount(),_}_enforceMaxCount(){let e=this.context.indicator?.max_polylines_count??50,n=this._polylines.filter(r=>!r._deleted);if(n.length>e){let r=n.length-e,i=0;for(let s of this._polylines){if(i>=r)break;s._deleted||(s._deleted=!0,i++)}}}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof dt||typeof n=="number"&&isNaN(n))return null;if(n instanceof vr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof vr)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(n=>n._createdAtBar<e),this.syncToPlot()}};oc([T],ii.prototype,"new",1),oc([T],ii.prototype,"delete",1);var B1=Object.defineProperty,$1=(t,e,n)=>e in t?B1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ot=(t,e,n)=>$1(t,typeof e!="symbol"?e+"":e,n),j1=0;function Ke(t){return Number.isFinite(t)?Math.trunc(t):NaN}var Nr=class{constructor(e="top_right",n=1,r=1,i="",s="",a=0,o="",l=0,c=!1){ot(this,"id"),ot(this,"position"),ot(this,"columns"),ot(this,"rows"),ot(this,"bgcolor"),ot(this,"frame_color"),ot(this,"frame_width"),ot(this,"border_color"),ot(this,"border_width"),ot(this,"force_overlay"),ot(this,"_deleted"),ot(this,"cells"),ot(this,"merges"),ot(this,"_helper"),this.id=j1++,this.position=e,this.columns=Ke(n),this.rows=Ke(r),this.bgcolor=i,this.frame_color=s,this.frame_width=a,this.border_color=o,this.border_width=l,this.force_overlay=c,this._deleted=!1,this.merges=[],this.cells=[];for(let u=0;u<this.rows;u++){this.cells[u]=[];for(let p=0;p<this.columns;p++)this.cells[u][p]=null}}delete(){this._deleted=!0}toPlotData(){let e=this.cells.map(n=>n.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(n=>({...n}))}}setCell(e,n,r){if(e=Ke(e),n=Ke(n),!(n>=0&&n<this.rows&&e>=0&&e<this.columns))return;let i=new Set;for(;;){let a=this.cells[n][e];if(!a?._merged||!a._merge_parent)break;i.add(n*this.columns+e);let[o,l]=a._merge_parent;if(!(l>=0&&l<this.rows&&o>=0&&o<this.columns)||i.has(l*this.columns+o)){a._merged=!1,a._merge_parent=null;break}e=o,n=l}let s=this.cells[n][e]||this._defaultCell();Object.assign(s,r),this.cells[n][e]=s}markMerged(e,n,r,i){if(!(n>=0&&n<this.rows&&e>=0&&e<this.columns))return;let s=this.cells[n][e]||this._defaultCell();s._merged=!0,s._merge_parent=[r,i],this.cells[n][e]=s}getCell(e,n){return e=Ke(e),n=Ke(n),n>=0&&n<this.rows&&e>=0&&e<this.columns?this.cells[n][e]:null}clearCell(e,n){e=Ke(e),n=Ke(n),n>=0&&n<this.rows&&e>=0&&e<this.columns&&(this.cells[n][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)}cell_set_text_formatting(...e){return this._helper.cell_set_text_formatting(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",text_formatting:"none",_merged:!1,_merge_parent:null}}},Ru=Object.defineProperty,W1=Object.getOwnPropertyDescriptor,U1=(t,e,n)=>e in t?Ru(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ae=(t,e,n,r)=>{for(var i=r>1?void 0:r?W1(e,n):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(i=(r?a(e,n,i):a(i))||i);return r&&i&&Ru(e,n,i),i},q1=(t,e,n)=>U1(t,typeof e!="symbol"?e+"":e,n),z1=["position","columns","rows","bgcolor","frame_color","frame_width","border_color","border_width","force_overlay"],H1=["column","row","text","width","height","text_color","text_halign","text_valign","text_size","bgcolor","tooltip","text_font_family","text_formatting"],lc=["start_column","start_row","end_column","end_row"];function Si(t,e){return!!t&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Nr)&&e.some(n=>n in t)}var Ee=class{constructor(e){this.context=e,q1(this,"_tables",[])}param(e,n=0,r){return y.from(e).get(n)}_ensurePlotsEntry(){this.context.plots.__tables__||(this.context.plots.__tables__={title:"__tables__",data:[],options:{style:"table",overlay:!0}})}syncToPlot(){this._ensurePlotsEntry();let e=this.context.marketData[0]?.openTime||0;this._tables=this._tables.filter(n=>!n._deleted),this.context.plots.__tables__.data=[{time:e,value:this._tables.map(n=>n.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 n="top_right",r=1,i=1,s="",a="",o=0,l="",c=0,u=!1,p=e[e.length-1];if(Si(p,z1)){let d=p,f=e.slice(0,-1);n=f[0]??d.position??n,r=f[1]??d.columns??r,i=f[2]??d.rows??i,s=d.bgcolor??s,a=d.frame_color??a,o=d.frame_width??o,l=d.border_color??l,c=d.border_width??c,u=d.force_overlay??u}else n=e[0]??n,r=e[1]??r,i=e[2]??i,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u;let h=new Nr(this._resolve(n)||"top_right",this._resolve(r)||1,this._resolve(i)||1,this._resolve(s)||"",this._resolve(a)||"",this._resolve(o)||0,this._resolve(l)||"",this._resolve(c)||0,this._resolve(u)??!1);return h._setHelper(this),this._takePosition(h),this._tables.push(h),h}_takePosition(e){for(let n of this._tables)n!==e&&!n._deleted&&n.position===e.position&&(n._deleted=!0)}any(...e){if(e.length===1){let n=e[0];return n==null||typeof n=="object"&&"__value"in n||typeof n=="number"&&isNaN(n)?null:n instanceof Nr?n:null}return this.new(...e)}cell(...e){let n,r,i,s="",a=0,o=0,l="#000000",c="center",u="center",p="normal",h="",d="",f="default",m="none",_=e[e.length-1];if(Si(_,H1)){let v=_,E=e.slice(0,-1);n=E[0],r=E.length>1?E[1]:v.column??0,i=E.length>2?E[2]:v.row??0,s=E[3]??v.text??s,a=E[4]??v.width??a,o=E[5]??v.height??o,l=E[6]??v.text_color??l,c=E[7]??v.text_halign??c,u=E[8]??v.text_valign??u,p=E[9]??v.text_size??p,h=E[10]??v.bgcolor??h,d=E[11]??v.tooltip??d,f=E[12]??v.text_font_family??f,m=E[13]??v.text_formatting??m}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??s,a=e[4]??a,o=e[5]??o,l=e[6]??l,c=e[7]??c,u=e[8]??u,p=e[9]??p,h=e[10]??h,d=e[11]??d,f=e[12]??f,m=e[13]??m;let x=this._resolve(n);if(!x||x._deleted)return;let w=this._resolve(r)??0,S=this._resolve(i)??0;x.setCell(w,S,{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(d)),text_font_family:this._resolve(f)||"default",text_formatting:this._resolve(m)||"none"})}delete(e){e&&(e._deleted=!0)}clear(...e){let n,r,i,s,a,o=e[e.length-1];if(Si(o,lc)){let d=o;n=e[0],r=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:r),a=d.end_row??(e.length>5?e[4]:i)}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??r,a=e[4]??i;let l=this._resolve(n);if(!l||l._deleted)return;let c=Ke(this._resolve(r)??0),u=Ke(this._resolve(i)??0),p=Ke(this._resolve(s)??c),h=Ke(this._resolve(a)??u);for(let d=u;d<=h;d++)for(let f=c;f<=p;f++)l.clearCell(f,d)}merge_cells(...e){let n,r,i,s,a,o=e[e.length-1];if(Si(o,lc)){let d=o;n=e[0],r=e.length>2?e[1]:d.start_column??0,i=e.length>3?e[2]:d.start_row??0,s=d.end_column??(e.length>4?e[3]:0),a=d.end_row??(e.length>5?e[4]:0)}else n=e[0],r=e[1]??0,i=e[2]??0,s=e[3]??0,a=e[4]??0;let l=this._resolve(n);if(!l||l._deleted)return;let c=Ke(this._resolve(r)??0),u=Ke(this._resolve(i)??0),p=Ke(this._resolve(s)??0),h=Ke(this._resolve(a)??0);if(!(isNaN(c)||isNaN(u)||isNaN(p)||isNaN(h))){for(let d=u;d<=h;d++)for(let f=c;f<=p;f++)d===u&&f===c||l.markMerged(f,d,c,u);l.merges.push({startCol:c,startRow:u,endCol:p,endRow:h})}}cell_set_text(e,n,r,i){this._setCellProp(e,n,r,"text",i,!0)}cell_set_bgcolor(e,n,r,i){this._setCellProp(e,n,r,"bgcolor",i)}cell_set_text_color(e,n,r,i){this._setCellProp(e,n,r,"text_color",i)}cell_set_text_size(e,n,r,i){this._setCellProp(e,n,r,"text_size",i)}cell_set_height(e,n,r,i){this._setCellProp(e,n,r,"height",i)}cell_set_width(e,n,r,i){this._setCellProp(e,n,r,"width",i)}cell_set_tooltip(e,n,r,i){this._setCellProp(e,n,r,"tooltip",i,!0)}cell_set_text_halign(e,n,r,i){this._setCellProp(e,n,r,"text_halign",i)}cell_set_text_valign(e,n,r,i){this._setCellProp(e,n,r,"text_valign",i)}cell_set_text_font_family(e,n,r,i){this._setCellProp(e,n,r,"text_font_family",i)}cell_set_text_formatting(e,n,r,i){this._setCellProp(e,n,r,"text_formatting",i)}set_position(e,n){let r=this._resolve(e);!r||r._deleted||(r.position=this._resolve(n)||r.position,this._takePosition(r))}set_bgcolor(e,n){let r=this._resolve(e);!r||r._deleted||(r.bgcolor=this._resolve(n)||"")}set_border_color(e,n){let r=this._resolve(e);!r||r._deleted||(r.border_color=this._resolve(n)||"")}set_border_width(e,n){let r=this._resolve(e);!r||r._deleted||(r.border_width=this._resolve(n)||0)}set_frame_color(e,n){let r=this._resolve(e);!r||r._deleted||(r.frame_color=this._resolve(n)||"")}set_frame_width(e,n){let r=this._resolve(e);!r||r._deleted||(r.frame_width=this._resolve(n)||0)}get all(){return this._tables.filter(e=>!e._deleted)}rollbackFromBar(e){this.syncToPlot()}_setCellProp(e,n,r,i,s,a=!1){let o=this._resolve(e);if(!o||o._deleted)return;let l=this._resolve(n)??0,c=this._resolve(r)??0,u=this._resolve(s);o.setCell(l,c,{[i]:a?this._resolveText(u):u})}_resolveText(e){return e==null||e!==e?"":String(e)}};Ae([T],Ee.prototype,"new",1),Ae([T],Ee.prototype,"cell",1),Ae([T],Ee.prototype,"delete",1),Ae([T],Ee.prototype,"clear",1),Ae([T],Ee.prototype,"merge_cells",1),Ae([T],Ee.prototype,"cell_set_text",1),Ae([T],Ee.prototype,"cell_set_bgcolor",1),Ae([T],Ee.prototype,"cell_set_text_color",1),Ae([T],Ee.prototype,"cell_set_text_size",1),Ae([T],Ee.prototype,"cell_set_height",1),Ae([T],Ee.prototype,"cell_set_width",1),Ae([T],Ee.prototype,"cell_set_tooltip",1),Ae([T],Ee.prototype,"cell_set_text_halign",1),Ae([T],Ee.prototype,"cell_set_text_valign",1),Ae([T],Ee.prototype,"cell_set_text_font_family",1),Ae([T],Ee.prototype,"cell_set_text_formatting",1),Ae([T],Ee.prototype,"set_position",1),Ae([T],Ee.prototype,"set_bgcolor",1),Ae([T],Ee.prototype,"set_border_color",1),Ae([T],Ee.prototype,"set_border_width",1),Ae([T],Ee.prototype,"set_frame_color",1),Ae([T],Ee.prototype,"set_frame_width",1);function hn(t,e){let n=Lo(t);if(n instanceof Ui)return n;throw new ye(`The \\`footprint\\` ID used in the \\`${e}()\\` call cannot be \\`na\\`.`,`footprint.${e}`)}var Aa=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(){throw new ye("Could not find function or function reference \'footprint\'","footprint")}buy_volume(e){return hn(e,"buy_volume").buy_volume()}sell_volume(e){return hn(e,"sell_volume").sell_volume()}total_volume(e){return hn(e,"total_volume").total_volume()}delta(e){return hn(e,"delta").delta()}poc(e){return hn(e,"poc").poc()}vah(e){return hn(e,"vah").vah()}val(e){return hn(e,"val").val()}rows(e){return hn(e,"rows").rows()}get_row_by_price(e,n){return hn(e,"get_row_by_price").get_row_by_price(n)}};function Cn(t,e){let n=Lo(t);if(n instanceof Wi)return n;throw new ye(`The \\`volume_row\\` ID used in the \\`${e}()\\` call cannot be \\`na\\`.`,`volume_row.${e}`)}var Ma=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(){throw new ye("Could not find function or function reference \'volume_row\'","volume_row")}up_price(e){return Cn(e,"up_price").up_price()}down_price(e){return Cn(e,"down_price").down_price()}buy_volume(e){return Cn(e,"buy_volume").buy_volume()}sell_volume(e){return Cn(e,"sell_volume").sell_volume()}total_volume(e){return Cn(e,"total_volume").total_volume()}delta(e){return Cn(e,"delta").delta()}has_buy_imbalance(e){return Cn(e,"has_buy_imbalance").has_buy_imbalance()}has_sell_imbalance(e){return Cn(e,"has_sell_imbalance").has_sell_imbalance()}},cc=["session","adjustment","backadjustment","settlement_as_close"],K1=t=>t!==null&&typeof t=="object"&&Object.getPrototypeOf(t)===Object.prototype;function uc(t,e){let n={};return t.forEach((r,i)=>{K1(r)?Object.assign(n,r):i<e.length&&r!==void 0&&(n[e[i]]=r)}),n}function hc(t){let{modifier:e}=Wn(t);return e?{base:t.slice(0,t.lastIndexOf(";")),chartType:e}:{base:t,chartType:null}}var Ta=class{constructor(e){this.context=e}param(e,n=0,r){return typeof e=="string"?e:y.from(e).get(n)}inherit(e,n){let{base:r,chartType:i}=hc(this._coerce(e)),s=Pn(this._coerce(n)),a=Us(s,zr(r).modifiers);return i&&i!=="standard"?`${a};${i}`:a}new(e,n,...r){let i=uc([e,n,...r],["prefix","ticker",...cc]),s=this._coerce(i.prefix),a=this._coerce(i.ticker),o=s?a?`${s}:${a}`:s:a;return Us(o,this._applyModifiers({},i))}modify(e,...n){let r=uc([e,...n],["tickerid",...cc]),{base:i,chartType:s}=hc(this._coerce(r.tickerid)),{symbol:a,modifiers:o}=zr(i),l=Us(a,this._applyModifiers(o,r));return s?`${l};${s}`:l}_applyModifiers(e,n){let r={...e},i=c=>{let u=c===void 0?"":this._coerce(c);return u===""?void 0:u},s=i(n.session);s==="regular"?delete r.session:s!==void 0&&(r.session=s);let a=i(n.adjustment);a!==void 0&&(r.adjustment=a);let o=i(n.backadjustment);o==="on"?r.backadjustment="default":o==="off"&&delete r.backadjustment;let l=i(n.settlement_as_close);return l==="on"?r["settlement-as-close"]=!0:l==="off"&&(r["settlement-as-close"]=!1),r}standard(e){return e==null?Pn(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):Pn(this._coerce(e))}heikinashi(e){return gu(this._coerce(e),"heikinashi")}renko(e,n,r,i,s){return this._coerce(e)}kagi(e,n){return this._coerce(e)}linebreak(e,n){return this._coerce(e)}pointfigure(e,n,r,i,s){return this._coerce(e)}_coerce(e){if(e==null)return"";if(e instanceof y){let n=e.get(0);return n==null?"":String(n)}return typeof e=="number"&&isNaN(e)?"":String(e)}};function G1(t){let e=t.trim();if(e.endsWith("[]"))return"array";let n=e.indexOf("<");n>=0&&(e=e.slice(0,n));let r=e.split(/\\s+/).filter(Boolean);return r.length?r[r.length-1]:""}function Y1(t,e,n){if(e)return n instanceof Ht&&n._udt?.__name__===e;let r=t?.__pineReceiverType__;if(typeof r!="string")return!1;switch(G1(r)){case"line":return n instanceof fn;case"box":return n instanceof xr;case"label":return n instanceof _r;case"polyline":return n instanceof vr;case"linefill":return n instanceof ri;case"table":return n instanceof Nr;case"array":return n instanceof Y||Array.isArray(n);case"map":return n instanceof ti;case"matrix":return n instanceof le;case"chart.point":return n instanceof Ye;case"string":return typeof n=="string";case"bool":return typeof n=="boolean";case"int":case"float":return typeof n=="number";default:return!1}}var X1=Object.defineProperty,Z1=(t,e,n)=>e in t?X1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J=(t,e,n)=>Z1(t,typeof e!="symbol"?e+"":e,n),Q1=new Proxy({},{get:(t,e)=>e==="get_text"||e==="get_tooltip"?()=>"":()=>NaN}),Pa=class Mi{constructor({marketData:e,source:n,tickerId:r,timeframe:i,limit:s,sDate:a,eDate:o,fullContext:l,inputs:c}){J(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([])}),J(this,"indicator"),J(this,"cache",{}),J(this,"taState",{}),J(this,"strategy"),J(this,"isSecondaryContext",!1),J(this,"chartTimezone",null),J(this,"chartStyle","standard"),J(this,"dataVersion",0),J(this,"__maxLoops",5e5),J(this,"NA",NaN),J(this,"warnings",[]),J(this,"alerts",[]),J(this,"_alertMode","realtime"),J(this,"_propOverrides",{}),J(this,"_execTick",0),J(this,"lang"),J(this,"length",0),J(this,"_drawingHelpers",[]),J(this,"pine"),J(this,"idx",0),J(this,"params",{}),J(this,"const",{}),J(this,"var",{}),J(this,"let",{}),J(this,"lctx",new Map),J(this,"result"),J(this,"plots",{}),J(this,"marketData"),J(this,"source"),J(this,"tickerId"),J(this,"timeframe",""),J(this,"pineVersion",null),J(this,"limit"),J(this,"sDate"),J(this,"eDate"),J(this,"fullContext"),J(this,"viewportLeft"),J(this,"viewportRight"),J(this,"pineTSCode"),J(this,"inputs",{}),J(this,"_callStack",[]),J(this,"_pathStack",[]),this.marketData=e,this.source=n,this.tickerId=r,this.timeframe=i,this.limit=s,this.sDate=a,this.eDate=o,this.fullContext=l||this,this.inputs=c||{};let u=new ji(this),p={Type:u.Type.bind(u),na:new dt,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new $i(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new Bi(this,"openTime"),time_close:new Bi(this,"closeTime"),dayofmonth:new Zt(this,En.dayofmonth),dayofweek:new Zt(this,En.dayofweek),hour:new Zt(this,En.hour),minute:new Zt(this,En.minute),month:new Zt(this,En.month),second:new Zt(this,En.second),weekofyear:new Zt(this,En.weekofyear),year:new Zt(this,En.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 da(this),ta:new xa(this),math:new fa(this),request:new _a(this),array:new aa(this),map:new oa(this),matrix:new la(this),ticker:new Ta(this),strategy:new Sa(this),syminfo:null,timeframe:new Ia(this),barstate:new ca(this),session:new pa(this),get bar_index(){return h.data.bar_index},get last_bar_index(){let A=h.marketData;return Array.isArray(A)&&A.length>0?A.length-1:h.data.close.length-1},get last_bar_time(){let A=h.marketData;return Array.isArray(A)&&A.length>0?A[A.length-1].openTime:h.data.openTime.get(0)},get timenow(){return new Date().getTime()},get ask(){return NaN},get bid(){return NaN},get time_tradingday(){let A=y.from(h.data.closeTime).get(0);if(isNaN(A))return NaN;let ue=h.pine?.syminfo?.timezone||"UTC",D=Dn(A,ue);return Date.UTC(D.year,D.month-1,D.day,0,0,0)},get inputs(){return h.inputs},log:new Ea(this),runtime:new Na(this),str:new Ca(this),...p,...eu};let d=p.dayofweek;Object.assign(d,{sunday:1,monday:2,tuesday:3,wednesday:4,thursday:5,friday:6,saturday:7}),this.pine.dayofweek=d;let f=new Wt(this),m=new Hi(this),_=new Ki(this);this.bindContextObject(f,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(f,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(m,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(_,["any","param"],"fill");let x=new ka(this);this.pine.chart={param:x.param.bind(x),get bg_color(){return x.bg_color()},get fg_color(){return x.fg_color()},get is_standard(){return x.is_standard()},get is_heikinashi(){return x.is_heikinashi()},get is_kagi(){return x.is_kagi()},get is_linebreak(){return x.is_linebreak()},get is_pnf(){return x.is_pnf()},get is_range(){return x.is_range()},get is_renko(){return x.is_renko()},point:x.point,get left_visible_bar_time(){if(h.viewportLeft!==void 0)return h.viewportLeft;let A=h.marketData;return Array.isArray(A)&&A.length>0?A[0].openTime:NaN},get right_visible_bar_time(){if(h.viewportRight!==void 0)return h.viewportRight;let A=h.marketData;return Array.isArray(A)&&A.length>0?A[A.length-1].openTime:NaN}};let w=new Pe(this);this.bindContextObject(w,["any","new","param","set_x","set_y","set_xy","set_text","set_color","set_textcolor","set_size","set_style","set_textalign","set_tooltip","set_text_font_family","set_text_formatting","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:()=>new Y(w.all,H.label,this)});let S=new Re(this);this.bindContextObject(S,["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:()=>new Y(S.all,H.line,this)});let v=new me(this);this.bindContextObject(v,["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:()=>new Y(v.all,H.box,this)});let E=new br(this);S.linefills=E,this.bindContextObject(E,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>new Y(E.all,H.linefill,this)});let C=new ii(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>new Y(C.all,H.any,this)});let I=new Ee(this);this.bindContextObject(I,["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","cell_set_text_formatting","set_position","set_bgcolor","set_border_color","set_border_width","set_frame_color","set_frame_width"],"table"),Object.defineProperty(this.pine.table,"all",{get:()=>new Y(I.all,H.table,this)}),this._drawingHelpers=[w,S,v,E,C,I];let F=new Aa(this);this.bindContextObject(F,["any","param","buy_volume","sell_volume","total_volume","delta","poc","vah","val","rows","get_row_by_price"],"footprint");let $=new Ma(this);this.bindContextObject($,["any","param","up_price","down_price","buy_volume","sell_volume","total_volume","delta","has_buy_imbalance","has_sell_imbalance"],"volume_row");let j=new sa(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,n){this.warnings.push({message:e,method:n,bar:this.idx})}rollbackDrawings(e){for(let n of this._drawingHelpers)n.rollbackFromBar(e)}bindContextObject(e,n,r=""){r&&!this.pine[r]&&(this.pine[r]={});let i=r?this.pine[r]:this.pine;for(let s of n)typeof e[s]=="function"?i[s]=e[s].bind(e):i[s]=e[s]}toTuple(e,n){return Array.isArray(e)?Array.isArray(e[0])?e:[e]:[new Array(n).fill(NaN)]}init(e,n,r=0){let i;return n instanceof y?i=n.get(0):Array.isArray(n)?Array.isArray(n[0])?i=n[0]:i=n[n.length-1+r]:i=n,e?e instanceof y?(e.data[e.data.length-1]=i,typeof i=="boolean"&&this.pineVersion>=6&&(e.beforeStart=!1),e):Array.isArray(e)?(e[e.length-1]=i,this.typedSeries(e,i)):this.typedSeries([i],i):this.typedSeries([i],i)}typedSeries(e,n,r=0){let i=new y(e,r);return typeof n=="boolean"&&this.pineVersion>=6&&(i.beforeStart=!1),i}initVar(e,n){if(e)return e;if(typeof n=="function"&&(n=n()),n instanceof Ht){let i=n.__def__;for(let s in i)typeof n[s]=="function"&&(n[s]=n[s]())}let r;return n instanceof y?r=n.get(0):Array.isArray(n)?Array.isArray(n[0])?r=n[0]:r=this.precision(n[n.length-1]):r=this.precision(n),this.typedSeries([r],r)}precision(e,n=10){if(typeof e!="number")return e;let r=n===10?Mi.PRECISION_EPSILON:10**n;return Math.abs(e)*r<2**53?Math.round(e*r)/r:e}param(e,n,r){if(typeof e=="string")return e;if(e instanceof y){if(n){let i=new y(e.data,e.offset+n);return i.beforeStart=e.beforeStart,i}return e}return ua(e)&&(e=e.__value),!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?new y(e,n||0):(this.params[r].length===0?this.params[r].push(e):this.params[r][this.params[r].length-1]=e,this.typedSeries(this.params[r],e,n||0)))}get(e,n){if((n==null||Number.isNaN(n))&&(n=0),typeof n=="number"&&!Number.isInteger(n)&&(n=Math.trunc(n)),e instanceof y)return e.get(n);if(Array.isArray(e)){let r=e.length-1-n;return r<0||r>=e.length?NaN:e[r]}return e}set(e,n){if(e instanceof y){e.set(0,typeof n=="number"?this.precision(n):n);return}if(Array.isArray(e)){e.length>0?e[e.length-1]=n:e.push(n);return}}iter(e){return e==null?[]:Array.isArray(e.array)?e.array:e.map instanceof Map?e.map:e}entries(e){return e==null?[].entries():Array.isArray(e.array)?e.array.entries():e.map instanceof Map?e.map.entries():Array.isArray(e)||typeof e.entries=="function"?e.entries():[].entries()}pushId(e){let n=this._pathStack.length>0?this._pathStack[this._pathStack.length-1]:"",r=n?n+"|"+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(){let e=this.peekId();if(!e)return this;let n=this.lctx.get(e);return n||(n={id:e,let:{},const:{},var:{}},this.lctx.set(e,n)),n}drawingOrNa(e){return e==null||typeof e=="number"&&isNaN(e)?Q1:e}call(e,n,...r){this.pushId(n);try{let i=e(...r);return i===void 0?NaN:i}finally{this.popId()}}callMethod(e,n,r,i,...s){let a=c=>c instanceof y?c.get(0):c,o=a(i);if(o==null||typeof o=="number"&&Number.isNaN(o))return;for(let[c,u]of r)if(Y1(c,u,o))return this.call(c,n,i,...s);let l=o[e];return typeof l=="function"?l.apply(o,s.map(a)):void 0}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,n){let r=`${e}->${n}`;Mi._deprecationWarningsShown.has(r)||(Mi._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,n):console.warn(`\\x1B[33m[WARNING] ${e} syntax is deprecated. Use ${n} instead. This will be removed in a future version.\\x1B[0m`))}};J(Pa,"_deprecationWarningsShown",new Set),J(Pa,"PRECISION_EPSILON",10**10);var Cr=Pa;function pc(t){let e=y.from(t).get(0);if(e==null||typeof e=="number"&&isNaN(e))return["",""];let n=Pn(String(e)),r=n.indexOf(":");return r<0?["",""]:[n.slice(0,r),n.slice(r+1)]}function dc(t){return{...t,param:(e,n=0)=>y.from(e).get(n),__ticker:e=>pc(e)[1],__prefix:e=>pc(e)[0]}}var J1=[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],Lu=[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],ev="\\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",Fu="\\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",Hs={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"},Ks="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",tv={5:Ks,"5module":Ks+" export import",6:Ks+" const class extends export import super"},Vu=/^in(stanceof)?$/,nv=new RegExp("["+Fu+"]"),rv=new RegExp("["+Fu+ev+"]");function Da(t,e){for(var n=65536,r=0;r<e.length;r+=2){if(n+=e[r],n>t)return!1;if(n+=e[r+1],n>=t)return!0}return!1}function on(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&nv.test(String.fromCharCode(t)):e===!1?!1:Da(t,Lu)}function On(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&&rv.test(String.fromCharCode(t)):e===!1?!1:Da(t,Lu)||Da(t,J1)}var oe=function(t,e){e===void 0&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null};function Ct(t,e){return new oe(t,{beforeExpr:!0,binop:e})}var It={beforeExpr:!0},lt={startsExpr:!0},jo={};function ie(t,e){return e===void 0&&(e={}),e.keyword=t,jo[t]=new oe(t,e)}var b={num:new oe("num",lt),regexp:new oe("regexp",lt),string:new oe("string",lt),name:new oe("name",lt),privateId:new oe("privateId",lt),eof:new oe("eof"),bracketL:new oe("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new oe("]"),braceL:new oe("{",{beforeExpr:!0,startsExpr:!0}),braceR:new oe("}"),parenL:new oe("(",{beforeExpr:!0,startsExpr:!0}),parenR:new oe(")"),comma:new oe(",",It),semi:new oe(";",It),colon:new oe(":",It),dot:new oe("."),question:new oe("?",It),questionDot:new oe("?."),arrow:new oe("=>",It),template:new oe("template"),invalidTemplate:new oe("invalidTemplate"),ellipsis:new oe("...",It),backQuote:new oe("`",lt),dollarBraceL:new oe("${",{beforeExpr:!0,startsExpr:!0}),eq:new oe("=",{beforeExpr:!0,isAssign:!0}),assign:new oe("_=",{beforeExpr:!0,isAssign:!0}),incDec:new oe("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new oe("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:Ct("||",1),logicalAND:Ct("&&",2),bitwiseOR:Ct("|",3),bitwiseXOR:Ct("^",4),bitwiseAND:Ct("&",5),equality:Ct("==/!=/===/!==",6),relational:Ct("</>/<=/>=",7),bitShift:Ct("<</>>/>>>",8),plusMin:new oe("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:Ct("%",10),star:Ct("*",10),slash:Ct("/",10),starstar:new oe("**",{beforeExpr:!0}),coalesce:Ct("??",1),_break:ie("break"),_case:ie("case",It),_catch:ie("catch"),_continue:ie("continue"),_debugger:ie("debugger"),_default:ie("default",It),_do:ie("do",{isLoop:!0,beforeExpr:!0}),_else:ie("else",It),_finally:ie("finally"),_for:ie("for",{isLoop:!0}),_function:ie("function",lt),_if:ie("if"),_return:ie("return",It),_switch:ie("switch"),_throw:ie("throw",It),_try:ie("try"),_var:ie("var"),_const:ie("const"),_while:ie("while",{isLoop:!0}),_with:ie("with"),_new:ie("new",{beforeExpr:!0,startsExpr:!0}),_this:ie("this",lt),_super:ie("super",lt),_class:ie("class",lt),_extends:ie("extends",It),_export:ie("export"),_import:ie("import",lt),_null:ie("null",lt),_true:ie("true",lt),_false:ie("false",lt),_in:ie("in",{beforeExpr:!0,binop:7}),_instanceof:ie("instanceof",{beforeExpr:!0,binop:7}),_typeof:ie("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:ie("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:ie("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},ft=/\\r\\n?|\\n|\\u2028|\\u2029/,iv=new RegExp(ft.source,"g");function Ar(t){return t===10||t===13||t===8232||t===8233}function Bu(t,e,n){n===void 0&&(n=t.length);for(var r=e;r<n;r++){var i=t.charCodeAt(r);if(Ar(i))return r<n-1&&i===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var $u=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,Ge=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,ju=Object.prototype,sv=ju.hasOwnProperty,av=ju.toString,Mr=Object.hasOwn||(function(t,e){return sv.call(t,e)}),fc=Array.isArray||(function(t){return av.call(t)==="[object Array]"}),mc=Object.create(null);function Tn(t){return mc[t]||(mc[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function gn(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var ov=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,si=function(t,e){this.line=t,this.column=e};si.prototype.offset=function(t){return new si(this.line,this.column+t)};var fs=function(t,e,n){this.start=e,this.end=n,t.sourceFile!==null&&(this.source=t.sourceFile)};function Wu(t,e){for(var n=1,r=0;;){var i=Bu(t,r,e);if(i<0)return new si(n,e-r);++n,r=i}}var Oa={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},yc=!1;function lv(t){var e={};for(var n in Oa)e[n]=t&&Mr(t,n)?t[n]:Oa[n];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!yc&&typeof console=="object"&&console.warn&&(yc=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=11):e.ecmaVersion>=2015&&(e.ecmaVersion-=2009),e.allowReserved==null&&(e.allowReserved=e.ecmaVersion<5),(!t||t.allowHashBang==null)&&(e.allowHashBang=e.ecmaVersion>=14),fc(e.onToken)){var r=e.onToken;e.onToken=function(i){return r.push(i)}}if(fc(e.onComment)&&(e.onComment=cv(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function cv(t,e){return function(n,r,i,s,a,o){var l={type:n?"Block":"Line",value:r,start:i,end:s};t.locations&&(l.loc=new fs(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var qn=1,Hn=2,Wo=4,Uu=8,Uo=16,qu=32,ms=64,zu=128,Kn=256,hi=512,Hu=1024,ys=qn|Hn|Kn;function qo(t,e){return Hn|(t?Wo:0)|(e?Uu:0)}var Yi=0,zo=1,bn=2,Ku=3,Gu=4,Yu=5,Ve=function(t,e,n){this.options=t=lv(t),this.sourceFile=t.sourceFile,this.keywords=Tn(tv[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var r="";t.allowReserved!==!0&&(r=Hs[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(r+=" await")),this.reservedWords=Tn(r);var i=(r?r+" ":"")+Hs.strict;this.reservedWordsStrict=Tn(i),this.reservedWordsStrictBind=Tn(i+" "+Hs.strictBind),this.input=String(e),this.containsEsc=!1,n?(this.pos=n,this.lineStart=this.input.lastIndexOf(`\n`,n-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(ft).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=b.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=t.sourceType==="module",this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&t.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(this.options.sourceType==="commonjs"?Hn:qn),this.regexpState=null,this.privateNameStack=[]},Dt={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}};Ve.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};Dt.inFunction.get=function(){return(this.currentVarScope().flags&Hn)>0};Dt.inGenerator.get=function(){return(this.currentVarScope().flags&Uu)>0};Dt.inAsync.get=function(){return(this.currentVarScope().flags&Wo)>0};Dt.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(Kn|hi))return!1;if(n&Hn)return(n&Wo)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};Dt.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&qn)};Dt.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&ms)>0||this.options.allowSuperOutsideMethod};Dt.allowDirectSuper.get=function(){return(this.currentThisScope().flags&zu)>0};Dt.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};Dt.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(Kn|hi)||n&Hn&&!(n&Uo))return!0}return!1};Dt.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Hu||!this.inModule&&e&qn)};Dt.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&Kn)>0};Ve.extend=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];for(var n=this,r=0;r<t.length;r++)n=t[r](n);return n};Ve.parse=function(t,e){return new this(e,t).parse()};Ve.parseExpressionAt=function(t,e,n){var r=new this(n,t,e);return r.nextToken(),r.parseExpression()};Ve.tokenizer=function(t,e){return new this(e,t)};Object.defineProperties(Ve.prototype,Dt);var rt=Ve.prototype,uv=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;rt.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){Ge.lastIndex=t,t+=Ge.exec(this.input)[0].length;var e=uv.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){Ge.lastIndex=t+e[0].length;var n=Ge.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===";"||i==="}"||ft.test(n[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,Ge.lastIndex=t,t+=Ge.exec(this.input)[0].length,this.input[t]===";"&&t++}};rt.eat=function(t){return this.type===t?(this.next(),!0):!1};rt.isContextual=function(t){return this.type===b.name&&this.value===t&&!this.containsEsc};rt.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};rt.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};rt.canInsertSemicolon=function(){return this.type===b.eof||this.type===b.braceR||ft.test(this.input.slice(this.lastTokEnd,this.start))};rt.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};rt.semicolon=function(){!this.eat(b.semi)&&!this.insertSemicolon()&&this.unexpected()};rt.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};rt.expect=function(t){this.eat(t)||this.unexpected()};rt.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var gs=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};rt.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var n=e?t.parenthesizedAssign:t.parenthesizedBind;n>-1&&this.raiseRecoverable(n,e?"Assigning to rvalue":"Parenthesized pattern")}};rt.checkExpressionErrors=function(t,e){if(!t)return!1;var n=t.shorthandAssign,r=t.doubleProto;if(!e)return n>=0||r>=0;n>=0&&this.raise(n,"Shorthand property assignments are valid only in destructuring patterns"),r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property")};rt.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")};rt.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var z=Ve.prototype;z.parseTopLevel=function(t){var e=Object.create(null);for(t.body||(t.body=[]);this.type!==b.eof;){var n=this.parseStatement(null,!0,e);t.body.push(n)}if(this.inModule)for(var r=0,i=Object.keys(this.undefinedExports);r<i.length;r+=1){var s=i[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 Ho={kind:"loop"},hv={kind:"switch"};z.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Ge.lastIndex=this.pos;var e=Ge.exec(this.input),n=this.pos+e[0].length,r=this.fullCharCodeAt(n);if(r===91||r===92)return!0;if(t)return!1;if(r===123)return!0;if(on(r)){var i=n;do n+=r<=65535?1:2;while(On(r=this.fullCharCodeAt(n)));if(r===92)return!0;var s=this.input.slice(i,n);if(!Vu.test(s))return!0}return!1};z.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Ge.lastIndex=this.pos;var t=Ge.exec(this.input),e=this.pos+t[0].length,n;return!ft.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(On(n=this.fullCharCodeAt(e+8))||n===92))};z.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;Ge.lastIndex=this.pos;var n=Ge.exec(this.input),r=this.pos+n[0].length;if(ft.test(this.input.slice(this.pos,r)))return!1;if(t){var i=r+5,s;if(this.input.slice(r,i)!=="using"||i===this.input.length||On(s=this.fullCharCodeAt(i))||s===92)return!1;Ge.lastIndex=i;var a=Ge.exec(this.input);if(r=i+a[0].length,a&&ft.test(this.input.slice(i,r)))return!1}var o=this.fullCharCodeAt(r);if(!on(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(On(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(Vu.test(c)||e&&c==="of")};z.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};z.isUsing=function(t){return this.isUsingKeyword(!1,t)};z.parseStatement=function(t,e,n){var r=this.type,i=this.startNode(),s;switch(this.isLet(t)&&(r=b._var,s="let"),r){case b._break:case b._continue:return this.parseBreakContinueStatement(i,r.keyword);case b._debugger:return this.parseDebuggerStatement(i);case b._do:return this.parseDoStatement(i);case b._for:return this.parseForStatement(i);case b._function:return t&&(this.strict||t!=="if"&&t!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(i,!1,!t);case b._class:return t&&this.unexpected(),this.parseClass(i,!0);case b._if:return this.parseIfStatement(i);case b._return:return this.parseReturnStatement(i);case b._switch:return this.parseSwitchStatement(i);case b._throw:return this.parseThrowStatement(i);case b._try:return this.parseTryStatement(i);case b._const:case b._var:return s=s||this.value,t&&s!=="var"&&this.unexpected(),this.parseVarStatement(i,s);case b._while:return this.parseWhileStatement(i);case b._with:return this.parseWithStatement(i);case b.braceL:return this.parseBlock(!0,i);case b.semi:return this.parseEmptyStatement(i);case b._export:case b._import:if(this.options.ecmaVersion>10&&r===b._import){Ge.lastIndex=this.pos;var a=Ge.exec(this.input),o=this.pos+a[0].length,l=this.input.charCodeAt(o);if(l===40||l===46)return this.parseExpressionStatement(i,this.parseExpression())}return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"\'import\' and \'export\' may only appear at the top level"),this.inModule||this.raise(this.start,"\'import\' and \'export\' may appear only with \'sourceType: module\'")),r===b._import?this.parseImport(i):this.parseExport(i,n);default:if(this.isAsyncFunction())return t&&this.unexpected(),this.next(),this.parseFunctionStatement(i,!0,!t);var c=this.isAwaitUsing(!1)?"await using":this.isUsing(!1)?"using":null;if(c)return this.allowUsing||this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script` or in the bare case statement"),c==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.next(),this.parseVar(i,!1,c),this.semicolon(),this.finishNode(i,"VariableDeclaration");var u=this.value,p=this.parseExpression();return r===b.name&&p.type==="Identifier"&&this.eat(b.colon)?this.parseLabeledStatement(i,u,p,t):this.parseExpressionStatement(i,p)}};z.parseBreakContinueStatement=function(t,e){var n=e==="break";this.next(),this.eat(b.semi)||this.insertSemicolon()?t.label=null:this.type!==b.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var i=this.labels[r];if((t.label==null||i.name===t.label.name)&&(i.kind!=null&&(n||i.kind==="loop")||t.label&&n))break}return r===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,n?"BreakStatement":"ContinueStatement")};z.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};z.parseDoStatement=function(t){return this.next(),this.labels.push(Ho),t.body=this.parseStatement("do"),this.labels.pop(),this.expect(b._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(b.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")};z.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(Ho),this.enterScope(0),this.expect(b.parenL),this.type===b.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var n=this.isLet();if(this.type===b._var||this.type===b._const||n){var r=this.startNode(),i=n?"let":this.value;return this.next(),this.parseVar(r,!0,i),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 gs,p=this.start,h=e>-1?this.parseExprSubscripts(u,"await"):this.parseExpression(!0,u);return this.type===b._in||(a=this.options.ecmaVersion>=6&&this.isContextual("of"))?(e>-1?(this.type===b._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))};z.parseForAfterInit=function(t,e,n){return(this.type===b._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&e.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===b._in?n>-1&&this.unexpected(n):t.await=n>-1),this.parseForIn(t,e)):(n>-1&&this.unexpected(n),this.parseFor(t,e))};z.parseFunctionStatement=function(t,e,n){return this.next(),this.parseFunction(t,Gr|(n?0:Ra),!1,e)};z.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement("if"),t.alternate=this.eat(b._else)?this.parseStatement("if"):null,this.finishNode(t,"IfStatement")};z.parseReturnStatement=function(t){return this.allowReturn||this.raise(this.start,"\'return\' outside of function"),this.next(),this.eat(b.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")};z.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(b.braceL),this.labels.push(hv),this.enterScope(Hu);for(var e,n=!1;this.type!==b.braceR;)if(this.type===b._case||this.type===b._default){var r=this.type===b._case;e&&this.finishNode(e,"SwitchCase"),t.cases.push(e=this.startNode()),e.consequent=[],this.next(),r?e.test=this.parseExpression():(n&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),n=!0,e.test=null),this.expect(b.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")};z.parseThrowStatement=function(t){return this.next(),ft.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 pv=[];z.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?qu:0),this.checkLValPattern(t,e?Gu:bn),this.expect(b.parenR),t};z.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===b._catch){var e=this.startNode();this.next(),this.eat(b.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(b._finally)?this.parseBlock():null,!t.handler&&!t.finalizer&&this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")};z.parseVarStatement=function(t,e,n){return this.next(),this.parseVar(t,!1,e,n),this.semicolon(),this.finishNode(t,"VariableDeclaration")};z.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(Ho),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};z.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")};z.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};z.parseLabeledStatement=function(t,e,n,r){for(var i=0,s=this.labels;i<s.length;i+=1){var a=s[i];a.name===e&&this.raise(n.start,"Label \'"+e+"\' is already declared")}for(var o=this.type.isLoop?"loop":this.type===b._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=n,this.finishNode(t,"LabeledStatement")};z.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};z.parseBlock=function(t,e,n){for(t===void 0&&(t=!0),e===void 0&&(e=this.startNode()),e.body=[],this.expect(b.braceL),t&&this.enterScope(0);this.type!==b.braceR;){var r=this.parseStatement(null);e.body.push(r)}return n&&(this.strict=!1),this.next(),t&&this.exitScope(),this.finishNode(e,"BlockStatement")};z.parseFor=function(t,e){return t.init=e,this.expect(b.semi),t.test=this.type===b.semi?null:this.parseExpression(),this.expect(b.semi),t.update=this.type===b.parenR?null:this.parseExpression(),this.expect(b.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,"ForStatement")};z.parseForIn=function(t,e){var n=this.type===b._in;return this.next(),e.type==="VariableDeclaration"&&e.declarations[0].init!=null&&(!n||this.options.ecmaVersion<8||this.strict||e.kind!=="var"||e.declarations[0].id.type!=="Identifier")&&this.raise(e.start,(n?"for-in":"for-of")+" loop variable declaration may not have an initializer"),t.left=e,t.right=n?this.parseExpression():this.parseMaybeAssign(),this.expect(b.parenR),t.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(t,n?"ForInStatement":"ForOfStatement")};z.parseVar=function(t,e,n,r){for(t.declarations=[],t.kind=n;;){var i=this.startNode();if(this.parseVarId(i,n),this.eat(b.eq)?i.init=this.parseMaybeAssign(e):!r&&n==="const"&&!(this.type===b._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!r&&(n==="using"||n==="await using")&&this.options.ecmaVersion>=17&&this.type!==b._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+n+" declaration"):!r&&i.id.type!=="Identifier"&&!(e&&(this.type===b._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):i.init=null,t.declarations.push(this.finishNode(i,"VariableDeclarator")),!this.eat(b.comma))break}return t};z.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?zo:bn,!1)};var Gr=1,Ra=2,Xu=4;z.parseFunction=function(t,e,n,r,i){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===b.star&&e&Ra&&this.unexpected(),t.generator=this.eat(b.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&Gr&&(t.id=e&Xu&&this.type!==b.name?null:this.parseIdent(),t.id&&!(e&Ra)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?zo:bn:Ku));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(qo(t.async,t.generator)),e&Gr||(t.id=this.type===b.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,n,!1,i),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=o,this.finishNode(t,e&Gr?"FunctionDeclaration":"FunctionExpression")};z.parseFunctionParams=function(t){this.expect(b.parenL),t.params=this.parseBindingList(b.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};z.parseClass=function(t,e){this.next();var n=this.strict;this.strict=!0,this.parseClassId(t,e),this.parseClassSuper(t);var r=this.enterClassBody(),i=this.startNode(),s=!1;for(i.body=[],this.expect(b.braceL);this.type!==b.braceR;){var a=this.parseClassElement(t.superClass!==null);a&&(i.body.push(a),a.type==="MethodDefinition"&&a.kind==="constructor"?(s&&this.raiseRecoverable(a.start,"Duplicate constructor in the same class"),s=!0):a.key&&a.key.type==="PrivateIdentifier"&&dv(r,a)&&this.raiseRecoverable(a.key.start,"Identifier \'#"+a.key.name+"\' has already been declared"))}return this.strict=n,this.next(),t.body=this.finishNode(i,"ClassBody"),this.exitClassBody(),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")};z.parseClassElement=function(t){if(this.eat(b.semi))return null;var e=this.options.ecmaVersion,n=this.startNode(),r="",i=!1,s=!1,a="method",o=!1;if(this.eatContextual("static")){if(e>=13&&this.eat(b.braceL))return this.parseClassStaticBlock(n),n;this.isClassElementNameStart()||this.type===b.star?o=!0:r="static"}if(n.static=o,!r&&e>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===b.star)&&!this.canInsertSemicolon()?s=!0:r="async"),!r&&(e>=9||!s)&&this.eat(b.star)&&(i=!0),!r&&!s&&!i){var l=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?a=l:r=l)}if(r?(n.computed=!1,n.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),n.key.name=r,this.finishNode(n.key,"Identifier")):this.parseClassElementName(n),e<13||this.type===b.parenL||a!=="method"||i||s){var c=!n.static&&Xi(n,"constructor"),u=c&&t;c&&a!=="method"&&this.raise(n.key.start,"Constructor can\'t have get/set modifier"),n.kind=c?"constructor":a,this.parseClassMethod(n,i,s,u)}else this.parseClassField(n);return n};z.isClassElementNameStart=function(){return this.type===b.name||this.type===b.privateId||this.type===b.num||this.type===b.string||this.type===b.bracketL||this.type.keyword};z.parseClassElementName=function(t){this.type===b.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)};z.parseClassMethod=function(t,e,n,r){var i=t.key;t.kind==="constructor"?(e&&this.raise(i.start,"Constructor can\'t be a generator"),n&&this.raise(i.start,"Constructor can\'t be an async method")):t.static&&Xi(t,"prototype")&&this.raise(i.start,"Classes may not have a static property named prototype");var s=t.value=this.parseMethod(e,n,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")};z.parseClassField=function(t){return Xi(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&Xi(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(b.eq)?(this.enterScope(hi|ms),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};z.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(Kn|ms);this.type!==b.braceR;){var n=this.parseStatement(null);t.body.push(n)}return this.next(),this.exitScope(),this.labels=e,this.finishNode(t,"StaticBlock")};z.parseClassId=function(t,e){this.type===b.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,bn,!1)):(e===!0&&this.unexpected(),t.id=null)};z.parseClassSuper=function(t){t.superClass=this.eat(b._extends)?this.parseExprSubscripts(null,!1):null};z.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};z.exitClassBody=function(){var t=this.privateNameStack.pop(),e=t.declared,n=t.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,i=r===0?null:this.privateNameStack[r-1],s=0;s<n.length;++s){var a=n[s];Mr(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function dv(t,e){var n=e.key.name,r=t[n],i="true";return e.type==="MethodDefinition"&&(e.kind==="get"||e.kind==="set")&&(i=(e.static?"s":"i")+e.kind),r==="iget"&&i==="iset"||r==="iset"&&i==="iget"||r==="sget"&&i==="sset"||r==="sset"&&i==="sget"?(t[n]="true",!1):r?!0:(t[n]=i,!1)}function Xi(t,e){var n=t.computed,r=t.key;return!n&&(r.type==="Identifier"&&r.name===e||r.type==="Literal"&&r.value===e)}z.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!==b.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ExportAllDeclaration")};z.parseExport=function(t,e){if(this.next(),this.eat(b.star))return this.parseExportAllDeclaration(t,e);if(this.eat(b._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!==b.string&&this.unexpected(),t.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause());else{for(var n=0,r=t.specifiers;n<r.length;n+=1){var i=r[n];this.checkUnreserved(i.local),this.checkLocalExport(i.local),i.local.type==="Literal"&&this.raise(i.local.start,"A string literal cannot be used as an exported binding without `from`.")}t.source=null,this.options.ecmaVersion>=16&&(t.attributes=[])}this.semicolon()}return this.finishNode(t,"ExportNamedDeclaration")};z.parseExportDeclaration=function(t){return this.parseStatement(null)};z.parseExportDefaultDeclaration=function(){var t;if(this.type===b._function||(t=this.isAsyncFunction())){var e=this.startNode();return this.next(),t&&this.next(),this.parseFunction(e,Gr|Xu,!1,t)}else if(this.type===b._class){var n=this.startNode();return this.parseClass(n,"nullableID")}else{var r=this.parseMaybeAssign();return this.semicolon(),r}};z.checkExport=function(t,e,n){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),Mr(t,e)&&this.raiseRecoverable(n,"Duplicate export \'"+e+"\'"),t[e]=!0)};z.checkPatternExport=function(t,e){var n=e.type;if(n==="Identifier")this.checkExport(t,e,e.start);else if(n==="ObjectPattern")for(var r=0,i=e.properties;r<i.length;r+=1){var s=i[r];this.checkPatternExport(t,s)}else if(n==="ArrayPattern")for(var a=0,o=e.elements;a<o.length;a+=1){var l=o[a];l&&this.checkPatternExport(t,l)}else n==="Property"?this.checkPatternExport(t,e.value):n==="AssignmentPattern"?this.checkPatternExport(t,e.left):n==="RestElement"&&this.checkPatternExport(t,e.argument)};z.checkVariableExport=function(t,e){if(t)for(var n=0,r=e;n<r.length;n+=1){var i=r[n];this.checkPatternExport(t,i.id)}};z.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};z.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")};z.parseExportSpecifiers=function(t){var e=[],n=!0;for(this.expect(b.braceL);!this.eat(b.braceR);){if(n)n=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;e.push(this.parseExportSpecifier(t))}return e};z.parseImport=function(t){return this.next(),this.type===b.string?(t.specifiers=pv,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===b.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(t.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(t,"ImportDeclaration")};z.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,bn),this.finishNode(t,"ImportSpecifier")};z.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,bn),this.finishNode(t,"ImportDefaultSpecifier")};z.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,bn),this.finishNode(t,"ImportNamespaceSpecifier")};z.parseImportSpecifiers=function(){var t=[],e=!0;if(this.type===b.name&&(t.push(this.parseImportDefaultSpecifier()),!this.eat(b.comma)))return t;if(this.type===b.star)return t.push(this.parseImportNamespaceSpecifier()),t;for(this.expect(b.braceL);!this.eat(b.braceR);){if(e)e=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;t.push(this.parseImportSpecifier())}return t};z.parseWithClause=function(){var t=[];if(!this.eat(b._with))return t;this.expect(b.braceL);for(var e={},n=!0;!this.eat(b.braceR);){if(n)n=!1;else if(this.expect(b.comma),this.afterTrailingComma(b.braceR))break;var r=this.parseImportAttribute(),i=r.key.type==="Identifier"?r.key.name:r.key.value;Mr(e,i)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key \'"+i+"\'"),e[i]=!0,t.push(r)}return t};z.parseImportAttribute=function(){var t=this.startNode();return t.key=this.type===b.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(b.colon),this.type!==b.string&&this.unexpected(),t.value=this.parseExprAtom(),this.finishNode(t,"ImportAttribute")};z.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===b.string){var t=this.parseLiteral(this.value);return ov.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};z.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)};z.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 Ot=Ve.prototype;Ot.toAssignable=function(t,e,n){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",n&&this.checkPatternErrors(n,!0);for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[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",n&&this.checkPatternErrors(n,!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,n);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 n&&this.checkPatternErrors(n,!0);return t};Ot.toAssignableList=function(t,e){for(var n=t.length,r=0;r<n;r++){var i=t[r];i&&this.toAssignable(i,e)}if(n){var s=t[n-1];this.options.ecmaVersion===6&&e&&s&&s.type==="RestElement"&&s.argument.type!=="Identifier"&&this.unexpected(s.argument.start)}return t};Ot.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};Ot.parseRestBinding=function(){var t=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==b.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")};Ot.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case b.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(b.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case b.braceL:return this.parseObj(!0)}return this.parseIdent()};Ot.parseBindingList=function(t,e,n,r){for(var i=[],s=!0;!this.eat(t);)if(s?s=!1:this.expect(b.comma),e&&this.type===b.comma)i.push(null);else{if(n&&this.afterTrailingComma(t))break;if(this.type===b.ellipsis){var a=this.parseRestBinding();this.parseBindingListItem(a),i.push(a),this.type===b.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(t);break}else i.push(this.parseAssignableListItem(r))}return i};Ot.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};Ot.parseBindingListItem=function(t){return t};Ot.parseMaybeDefault=function(t,e,n){if(n=n||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(b.eq))return n;var r=this.startNodeAt(t,e);return r.left=n,r.right=this.parseMaybeAssign(),this.finishNode(r,"AssignmentPattern")};Ot.checkLValSimple=function(t,e,n){e===void 0&&(e=Yi);var r=e!==Yi;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===bn&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),n&&(Mr(n,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),n[t.name]=!0),e!==Yu&&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,n);default:this.raise(t.start,(r?"Binding":"Assigning to")+" rvalue")}};Ot.checkLValPattern=function(t,e,n){switch(e===void 0&&(e=Yi),t.type){case"ObjectPattern":for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];this.checkLValInnerPattern(s,e,n)}break;case"ArrayPattern":for(var a=0,o=t.elements;a<o.length;a+=1){var l=o[a];l&&this.checkLValInnerPattern(l,e,n)}break;default:this.checkLValSimple(t,e,n)}};Ot.checkLValInnerPattern=function(t,e,n){switch(e===void 0&&(e=Yi),t.type){case"Property":this.checkLValInnerPattern(t.value,e,n);break;case"AssignmentPattern":this.checkLValPattern(t.left,e,n);break;case"RestElement":this.checkLValPattern(t.argument,e,n);break;default:this.checkLValPattern(t,e,n)}};var Vt=function(t,e,n,r,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!n,this.override=r,this.generator=!!i},Ie={b_stat:new Vt("{",!1),b_expr:new Vt("{",!0),b_tmpl:new Vt("${",!1),p_stat:new Vt("(",!1),p_expr:new Vt("(",!0),q_tmpl:new Vt("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new Vt("function",!1),f_expr:new Vt("function",!0),f_expr_gen:new Vt("function",!0,!1,null,!0),f_gen:new Vt("function",!1,!1,null,!0)},Tr=Ve.prototype;Tr.initialContext=function(){return[Ie.b_stat]};Tr.curContext=function(){return this.context[this.context.length-1]};Tr.braceIsBlock=function(t){var e=this.curContext();return e===Ie.f_expr||e===Ie.f_stat?!0:t===b.colon&&(e===Ie.b_stat||e===Ie.b_expr)?!e.isExpr:t===b._return||t===b.name&&this.exprAllowed?ft.test(this.input.slice(this.lastTokEnd,this.start)):t===b._else||t===b.semi||t===b.eof||t===b.parenR||t===b.arrow?!0:t===b.braceL?e===Ie.b_stat:t===b._var||t===b._const||t===b.name?!1:!this.exprAllowed};Tr.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};Tr.updateContext=function(t){var e,n=this.type;n.keyword&&t===b.dot?this.exprAllowed=!1:(e=n.updateContext)?e.call(this,t):this.exprAllowed=n.beforeExpr};Tr.overrideContext=function(t){this.curContext()!==t&&(this.context[this.context.length-1]=t)};b.parenR.updateContext=b.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var t=this.context.pop();t===Ie.b_stat&&this.curContext().token==="function"&&(t=this.context.pop()),this.exprAllowed=!t.isExpr};b.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?Ie.b_stat:Ie.b_expr),this.exprAllowed=!0};b.dollarBraceL.updateContext=function(){this.context.push(Ie.b_tmpl),this.exprAllowed=!0};b.parenL.updateContext=function(t){var e=t===b._if||t===b._for||t===b._with||t===b._while;this.context.push(e?Ie.p_stat:Ie.p_expr),this.exprAllowed=!0};b.incDec.updateContext=function(){};b._function.updateContext=b._class.updateContext=function(t){t.beforeExpr&&t!==b._else&&!(t===b.semi&&this.curContext()!==Ie.p_stat)&&!(t===b._return&&ft.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===b.colon||t===b.braceL)&&this.curContext()===Ie.b_stat)?this.context.push(Ie.f_expr):this.context.push(Ie.f_stat),this.exprAllowed=!1};b.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};b.backQuote.updateContext=function(){this.curContext()===Ie.q_tmpl?this.context.pop():this.context.push(Ie.q_tmpl),this.exprAllowed=!1};b.star.updateContext=function(t){if(t===b._function){var e=this.context.length-1;this.context[e]===Ie.f_expr?this.context[e]=Ie.f_expr_gen:this.context[e]=Ie.f_gen}this.exprAllowed=!0};b.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&t!==b.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var Z=Ve.prototype;Z.checkPropClash=function(t,e,n){if(!(this.options.ecmaVersion>=9&&t.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var r=t.key,i;switch(r.type){case"Identifier":i=r.name;break;case"Literal":i=String(r.value);break;default:return}var s=t.kind;if(this.options.ecmaVersion>=6){i==="__proto__"&&s==="init"&&(e.proto&&(n?n.doubleProto<0&&(n.doubleProto=r.start):this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0);return}i="$"+i;var a=e[i];if(a){var o;s==="init"?o=this.strict&&a.init||a.get||a.set:o=a.init||a[s],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else a=e[i]={init:!1,get:!1,set:!1};a[s]=!0}};Z.parseExpression=function(t,e){var n=this.start,r=this.startLoc,i=this.parseMaybeAssign(t,e);if(this.type===b.comma){var s=this.startNodeAt(n,r);for(s.expressions=[i];this.eat(b.comma);)s.expressions.push(this.parseMaybeAssign(t,e));return this.finishNode(s,"SequenceExpression")}return i};Z.parseMaybeAssign=function(t,e,n){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(t);this.exprAllowed=!1}var r=!1,i=-1,s=-1,a=-1;e?(i=e.parenthesizedAssign,s=e.trailingComma,a=e.doubleProto,e.parenthesizedAssign=e.trailingComma=-1):(e=new gs,r=!0);var o=this.start,l=this.startLoc;(this.type===b.parenL||this.type===b.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=t==="await");var c=this.parseMaybeConditional(t,e);if(n&&(c=n.call(this,c,o,l)),this.type.isAssign){var u=this.startNodeAt(o,l);return u.operator=this.value,this.type===b.eq&&(c=this.toAssignable(c,!1,e)),r||(e.parenthesizedAssign=e.trailingComma=e.doubleProto=-1),e.shorthandAssign>=c.start&&(e.shorthandAssign=-1),this.type===b.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 i>-1&&(e.parenthesizedAssign=i),s>-1&&(e.trailingComma=s),c};Z.parseMaybeConditional=function(t,e){var n=this.start,r=this.startLoc,i=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return i;if(this.eat(b.question)){var s=this.startNodeAt(n,r);return s.test=i,s.consequent=this.parseMaybeAssign(),this.expect(b.colon),s.alternate=this.parseMaybeAssign(t),this.finishNode(s,"ConditionalExpression")}return i};Z.parseExprOps=function(t,e){var n=this.start,r=this.startLoc,i=this.parseMaybeUnary(e,!1,!1,t);return this.checkExpressionErrors(e)||i.start===n&&i.type==="ArrowFunctionExpression"?i:this.parseExprOp(i,n,r,-1,t)};Z.parseExprOp=function(t,e,n,r,i){var s=this.type.binop;if(s!=null&&(!i||this.type!==b._in)&&s>r){var a=this.type===b.logicalOR||this.type===b.logicalAND,o=this.type===b.coalesce;o&&(s=b.logicalAND.binop);var l=this.value;this.next();var c=this.start,u=this.startLoc,p=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,i),c,u,s,i),h=this.buildBinary(e,n,t,p,l,a||o);return(a&&this.type===b.coalesce||o&&(this.type===b.logicalOR||this.type===b.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(h,e,n,r,i)}return t};Z.buildBinary=function(t,e,n,r,i,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=n,a.operator=i,a.right=r,this.finishNode(a,s?"LogicalExpression":"BinaryExpression")};Z.parseMaybeUnary=function(t,e,n,r){var i=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===b.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"&&Zu(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&La(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===b.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),a=this.parsePrivateIdent(),this.type!==b._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(i,s);c.operator=this.value,c.prefix=!1,c.argument=a,this.checkLValSimple(a),this.next(),a=this.finishNode(c,"UpdateExpression")}}if(!n&&this.eat(b.starstar))if(e)this.unexpected(this.lastTokStart);else return this.buildBinary(i,s,a,this.parseMaybeUnary(null,!1,!1,r),"**",!1);else return a};function Zu(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&Zu(t.expression)}function La(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&La(t.expression)||t.type==="ParenthesizedExpression"&&La(t.expression)}Z.parseExprSubscripts=function(t,e){var n=this.start,r=this.startLoc,i=this.parseExprAtom(t,e);if(i.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return i;var s=this.parseSubscripts(i,n,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};Z.parseSubscripts=function(t,e,n,r,i){for(var s=this.options.ecmaVersion>=8&&t.type==="Identifier"&&t.name==="async"&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&t.end-t.start===5&&this.potentialArrowAt===t.start,a=!1;;){var o=this.parseSubscript(t,e,n,r,s,a,i);if(o.optional&&(a=!0),o===t||o.type==="ArrowFunctionExpression"){if(a){var l=this.startNodeAt(e,n);l.expression=o,o=this.finishNode(l,"ChainExpression")}return o}t=o}};Z.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(b.arrow)};Z.parseSubscriptAsyncArrow=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!0,r)};Z.parseSubscript=function(t,e,n,r,i,s,a){var o=this.options.ecmaVersion>=11,l=o&&this.eat(b.questionDot);r&&l&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(b.bracketL);if(c||l&&this.type!==b.parenL&&this.type!==b.backQuote||this.eat(b.dot)){var u=this.startNodeAt(e,n);u.object=t,c?(u.property=this.parseExpression(),this.expect(b.bracketR)):this.type===b.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(b.parenL)){var p=new gs,h=this.yieldPos,d=this.awaitPos,f=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var m=this.parseExprList(b.parenR,this.options.ecmaVersion>=8,!1,p);if(i&&!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=d,this.awaitIdentPos=f,this.parseSubscriptAsyncArrow(e,n,m,a);this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=d||this.awaitPos,this.awaitIdentPos=f||this.awaitIdentPos;var _=this.startNodeAt(e,n);_.callee=t,_.arguments=m,o&&(_.optional=l),t=this.finishNode(_,"CallExpression")}else if(this.type===b.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var x=this.startNodeAt(e,n);x.tag=t,x.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(x,"TaggedTemplateExpression")}return t};Z.parseExprAtom=function(t,e,n){this.type===b.slash&&this.readRegexp();var r,i=this.potentialArrowAt===this.start;switch(this.type){case b._super:return this.allowSuper||this.raise(this.start,"\'super\' keyword outside a method"),r=this.startNode(),this.next(),this.type===b.parenL&&!this.allowDirectSuper&&this.raise(r.start,"super() call outside constructor of a subclass"),this.type!==b.dot&&this.type!==b.bracketL&&this.type!==b.parenL&&this.unexpected(),this.finishNode(r,"Super");case b._this:return r=this.startNode(),this.next(),this.finishNode(r,"ThisExpression");case b.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(b._function))return this.overrideContext(Ie.f_expr),this.parseFunction(this.startNodeAt(s,a),0,!1,!0,e);if(i&&!this.canInsertSemicolon()){if(this.eat(b.arrow))return this.parseArrowExpression(this.startNodeAt(s,a),[l],!1,e);if(this.options.ecmaVersion>=8&&l.name==="async"&&this.type===b.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return l=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(b.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,a),[l],!0,e)}return l;case b.regexp:var c=this.value;return r=this.parseLiteral(c.value),r.regex={pattern:c.pattern,flags:c.flags},r;case b.num:case b.string:return this.parseLiteral(this.value);case b._null:case b._true:case b._false:return r=this.startNode(),r.value=this.type===b._null?null:this.type===b._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,"Literal");case b.parenL:var u=this.start,p=this.parseParenAndDistinguishExpression(i,e);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=u),t.parenthesizedBind<0&&(t.parenthesizedBind=u)),p;case b.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(b.bracketR,!0,!0,t),this.finishNode(r,"ArrayExpression");case b.braceL:return this.overrideContext(Ie.b_expr),this.parseObj(!1,t);case b._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case b._class:return this.parseClass(this.startNode(),!1);case b._new:return this.parseNew();case b.backQuote:return this.parseTemplate();case b._import:return this.options.ecmaVersion>=11?this.parseExprImport(n):this.unexpected();default:return this.parseExprAtomDefault()}};Z.parseExprAtomDefault=function(){this.unexpected()};Z.parseExprImport=function(t){var e=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===b.parenL&&!t)return this.parseDynamicImport(e);if(this.type===b.dot){var n=this.startNodeAt(e.start,e.loc&&e.loc.start);return n.name="import",e.meta=this.finishNode(n,"Identifier"),this.parseImportMeta(e)}else this.unexpected()};Z.parseDynamicImport=function(t){if(this.next(),t.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(b.parenR)?t.options=null:(this.expect(b.comma),this.afterTrailingComma(b.parenR)?t.options=null:(t.options=this.parseMaybeAssign(),this.eat(b.parenR)||(this.expect(b.comma),this.afterTrailingComma(b.parenR)||this.unexpected())));else if(!this.eat(b.parenR)){var e=this.start;this.eat(b.comma)&&this.eat(b.parenR)?this.raiseRecoverable(e,"Trailing comma is not allowed in import()"):this.unexpected(e)}return this.finishNode(t,"ImportExpression")};Z.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")};Z.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")};Z.parseParenExpression=function(){this.expect(b.parenL);var t=this.parseExpression();return this.expect(b.parenR),t};Z.shouldParseArrow=function(t){return!this.canInsertSemicolon()};Z.parseParenAndDistinguishExpression=function(t,e){var n=this.start,r=this.startLoc,i,s=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var a=this.start,o=this.startLoc,l=[],c=!0,u=!1,p=new gs,h=this.yieldPos,d=this.awaitPos,f;for(this.yieldPos=0,this.awaitPos=0;this.type!==b.parenR;)if(c?c=!1:this.expect(b.comma),s&&this.afterTrailingComma(b.parenR,!0)){u=!0;break}else if(this.type===b.ellipsis){f=this.start,l.push(this.parseParenItem(this.parseRestBinding())),this.type===b.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,_=this.lastTokEndLoc;if(this.expect(b.parenR),t&&this.shouldParseArrow(l)&&this.eat(b.arrow))return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=h,this.awaitPos=d,this.parseParenArrowList(n,r,l,e);(!l.length||u)&&this.unexpected(this.lastTokStart),f&&this.unexpected(f),this.checkExpressionErrors(p,!0),this.yieldPos=h||this.yieldPos,this.awaitPos=d||this.awaitPos,l.length>1?(i=this.startNodeAt(a,o),i.expressions=l,this.finishNodeAt(i,"SequenceExpression",m,_)):i=l[0]}else i=this.parseParenExpression();if(this.options.preserveParens){var x=this.startNodeAt(n,r);return x.expression=i,this.finishNode(x,"ParenthesizedExpression")}else return i};Z.parseParenItem=function(t){return t};Z.parseParenArrowList=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!1,r)};var fv=[];Z.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===b.dot){var e=this.startNodeAt(t.start,t.loc&&t.loc.start);e.name="new",t.meta=this.finishNode(e,"Identifier"),this.next();var n=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\'"),n&&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,i=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,i,!0,!1),this.eat(b.parenL)?t.arguments=this.parseExprList(b.parenR,this.options.ecmaVersion>=8,!1):t.arguments=fv,this.finishNode(t,"NewExpression")};Z.parseTemplateElement=function(t){var e=t.isTagged,n=this.startNode();return this.type===b.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),n.value={raw:this.value.replace(/\\r\\n?/g,`\n`),cooked:null}):n.value={raw:this.input.slice(this.start,this.end).replace(/\\r\\n?/g,`\n`),cooked:this.value},this.next(),n.tail=this.type===b.backQuote,this.finishNode(n,"TemplateElement")};Z.parseTemplate=function(t){t===void 0&&(t={});var e=t.isTagged;e===void 0&&(e=!1);var n=this.startNode();this.next(),n.expressions=[];var r=this.parseTemplateElement({isTagged:e});for(n.quasis=[r];!r.tail;)this.type===b.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(b.dollarBraceL),n.expressions.push(this.parseExpression()),this.expect(b.braceR),n.quasis.push(r=this.parseTemplateElement({isTagged:e}));return this.next(),this.finishNode(n,"TemplateLiteral")};Z.isAsyncProp=function(t){return!t.computed&&t.key.type==="Identifier"&&t.key.name==="async"&&(this.type===b.name||this.type===b.num||this.type===b.string||this.type===b.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===b.star)&&!ft.test(this.input.slice(this.lastTokEnd,this.start))};Z.parseObj=function(t,e){var n=this.startNode(),r=!0,i={};for(n.properties=[],this.next();!this.eat(b.braceR);){if(r)r=!1;else if(this.expect(b.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(b.braceR))break;var s=this.parseProperty(t,e);t||this.checkPropClash(s,i,e),n.properties.push(s)}return this.finishNode(n,t?"ObjectPattern":"ObjectExpression")};Z.parseProperty=function(t,e){var n=this.startNode(),r,i,s,a;if(this.options.ecmaVersion>=9&&this.eat(b.ellipsis))return t?(n.argument=this.parseIdent(!1),this.type===b.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(n,"RestElement")):(n.argument=this.parseMaybeAssign(!1,e),this.type===b.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(n,"SpreadElement"));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(t||e)&&(s=this.start,a=this.startLoc),t||(r=this.eat(b.star)));var o=this.containsEsc;return this.parsePropertyName(n),!t&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(n)?(i=!0,r=this.options.ecmaVersion>=9&&this.eat(b.star),this.parsePropertyName(n)):i=!1,this.parsePropertyValue(n,t,r,i,s,a,e,o),this.finishNode(n,"Property")};Z.parseGetterSetter=function(t){var e=t.key.name;this.parsePropertyName(t),t.value=this.parseMethod(!1),t.kind=e;var n=t.kind==="get"?0:1;if(t.value.params.length!==n){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")};Z.parsePropertyValue=function(t,e,n,r,i,s,a,o){(n||r)&&this.type===b.colon&&this.unexpected(),this.eat(b.colon)?(t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,a),t.kind="init"):this.options.ecmaVersion>=6&&this.type===b.parenL?(e&&this.unexpected(),t.method=!0,t.value=this.parseMethod(n,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!==b.comma&&this.type!==b.braceR&&this.type!==b.eq?((n||r)&&this.unexpected(),this.parseGetterSetter(t)):this.options.ecmaVersion>=6&&!t.computed&&t.key.type==="Identifier"?((n||r)&&this.unexpected(),this.checkUnreserved(t.key),t.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=i),e?t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key)):this.type===b.eq&&a?(a.shorthandAssign<0&&(a.shorthandAssign=this.start),t.value=this.parseMaybeDefault(i,s,this.copyNode(t.key))):t.value=this.copyNode(t.key),t.kind="init",t.shorthand=!0):this.unexpected()};Z.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(b.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(b.bracketR),t.key;t.computed=!1}return t.key=this.type===b.num||this.type===b.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};Z.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};Z.parseMethod=function(t,e,n){var r=this.startNode(),i=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(qo(e,r.generator)|ms|(n?zu:0)),this.expect(b.parenL),r.params=this.parseBindingList(b.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(r,"FunctionExpression")};Z.parseArrowExpression=function(t,e,n,r){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(qo(n,!1)|Uo),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!n),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0,!1,r),this.yieldPos=i,this.awaitPos=s,this.awaitIdentPos=a,this.finishNode(t,"ArrowFunctionExpression")};Z.parseFunctionBody=function(t,e,n,r){var i=e&&this.type!==b.braceL,s=this.strict,a=!1;if(i)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&&!n&&this.isSimpleParamList(t.params)),this.strict&&t.id&&this.checkLValSimple(t.id,Yu),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};Z.isSimpleParamList=function(t){for(var e=0,n=t;e<n.length;e+=1){var r=n[e];if(r.type!=="Identifier")return!1}return!0};Z.checkParams=function(t,e){for(var n=Object.create(null),r=0,i=t.params;r<i.length;r+=1){var s=i[r];this.checkLValInnerPattern(s,zo,e?null:n)}};Z.parseExprList=function(t,e,n,r){for(var i=[],s=!0;!this.eat(t);){if(s)s=!1;else if(this.expect(b.comma),e&&this.afterTrailingComma(t))break;var a=void 0;n&&this.type===b.comma?a=null:this.type===b.ellipsis?(a=this.parseSpread(r),r&&this.type===b.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):a=this.parseMaybeAssign(!1,r),i.push(a)}return i};Z.checkUnreserved=function(t){var e=t.start,n=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&ys)&&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,n).indexOf("\\\\")!==-1)){var i=this.strict?this.reservedWordsStrict:this.reservedWords;i.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"))}};Z.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};Z.parseIdentNode=function(){var t=this.startNode();return this.type===b.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=b.name):this.unexpected(),t};Z.parsePrivateIdent=function(){var t=this.startNode();return this.type===b.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};Z.parseYield=function(t){this.yieldPos||(this.yieldPos=this.start);var e=this.startNode();return this.next(),this.type===b.semi||this.canInsertSemicolon()||this.type!==b.star&&!this.type.startsExpr?(e.delegate=!1,e.argument=null):(e.delegate=this.eat(b.star),e.argument=this.parseMaybeAssign(t)),this.finishNode(e,"YieldExpression")};Z.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=Ve.prototype;Zi.raise=function(t,e){var n=Wu(this.input,t);e+=" ("+n.line+":"+n.column+")",this.sourceFile&&(e+=" in "+this.sourceFile);var r=new SyntaxError(e);throw r.pos=t,r.loc=n,r.raisedAt=this.pos,r};Zi.raiseRecoverable=Zi.raise;Zi.curPosition=function(){if(this.options.locations)return new si(this.curLine,this.pos-this.lineStart)};var Ln=Ve.prototype,mv=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};Ln.enterScope=function(t){this.scopeStack.push(new mv(t))};Ln.exitScope=function(){this.scopeStack.pop()};Ln.treatFunctionsAsVarInScope=function(t){return t.flags&Hn||!this.inModule&&t.flags&qn};Ln.declareName=function(t,e,n){var r=!1;if(e===bn){var i=this.currentScope();r=i.lexical.indexOf(t)>-1||i.functions.indexOf(t)>-1||i.var.indexOf(t)>-1,i.lexical.push(t),this.inModule&&i.flags&qn&&delete this.undefinedExports[t]}else if(e===Gu){var s=this.currentScope();s.lexical.push(t)}else if(e===Ku){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&qu&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&qn&&delete this.undefinedExports[t],l.flags&ys)break}r&&this.raiseRecoverable(n,"Identifier \'"+t+"\' has already been declared")};Ln.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};Ln.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};Ln.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(ys|hi|Kn))return e}};Ln.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(ys|hi|Kn)&&!(e.flags&Uo))return e}};var _s=function(t,e,n){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new fs(t,n)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},pi=Ve.prototype;pi.startNode=function(){return new _s(this,this.start,this.startLoc)};pi.startNodeAt=function(t,e){return new _s(this,t,e)};function Qu(t,e,n,r){return t.type=e,t.end=n,this.options.locations&&(t.loc.end=r),this.options.ranges&&(t.range[1]=n),t}pi.finishNode=function(t,e){return Qu.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};pi.finishNodeAt=function(t,e,n,r){return Qu.call(this,t,e,n,r)};pi.copyNode=function(t){var e=new _s(this,t.start,this.startLoc);for(var n in t)e[n]=t[n];return e};var yv="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",Ju="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",eh=Ju+" Extended_Pictographic",th=eh,nh=th+" EBase EComp EMod EPres ExtPict",rh=nh,gv=rh,_v={9:Ju,10:eh,11:th,12:nh,13:rh,14:gv},xv="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",bv={9:"",10:"",11:"",12:"",13:"",14:xv},gc="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",ih="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",sh=ih+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",ah=sh+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",oh=ah+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",lh=oh+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",vv=lh+" "+yv,wv={9:ih,10:sh,11:ah,12:oh,13:lh,14:vv},ch={};function Sv(t){var e=ch[t]={binary:Tn(_v[t]+" "+gc),binaryOfStrings:Tn(bv[t]),nonBinary:{General_Category:Tn(gc),Script:Tn(wv[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(Ei=0,Gs=[9,10,11,12,13,14];Ei<Gs.length;Ei+=1)_c=Gs[Ei],Sv(_c);var _c,Ei,Gs,q=Ve.prototype,Qi=function(t,e){this.parent=t,this.base=e||this};Qi.prototype.separatedFrom=function(t){for(var e=this;e;e=e.parent)for(var n=t;n;n=n.parent)if(e.base===n.base&&e!==n)return!0;return!1};Qi.prototype.sibling=function(){return new Qi(this.parent,this.base)};var ln=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":"")+(t.options.ecmaVersion>=13?"d":"")+(t.options.ecmaVersion>=15?"v":""),this.unicodeProperties=ch[t.options.ecmaVersion>=14?14:t.options.ecmaVersion],this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};ln.prototype.reset=function(t,e,n){var r=n.indexOf("v")!==-1,i=n.indexOf("u")!==-1;this.start=t|0,this.source=e+"",this.flags=n,r&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=i&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=i&&this.parser.options.ecmaVersion>=9)};ln.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};ln.prototype.at=function(t,e){e===void 0&&(e=!1);var n=this.source,r=n.length;if(t>=r)return-1;var i=n.charCodeAt(t);if(!(e||this.switchU)||i<=55295||i>=57344||t+1>=r)return i;var s=n.charCodeAt(t+1);return s>=56320&&s<=57343?(i<<10)+s-56613888:i};ln.prototype.nextIndex=function(t,e){e===void 0&&(e=!1);var n=this.source,r=n.length;if(t>=r)return r;var i=n.charCodeAt(t),s;return!(e||this.switchU)||i<=55295||i>=57344||t+1>=r||(s=n.charCodeAt(t+1))<56320||s>57343?t+1:t+2};ln.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};ln.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};ln.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};ln.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};ln.prototype.eatChars=function(t,e){e===void 0&&(e=!1);for(var n=this.pos,r=0,i=t;r<i.length;r+=1){var s=i[r],a=this.at(n,e);if(a===-1||a!==s)return!1;n=this.nextIndex(n,e)}return this.pos=n,!0};q.validateRegExpFlags=function(t){for(var e=t.validFlags,n=t.flags,r=!1,i=!1,s=0;s<n.length;s++){var a=n.charAt(s);e.indexOf(a)===-1&&this.raise(t.start,"Invalid regular expression flag"),n.indexOf(a,s+1)>-1&&this.raise(t.start,"Duplicate regular expression flag"),a==="u"&&(r=!0),a==="v"&&(i=!0)}this.options.ecmaVersion>=15&&r&&i&&this.raise(t.start,"Invalid regular expression flag")};function Ev(t){for(var e in t)return!0;return!1}q.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Ev(t.groupNames)&&(t.switchN=!0,this.regexp_pattern(t))};q.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,n=t.backReferenceNames;e<n.length;e+=1){var r=n[e];t.groupNames[r]||t.raise("Invalid named capture referenced")}};q.regexp_disjunction=function(t){var e=this.options.ecmaVersion>=16;for(e&&(t.branchID=new Qi(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")};q.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););};q.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};q.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 n=!1;if(this.options.ecmaVersion>=9&&(n=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!n,!0}return t.pos=e,!1};q.regexp_eatQuantifier=function(t,e){return e===void 0&&(e=!1),this.regexp_eatQuantifierPrefix(t,e)?(t.eat(63),!0):!1};q.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)};q.regexp_eatBracedQuantifier=function(t,e){var n=t.pos;if(t.eat(123)){var r=0,i=-1;if(this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(i=t.lastIntValue),t.eat(125)))return i!==-1&&i<r&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=n}return!1};q.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)};q.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1};q.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)){if(this.options.ecmaVersion>=16){var n=this.regexp_eatModifiers(t),r=t.eat(45);if(n||r){for(var i=0;i<n.length;i++){var s=n.charAt(i);n.indexOf(s,i+1)>-1&&t.raise("Duplicate regular expression modifiers")}if(r){var a=this.regexp_eatModifiers(t);!n&&!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||n.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};q.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};q.regexp_eatModifiers=function(t){for(var e="",n=0;(n=t.current())!==-1&&Nv(n);)e+=gn(n),t.advance();return e};function Nv(t){return t===105||t===109||t===115}q.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)};q.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1};q.regexp_eatSyntaxCharacter=function(t){var e=t.current();return uh(e)?(t.lastIntValue=e,t.advance(),!0):!1};function uh(t){return t===36||t>=40&&t<=43||t===46||t===63||t>=91&&t<=94||t>=123&&t<=125}q.regexp_eatPatternCharacters=function(t){for(var e=t.pos,n=0;(n=t.current())!==-1&&!uh(n);)t.advance();return t.pos!==e};q.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};q.regexp_groupSpecifier=function(t){if(t.eat(63)){this.regexp_eatGroupName(t)||t.raise("Invalid group");var e=this.options.ecmaVersion>=16,n=t.groupNames[t.lastStringValue];if(n)if(e)for(var r=0,i=n;r<i.length;r+=1){var s=i[r];s.separatedFrom(t.branchID)||t.raise("Duplicate capture group name")}else t.raise("Duplicate capture group name");e?(n||(t.groupNames[t.lastStringValue]=[])).push(t.branchID):t.groupNames[t.lastStringValue]=!0}};q.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};q.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=gn(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=gn(t.lastIntValue);return!0}return!1};q.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,n=this.options.ecmaVersion>=11,r=t.current(n);return t.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,n)&&(r=t.lastIntValue),Cv(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function Cv(t){return on(t,!0)||t===36||t===95}q.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,n=this.options.ecmaVersion>=11,r=t.current(n);return t.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(t,n)&&(r=t.lastIntValue),Iv(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function Iv(t){return On(t,!0)||t===36||t===95||t===8204||t===8205}q.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)};q.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var n=t.lastIntValue;if(t.switchU)return n>t.maxBackReference&&(t.maxBackReference=n),!0;if(n<=t.numCapturingParens)return!0;t.pos=e}return!1};q.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};q.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)};q.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1};q.regexp_eatZero=function(t){return t.current()===48&&!xs(t.lookahead())?(t.lastIntValue=0,t.advance(),!0):!1};q.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};q.regexp_eatControlLetter=function(t){var e=t.current();return hh(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function hh(t){return t>=65&&t<=90||t>=97&&t<=122}q.regexp_eatRegExpUnicodeEscapeSequence=function(t,e){e===void 0&&(e=!1);var n=t.pos,r=e||t.switchU;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(r&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var a=t.lastIntValue;if(a>=56320&&a<=57343)return t.lastIntValue=(i-55296)*1024+(a-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(r&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&kv(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=n}return!1};function kv(t){return t>=0&&t<=1114111}q.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};q.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 ph=0,_n=1,Pt=2;q.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(Av(e))return t.lastIntValue=-1,t.advance(),_n;var n=!1;if(t.switchU&&this.options.ecmaVersion>=9&&((n=e===80)||e===112)){t.lastIntValue=-1,t.advance();var r;if(t.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(t))&&t.eat(125))return n&&r===Pt&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return ph};function Av(t){return t===100||t===68||t===115||t===83||t===119||t===87}q.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var n=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,n,r),_n}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return ph};q.regexp_validateUnicodePropertyNameAndValue=function(t,e,n){Mr(t.unicodeProperties.nonBinary,e)||t.raise("Invalid property name"),t.unicodeProperties.nonBinary[e].test(n)||t.raise("Invalid property value")};q.regexp_validateUnicodePropertyNameOrValue=function(t,e){if(t.unicodeProperties.binary.test(e))return _n;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return Pt;t.raise("Invalid property name")};q.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";dh(e=t.current());)t.lastStringValue+=gn(e),t.advance();return t.lastStringValue!==""};function dh(t){return hh(t)||t===95}q.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";Mv(e=t.current());)t.lastStringValue+=gn(e),t.advance();return t.lastStringValue!==""};function Mv(t){return dh(t)||xs(t)}q.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)};q.regexp_eatCharacterClass=function(t){if(t.eat(91)){var e=t.eat(94),n=this.regexp_classContents(t);return t.eat(93)||t.raise("Unterminated character class"),e&&n===Pt&&t.raise("Negated character class may contain strings"),!0}return!1};q.regexp_classContents=function(t){return t.current()===93?_n:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),_n)};q.regexp_nonEmptyClassRanges=function(t){for(;this.regexp_eatClassAtom(t);){var e=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassAtom(t)){var n=t.lastIntValue;t.switchU&&(e===-1||n===-1)&&t.raise("Invalid character class"),e!==-1&&n!==-1&&e>n&&t.raise("Range out of order in character class")}}};q.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var n=t.current();(n===99||yh(n))&&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};q.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)};q.regexp_classSetExpression=function(t){var e=_n,n;if(!this.regexp_eatClassSetRange(t))if(n=this.regexp_eatClassSetOperand(t)){n===Pt&&(e=Pt);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(n=this.regexp_eatClassSetOperand(t))){n!==Pt&&(e=_n);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(n=this.regexp_eatClassSetOperand(t),!n)return e;n===Pt&&(e=Pt)}};q.regexp_eatClassSetRange=function(t){var e=t.pos;if(this.regexp_eatClassSetCharacter(t)){var n=t.lastIntValue;if(t.eat(45)&&this.regexp_eatClassSetCharacter(t)){var r=t.lastIntValue;return n!==-1&&r!==-1&&n>r&&t.raise("Range out of order in character class"),!0}t.pos=e}return!1};q.regexp_eatClassSetOperand=function(t){return this.regexp_eatClassSetCharacter(t)?_n:this.regexp_eatClassStringDisjunction(t)||this.regexp_eatNestedClass(t)};q.regexp_eatNestedClass=function(t){var e=t.pos;if(t.eat(91)){var n=t.eat(94),r=this.regexp_classContents(t);if(t.eat(93))return n&&r===Pt&&t.raise("Negated character class may contain strings"),r;t.pos=e}if(t.eat(92)){var i=this.regexp_eatCharacterClassEscape(t);if(i)return i;t.pos=e}return null};q.regexp_eatClassStringDisjunction=function(t){var e=t.pos;if(t.eatChars([92,113])){if(t.eat(123)){var n=this.regexp_classStringDisjunctionContents(t);if(t.eat(125))return n}else t.raise("Invalid escape");t.pos=e}return null};q.regexp_classStringDisjunctionContents=function(t){for(var e=this.regexp_classString(t);t.eat(124);)this.regexp_classString(t)===Pt&&(e=Pt);return e};q.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?_n:Pt};q.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 n=t.current();return n<0||n===t.lookahead()&&Tv(n)||Pv(n)?!1:(t.advance(),t.lastIntValue=n,!0)};function Tv(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 Pv(t){return t===40||t===41||t===45||t===47||t>=91&&t<=93||t>=123&&t<=125}q.regexp_eatClassSetReservedPunctuator=function(t){var e=t.current();return Dv(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Dv(t){return t===33||t===35||t===37||t===38||t===44||t===45||t>=58&&t<=62||t===64||t===96||t===126}q.regexp_eatClassControlLetter=function(t){var e=t.current();return xs(e)||e===95?(t.lastIntValue=e%32,t.advance(),!0):!1};q.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};q.regexp_eatDecimalDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;xs(n=t.current());)t.lastIntValue=10*t.lastIntValue+(n-48),t.advance();return t.pos!==e};function xs(t){return t>=48&&t<=57}q.regexp_eatHexDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;fh(n=t.current());)t.lastIntValue=16*t.lastIntValue+mh(n),t.advance();return t.pos!==e};function fh(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function mh(t){return t>=65&&t<=70?10+(t-65):t>=97&&t<=102?10+(t-97):t-48}q.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var n=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=e*64+n*8+t.lastIntValue:t.lastIntValue=e*8+n}else t.lastIntValue=e;return!0}return!1};q.regexp_eatOctalDigit=function(t){var e=t.current();return yh(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function yh(t){return t>=48&&t<=55}q.regexp_eatFixedHexDigits=function(t,e){var n=t.pos;t.lastIntValue=0;for(var r=0;r<e;++r){var i=t.current();if(!fh(i))return t.pos=n,!1;t.lastIntValue=16*t.lastIntValue+mh(i),t.advance()}return!0};var Ko=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new fs(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},ne=Ve.prototype;ne.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 Ko(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};ne.getToken=function(){return this.next(),new Ko(this)};typeof Symbol<"u"&&(ne[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===b.eof,value:e}}}});ne.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(b.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};ne.readToken=function(t){return on(t,this.options.ecmaVersion>=6)||t===92?this.readWord():this.getTokenFromCode(t)};ne.fullCharCodeAt=function(t){var e=this.input.charCodeAt(t);if(e<=55295||e>=56320)return e;var n=this.input.charCodeAt(t+1);return n<=56319||n>=57344?e:(e<<10)+n-56613888};ne.fullCharCodeAtPos=function(){return this.fullCharCodeAt(this.pos)};ne.skipBlockComment=function(){var t=this.options.onComment&&this.curPosition(),e=this.pos,n=this.input.indexOf("*/",this.pos+=2);if(n===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=n+2,this.options.locations)for(var r=void 0,i=e;(r=Bu(this.input,i,this.pos))>-1;)++this.curLine,i=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(e+2,n),e,this.pos,t,this.curPosition())};ne.skipLineComment=function(t){for(var e=this.pos,n=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!Ar(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(e+t,this.pos),e,this.pos,n,this.curPosition())};ne.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&&$u.test(String.fromCharCode(t)))++this.pos;else break e}}};ne.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var n=this.type;this.type=t,this.value=e,this.updateContext(n)};ne.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(b.ellipsis)):(++this.pos,this.finishToken(b.dot))};ne.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):t===61?this.finishOp(b.assign,2):this.finishOp(b.slash,1)};ne.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),n=1,r=t===42?b.star:b.modulo;return this.options.ecmaVersion>=7&&t===42&&e===42&&(++n,r=b.starstar,e=this.input.charCodeAt(this.pos+2)),e===61?this.finishOp(b.assign,n+1):this.finishOp(r,n)};ne.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);if(e===t){if(this.options.ecmaVersion>=12){var n=this.input.charCodeAt(this.pos+2);if(n===61)return this.finishOp(b.assign,3)}return this.finishOp(t===124?b.logicalOR:b.logicalAND,2)}return e===61?this.finishOp(b.assign,2):this.finishOp(t===124?b.bitwiseOR:b.bitwiseAND,1)};ne.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(b.assign,2):this.finishOp(b.bitwiseXOR,1)};ne.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||ft.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(b.incDec,2):e===61?this.finishOp(b.assign,2):this.finishOp(b.plusMin,1)};ne.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),n=1;return e===t?(n=t===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+n)===61?this.finishOp(b.assign,n+1):this.finishOp(b.bitShift,n)):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&&(n=2),this.finishOp(b.relational,n))};ne.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(b.equality,this.input.charCodeAt(this.pos+2)===61?3:2):t===61&&e===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(b.arrow)):this.finishOp(t===61?b.eq:b.prefix,1)};ne.readToken_question=function(){var t=this.options.ecmaVersion;if(t>=11){var e=this.input.charCodeAt(this.pos+1);if(e===46){var n=this.input.charCodeAt(this.pos+2);if(n<48||n>57)return this.finishOp(b.questionDot,2)}if(e===63){if(t>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(b.assign,3)}return this.finishOp(b.coalesce,2)}}return this.finishOp(b.question,1)};ne.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),on(e,!0)||e===92))return this.finishToken(b.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+gn(e)+"\'")};ne.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(b.parenL);case 41:return++this.pos,this.finishToken(b.parenR);case 59:return++this.pos,this.finishToken(b.semi);case 44:return++this.pos,this.finishToken(b.comma);case 91:return++this.pos,this.finishToken(b.bracketL);case 93:return++this.pos,this.finishToken(b.bracketR);case 123:return++this.pos,this.finishToken(b.braceL);case 125:return++this.pos,this.finishToken(b.braceR);case 58:return++this.pos,this.finishToken(b.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(b.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(b.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character \'"+gn(t)+"\'")};ne.finishOp=function(t,e){var n=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,n)};ne.readRegexp=function(){for(var t,e,n=this.pos;;){this.pos>=this.input.length&&this.raise(n,"Unterminated regular expression");var r=this.input.charAt(this.pos);if(ft.test(r)&&this.raise(n,"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 i=this.input.slice(n,this.pos);++this.pos;var s=this.pos,a=this.readWord1();this.containsEsc&&this.unexpected(s);var o=this.regexpState||(this.regexpState=new ln(this));o.reset(n,i,a),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var l=null;try{l=new RegExp(i,a)}catch{}return this.finishToken(b.regexp,{pattern:i,flags:a,value:l})};ne.readInt=function(t,e,n){for(var r=this.options.ecmaVersion>=12&&e===void 0,i=n&&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){i&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed in legacy octal numeric literals"),o===95&&this.raiseRecoverable(this.pos,"Numeric separator must be exactly one underscore"),l===0&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed at the first of digits"),o=u;continue}if(u>=97?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 Ov(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function gh(t){return typeof BigInt!="function"?null:BigInt(t.replace(/_/g,""))}ne.readRadixNumber=function(t){var e=this.pos;this.pos+=2;var n=this.readInt(t);return n==null&&this.raise(this.start+2,"Expected number in radix "+t),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(n=gh(this.input.slice(e,this.pos)),++this.pos):on(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(b.num,n)};ne.readNumber=function(t){var e=this.pos;!t&&this.readInt(10,void 0,!0)===null&&this.raise(e,"Invalid number");var n=this.pos-e>=2&&this.input.charCodeAt(e)===48;n&&this.strict&&this.raise(e,"Invalid number");var r=this.input.charCodeAt(this.pos);if(!n&&!t&&this.options.ecmaVersion>=11&&r===110){var i=gh(this.input.slice(e,this.pos));return++this.pos,on(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(b.num,i)}n&&/[89]/.test(this.input.slice(e,this.pos))&&(n=!1),r===46&&!n&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!n&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(e,"Invalid number")),on(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=Ov(this.input.slice(e,this.pos),n);return this.finishToken(b.num,s)};ne.readCodePoint=function(){var t=this.input.charCodeAt(this.pos),e;if(t===123){this.options.ecmaVersion<6&&this.unexpected();var n=++this.pos;e=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,e>1114111&&this.invalidStringToken(n,"Code point out of bounds")}else e=this.readHexChar(4);return e};ne.readString=function(t){for(var e="",n=++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(n,this.pos),e+=this.readEscapedChar(!1),n=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)):(Ar(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(n,this.pos++),this.finishToken(b.string,e)};var _h={};ne.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===_h)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};ne.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw _h;this.raise(t,e)};ne.readTmplToken=function(){for(var t="",e=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var n=this.input.charCodeAt(this.pos);if(n===96||n===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===b.template||this.type===b.invalidTemplate)?n===36?(this.pos+=2,this.finishToken(b.dollarBraceL)):(++this.pos,this.finishToken(b.backQuote)):(t+=this.input.slice(e,this.pos),this.finishToken(b.template,t));if(n===92)t+=this.input.slice(e,this.pos),t+=this.readEscapedChar(!0),e=this.pos;else if(Ar(n)){switch(t+=this.input.slice(e,this.pos),++this.pos,n){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:t+=`\n`;break;default:t+=String.fromCharCode(n);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),e=this.pos}else++this.pos}};ne.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(b.invalidTemplate,this.input.slice(this.start,this.pos));case"\\r":this.input[this.pos+1]===`\n`&&++this.pos;case`\n`:case"\\u2028":case"\\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};ne.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return`\n`;case 114:return"\\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return gn(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 n=this.pos-1;this.invalidStringToken(n,"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],i=parseInt(r,8);return i>255&&(r=r.slice(0,-1),i=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(i)}return Ar(e)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(e)}};ne.readHexChar=function(t){var e=this.pos,n=this.readInt(16,t);return n===null&&this.invalidStringToken(e,"Bad character escape sequence"),n};ne.readWord1=function(){this.containsEsc=!1;for(var t="",e=!0,n=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var i=this.fullCharCodeAtPos();if(On(i,r))this.pos+=i<=65535?1:2;else if(i===92){this.containsEsc=!0,t+=this.input.slice(n,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?on:On)(a,r)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=gn(a),n=this.pos}else break;e=!1}return t+this.input.slice(n,this.pos)};ne.readWord=function(){var t=this.readWord1(),e=b.name;return this.keywords.test(t)&&(e=jo[t]),this.finishToken(e,t)};var Rv="8.16.0";Ve.acorn={Parser:Ve,version:Rv,defaultOptions:Oa,Position:si,SourceLocation:fs,getLineInfo:Wu,Node:_s,TokenType:oe,tokTypes:b,keywordTypes:jo,TokContext:Vt,tokContexts:Ie,isIdentifierChar:On,isIdentifierStart:on,Token:Ko,isNewLine:Ar,lineBreak:ft,lineBreakG:iv,nonASCIIwhitespace:$u};function Go(t,e){return Ve.parse(t,e)}var{stringify:Lv}=JSON;if(!String.prototype.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!String.prototype.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var Ni={"||":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},qt=17,Fv={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:qt,ClassExpression:qt,FunctionExpression:qt,ObjectExpression:qt,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function ur(t,e){let{generator:n}=t;if(t.write("("),e!=null&&e.length>0){n[e[0].type](e[0],t);let{length:r}=e;for(let i=1;i<r;i++){let s=e[i];t.write(", "),n[s.type](s,t)}}t.write(")")}function xh(t,e,n,r){let i=t.expressionsPrecedence[e.type];if(i===qt)return!0;let s=t.expressionsPrecedence[n.type];return i!==s?!r&&i===15&&s===14&&n.operator==="**"||i<s:i!==13&&i!==14?!1:e.operator==="**"&&n.operator==="**"?!r:i===13&&s===13&&(e.operator==="??"||n.operator==="??")?!0:r?Ni[e.operator]<=Ni[n.operator]:Ni[e.operator]<Ni[n.operator]}function Ci(t,e,n,r){let{generator:i}=t;xh(t,e,n,r)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function Vv(t,e,n,r){let i=e.split(`\n`),s=i.length-1;if(t.write(i[0].trim()),s>0){t.write(r);for(let a=1;a<s;a++)t.write(n+i[a].trim()+r);t.write(n+i[s].trim())}}function Ze(t,e,n,r){let{length:i}=e;for(let s=0;s<i;s++){let a=e[s];t.write(n),a.type[0]==="L"?t.write("// "+a.value.trim()+`\n`,a):(t.write("/*"),Vv(t,a.value,n,r),t.write("*/"+r))}}function Bv(t){let e=t;for(;e!=null;){let{type:n}=e;if(n[0]==="C"&&n[1]==="a")return!0;if(n[0]==="M"&&n[1]==="e"&&n[2]==="m")e=e.object;else return!1}}function Ys(t,e){let{generator:n}=t,{declarations:r}=e;t.write(e.kind+" ");let{length:i}=r;if(i>0){n.VariableDeclarator(r[0],t);for(let s=1;s<i;s++)t.write(", "),n.VariableDeclarator(r[s],t)}}var xc,bc,vc,wc,Sc,Ec,Yo={Program(t,e){let n=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:i}=e;i&&t.comments!=null&&Ze(e,t.comments,n,r);let s=t.body,{length:a}=s;for(let o=0;o<a;o++){let l=s[o];i&&l.comments!=null&&Ze(e,l.comments,n,r),e.write(n),this[l.type](l,e),e.write(r)}i&&t.trailingComments!=null&&Ze(e,t.trailingComments,n,r)},BlockStatement:Ec=function(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e,s=n+e.indent;e.write("{");let a=t.body;if(a!=null&&a.length>0){e.write(r),i&&t.comments!=null&&Ze(e,t.comments,s,r);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&Ze(e,c.comments,s,r),e.write(s),this[c.type](c,e),e.write(r)}e.write(n)}else i&&t.comments!=null&&(e.write(r),Ze(e,t.comments,s,r),e.write(n));i&&t.trailingComments!=null&&Ze(e,t.trailingComments,s,r),e.write("}"),e.indentLevel--},ClassBody:Ec,StaticBlock(t,e){e.write("static "),this.BlockStatement(t,e)},EmptyStatement(t,e){e.write(";")},ExpressionStatement(t,e){let n=e.expressionsPrecedence[t.expression.type];n===qt||n===3&&t.expression.left.type[0]==="O"?(e.write("("),this[t.expression.type](t.expression,e),e.write(")")):this[t.expression.type](t.expression,e),e.write(";")},IfStatement(t,e){e.write("if ("),this[t.test.type](t.test,e),e.write(") "),this[t.consequent.type](t.consequent,e),t.alternate!=null&&(e.write(" else "),this[t.alternate.type](t.alternate,e))},LabeledStatement(t,e){this[t.label.type](t.label,e),e.write(": "),this[t.body.type](t.body,e)},BreakStatement(t,e){e.write("break"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},ContinueStatement(t,e){e.write("continue"),t.label!=null&&(e.write(" "),this[t.label.type](t.label,e)),e.write(";")},WithStatement(t,e){e.write("with ("),this[t.object.type](t.object,e),e.write(") "),this[t.body.type](t.body,e)},SwitchStatement(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e;e.indentLevel++;let s=n+e.indent,a=s+e.indent;e.write("switch ("),this[t.discriminant.type](t.discriminant,e),e.write(") {"+r);let{cases:o}=t,{length:l}=o;for(let c=0;c<l;c++){let u=o[c];i&&u.comments!=null&&Ze(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);let{consequent:p}=u,{length:h}=p;for(let d=0;d<h;d++){let f=p[d];i&&f.comments!=null&&Ze(e,f.comments,a,r),e.write(a),this[f.type](f,e),e.write(r)}}e.indentLevel-=2,e.write(n+"}")},ReturnStatement(t,e){e.write("return"),t.argument&&(e.write(" "),this[t.argument.type](t.argument,e)),e.write(";")},ThrowStatement(t,e){e.write("throw "),this[t.argument.type](t.argument,e),e.write(";")},TryStatement(t,e){if(e.write("try "),this[t.block.type](t.block,e),t.handler){let{handler:n}=t;n.param==null?e.write(" catch "):(e.write(" catch ("),this[n.param.type](n.param,e),e.write(") ")),this[n.body.type](n.body,e)}t.finalizer&&(e.write(" finally "),this[t.finalizer.type](t.finalizer,e))},WhileStatement(t,e){e.write("while ("),this[t.test.type](t.test,e),e.write(") "),this[t.body.type](t.body,e)},DoWhileStatement(t,e){e.write("do "),this[t.body.type](t.body,e),e.write(" while ("),this[t.test.type](t.test,e),e.write(");")},ForStatement(t,e){if(e.write("for ("),t.init!=null){let{init:n}=t;n.type[0]==="V"?Ys(e,n):this[n.type](n,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:xc=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:n}=t;n.type[0]==="V"?Ys(e,n):this[n.type](n,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:xc,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:bc=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),ur(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:bc,VariableDeclaration(t,e){Ys(e,t),e.write(";")},VariableDeclarator(t,e){this[t.id.type](t.id,e),t.init!=null&&(e.write(" = "),this[t.init.type](t.init,e))},ClassDeclaration(t,e){if(e.write("class "+(t.id?`${t.id.name} `:""),t),t.superClass){e.write("extends ");let{superClass:n}=t,{type:r}=n,i=e.expressionsPrecedence[r];(r[0]!=="C"||r[1]!=="l"||r[5]!=="E")&&(i===qt||i<e.expressionsPrecedence.ClassExpression)?(e.write("("),this[t.superClass.type](n,e),e.write(")")):this[n.type](n,e),e.write(" ")}this.ClassBody(t.body,e)},ImportDeclaration(t,e){e.write("import ");let{specifiers:n,attributes:r}=t,{length:i}=n,s=0;if(i>0){for(;s<i;){s>0&&e.write(", ");let a=n[s],o=a.type[6];if(o==="D")e.write(a.local.name,a),s++;else if(o==="N")e.write("* as "+a.local.name,a),s++;else break}if(s<i){for(e.write("{");;){let a=n[s],{name:o}=a.imported;if(e.write(o,a),o!==a.local.name&&e.write(" as "+a.local.name),++s<i)e.write(", ");else break}e.write("}")}e.write(" from ")}if(this.Literal(t.source,e),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("{");let{specifiers:n}=t,{length:r}=n;if(r>0)for(let i=0;;){let s=n[i],{name:a}=s.local;if(e.write(a,s),a!==s.exported.name&&e.write(" as "+s.exported.name),++i<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 i=0;i<t.attributes.length;i++)this.ImportAttribute(t.attributes[i],e),i<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")}},ExportAllDeclaration(t,e){if(t.exported!=null?e.write("export * as "+t.exported.name+" from "):e.write("export * from "),this.Literal(t.source,e),t.attributes&&t.attributes.length>0){e.write(" with { ");for(let n=0;n<t.attributes.length;n++)this.ImportAttribute(t.attributes[n],e),n<t.attributes.length-1&&e.write(", ");e.write(" }")}e.write(";")},MethodDefinition(t,e){t.static&&e.write("static ");let n=t.kind[0];(n==="g"||n==="s")&&e.write(t.kind+" "),t.value.async&&e.write("async "),t.value.generator&&e.write("*"),t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),ur(e,t.value.params),e.write(" "),this[t.value.body.type](t.value.body,e)},ClassExpression(t,e){this.ClassDeclaration(t,e)},ArrowFunctionExpression(t,e){e.write(t.async?"async ":"",t);let{params:n}=t;n!=null&&(n.length===1&&n[0].type[0]==="I"?e.write(n[0].name,n[0]):ur(e,t.params)),e.write(" => "),t.body.type[0]==="O"?(e.write("("),this.ObjectExpression(t.body,e),e.write(")")):this[t.body.type](t.body,e)},ThisExpression(t,e){e.write("this",t)},Super(t,e){e.write("super",t)},RestElement:vc=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:vc,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),Ci(e,t.argument,t)},TemplateLiteral(t,e){let{quasis:n,expressions:r}=t;e.write("`");let{length:i}=r;for(let a=0;a<i;a++){let o=r[a],l=n[a];e.write(l.value.raw,l),e.write("${"),this[o.type](o,e),e.write("}")}let s=n[n.length-1];e.write(s.value.raw,s),e.write("`")},TemplateElement(t,e){e.write(t.value.raw,t)},TaggedTemplateExpression(t,e){Ci(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:Sc=function(t,e){if(e.write("["),t.elements.length>0){let{elements:n}=t,{length:r}=n;for(let i=0;;){let s=n[i];if(s!=null&&this[s.type](s,e),++i<r)e.write(", ");else{s==null&&e.write(", ");break}}}e.write("]")},ArrayPattern:Sc,ObjectExpression(t,e){let n=e.indent.repeat(e.indentLevel++),{lineEnd:r,writeComments:i}=e,s=n+e.indent;if(e.write("{"),t.properties.length>0){e.write(r),i&&t.comments!=null&&Ze(e,t.comments,s,r);let a=","+r,{properties:o}=t,{length:l}=o;for(let c=0;;){let u=o[c];if(i&&u.comments!=null&&Ze(e,u.comments,s,r),e.write(s),this[u.type](u,e),++c<l)e.write(a);else break}e.write(r),i&&t.trailingComments!=null&&Ze(e,t.trailingComments,s,r),e.write(n+"}")}else i?t.comments!=null?(e.write(r),Ze(e,t.comments,s,r),t.trailingComments!=null&&Ze(e,t.trailingComments,s,r),e.write(n+"}")):t.trailingComments!=null?(e.write(r),Ze(e,t.trailingComments,s,r),e.write(n+"}")):e.write("}"):e.write("}");e.indentLevel--},Property(t,e){t.method||t.kind[0]!=="i"?this.MethodDefinition(t,e):(t.shorthand||(t.computed?(e.write("["),this[t.key.type](t.key,e),e.write("]")):this[t.key.type](t.key,e),e.write(": ")),this[t.value.type](t.value,e))},PropertyDefinition(t,e){if(t.static&&e.write("static "),t.computed&&e.write("["),this[t.key.type](t.key,e),t.computed&&e.write("]"),t.value==null){t.key.type[0]!=="F"&&e.write(";");return}e.write(" = "),this[t.value.type](t.value,e),e.write(";")},ObjectPattern(t,e){if(e.write("{"),t.properties.length>0){let{properties:n}=t,{length:r}=n;for(let i=0;this[n[i].type](n[i],e),++i<r;)e.write(", ")}e.write("}")},SequenceExpression(t,e){ur(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:n,argument:r,argument:{type:i}}=t;e.write(n);let s=xh(e,r,t);!s&&(n.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&r.prefix&&r.operator[0]===n&&(n==="+"||n==="-"))&&e.write(" "),s?(e.write(n.length>1?" (":"("),this[i](r,e),e.write(")")):this[i](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:wc=function(t,e){let n=t.operator==="in";n&&e.write("("),Ci(e,t.left,t,!1),e.write(" "+t.operator+" "),Ci(e,t.right,t,!0),n&&e.write(")")},LogicalExpression:wc,ConditionalExpression(t,e){let{test:n}=t,r=e.expressionsPrecedence[n.type];r===qt||r<=e.expressionsPrecedence.ConditionalExpression?(e.write("("),this[n.type](n,e),e.write(")")):this[n.type](n,e),e.write(" ? "),this[t.consequent.type](t.consequent,e),e.write(" : "),this[t.alternate.type](t.alternate,e)},NewExpression(t,e){e.write("new ");let n=e.expressionsPrecedence[t.callee.type];n===qt||n<e.expressionsPrecedence.CallExpression||Bv(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),ur(e,t.arguments)},CallExpression(t,e){let n=e.expressionsPrecedence[t.callee.type];n===qt||n<e.expressionsPrecedence.CallExpression?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),t.optional&&e.write("?."),ur(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let n=e.expressionsPrecedence[t.object.type];n===qt||n<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(Lv(t.value),t)},RegExpLiteral(t,e){let{regex:n}=t;e.write(`/${n.pattern}/${n.flags}`,t)}},$v={},jv=Yo,Fa=class{constructor(e){let n=e??$v;this.output="",n.output!=null?(this.output=n.output,this.write=this.writeToStream):this.output="",this.generator=n.generator!=null?n.generator:Yo,this.expressionsPrecedence=n.expressionsPrecedence!=null?n.expressionsPrecedence:Fv,this.indent=n.indent!=null?n.indent:" ",this.lineEnd=n.lineEnd!=null?n.lineEnd:`\n`,this.indentLevel=n.startingIndentLevel!=null?n.startingIndentLevel:0,this.writeComments=n.comments?n.comments:!1,n.sourceMap!=null&&(this.write=n.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=n.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`\n`).length-1,this.mapping={original:null,generated:this,name:void 0,source:n.sourceMap.file||n.sourceMap._file})}write(e){this.output+=e}writeToStream(e){this.output.write(e)}writeAndMap(e,n){this.output+=e,this.map(e,n)}writeToStreamAndMap(e,n){this.output.write(e),this.map(e,n)}map(e,n){if(n!=null){let{type:s}=n;if(s[0]==="L"&&s[2]==="n"){this.column=0,this.line++;return}if(n.loc!=null){let{mapping:a}=this;a.original=n.loc.start,a.name=n.name,this.sourceMap.addMapping(a)}if(s[0]==="T"&&s[8]==="E"||s[0]==="L"&&s[1]==="i"&&typeof n.value=="string"){let{length:a}=e,{column:o,line:l}=this;for(let c=0;c<a;c++)e[c]===`\n`?(o=0,l++):o++;this.column=o,this.line=l;return}}let{length:r}=e,{lineEnd:i}=this;r>0&&(this.lineEndSize>0&&(i.length===1?e[r-1]===i:e.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=r)}toString(){return this.output}};function Xo(t,e){let n=new Fa(e);return n.generator[t.type](t,n),n.output}var Wv=Object.defineProperty,Uv=(t,e,n)=>e in t?Wv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ae=(t,e,n)=>Uv(t,typeof e!="symbol"?e+"":e,n),qv=new Set(["Infinity","NaN","undefined","null","true","false"]),zv=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"]);function Va(t){if(!t||typeof t!="string")return;let e=t.trim();if(e.endsWith("[]"))return"array";let n=e.indexOf("<");n>=0&&(e=e.slice(0,n));let r=e.split(/\\s+/).filter(Boolean);return r.length>0?r[r.length-1]:void 0}var Ba=class{constructor(){ae(this,"scopes",[]),ae(this,"scopeTypes",[]),ae(this,"scopeCounts",new Map),ae(this,"contextBoundVars",new Set),ae(this,"arrayPatternElements",new Set),ae(this,"rootParams",new Set),ae(this,"localSeriesVars",new Set),ae(this,"varKinds",new Map),ae(this,"loopVars",new Set),ae(this,"loopVarNames",new Map),ae(this,"paramIdCounter",0),ae(this,"cacheIdCounter",0),ae(this,"tempVarCounter",0),ae(this,"taCallIdCounter",0),ae(this,"userCallIdCounter",0),ae(this,"plotCallIdCounter",0),ae(this,"alertCallIdCounter",0),ae(this,"loopGuardCounter",0),ae(this,"hoistingStack",[]),ae(this,"suppressHoisting",!1),ae(this,"reservedNames",new Set),ae(this,"userFunctions",new Set),ae(this,"userMethods",new Set),ae(this,"regularUserFunctions",new Set),ae(this,"udtTypeNames",new Map),ae(this,"udtInstances",new Map),ae(this,"functionReturnTypes",new Map),ae(this,"functionReturnTupleTypes",new Map),ae(this,"functionParamUdtTypes",new Map),ae(this,"varStaticTypes",new Map),ae(this,"methodReceiverTypes",new Map),ae(this,"functionParamStaticTypes",new Map),ae(this,"methodCandidates",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,n={}){this.udtTypeNames.set(e,n)}isUdtTypeName(e){return this.udtTypeNames.has(e)}getUdtTypeFields(e){return this.udtTypeNames.get(e)}markVariableAsUdtInstance(e,n){this.udtInstances.set(e,n)}getVariableUdtType(e){return this.udtInstances.get(e)}isUdtInstance(e){return this.udtInstances.has(e)}setFunctionReturnType(e,n){let r=this.functionReturnTypes.get(e);if(r&&r!==n){this.functionReturnTypes.delete(e);return}this.functionReturnTypes.set(e,n)}getFunctionReturnType(e){return this.functionReturnTypes.get(e)}setFunctionReturnTupleType(e,n){let r=this.functionReturnTupleTypes.get(e);if(r&&(r.length!==n.length||r.some((i,s)=>i!==n[s]))){this.functionReturnTupleTypes.delete(e);return}this.functionReturnTupleTypes.set(e,n)}getFunctionReturnTupleType(e){return this.functionReturnTupleTypes.get(e)}setFunctionParamUdtTypes(e,n){this.functionParamUdtTypes.set(e,n)}getFunctionParamUdtTypes(e){return this.functionParamUdtTypes.get(e)}unmarkVariableAsUdtInstance(e){this.udtInstances.delete(e)}setVarStaticType(e,n){let r=Va(n);r&&this.varStaticTypes.set(e,r)}getVarStaticType(e){return this.varStaticTypes.get(e)}unsetVarStaticType(e){this.varStaticTypes.delete(e)}addMethodCandidate(e,n){let r=this.methodCandidates.get(e)??[];r.includes(n)||r.push(n),this.methodCandidates.set(e,r)}getMethodCandidates(e){return this.methodCandidates.get(e)??[]}setMethodReceiverType(e,n){let r=Va(n);r&&this.methodReceiverTypes.set(e,r)}isMethodReceiverTypeName(e){for(let n of this.methodReceiverTypes.values())if(n===e)return!0;return!1}getMethodReceiverType(e){return this.methodReceiverTypes.get(e)}setFunctionParamStaticTypes(e,n){this.functionParamStaticTypes.set(e,n)}getFunctionParamStaticTypes(e){return this.functionParamStaticTypes.get(e)}addContextBoundVar(e,n=!1){this.contextBoundVars.add(e),n&&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 qv.has(e)||zv.has(e)?!1:this.contextBoundVars.has(e)}isArrayPatternElement(e){return this.arrayPatternElements.has(e)}isRootParam(e){return this.rootParams.has(e)}addLoopVariable(e,n){this.loopVars.add(e),this.loopVarNames.set(e,n)}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,n){if(this.isContextBound(e))return e;let r=this.scopes[this.scopes.length-1],i=this.scopeTypes[this.scopeTypes.length-1],s=this.scopeCounts.get(i)||1,a=`${i}${s}_${e}`;return r.set(e,a),this.varKinds.set(a,n),a}getVariable(e){if(this.loopVars.has(e)){let n=this.loopVarNames.get(e);if(n)return[n,"let"]}if(this.isContextBound(e))return[e,"let"];for(let n=this.scopes.length-1;n>=0;n--){let r=this.scopes[n];if(r.has(e)){let i=r.get(e),s=this.varKinds.get(i)||"let";return[i,s]}}return[e,"let"]}isVariableInFunctionScope(e){for(let n=this.scopes.length-1;n>=0;n--)if(this.scopes[n].has(e)){for(let r=0;r<=n;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){let n=Math.min(1,this.hoistingStack.length-1);this.hoistingStack[n].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 n=this.scopes.length-1;n>=0;n--)if(this.scopes[n].has(e))return!0;return!!(this.contextBoundVars.has(e)||this.loopVars.has(e)||this.localSeriesVars.has(e))}generateParamId(){let e=`p${this.paramIdCounter++}`;for(;this.hasVariableInScope(e);)e=`p${this.paramIdCounter++}`;let n=this.scopes[this.scopes.length-1];return n&&n.set(e,e),e}};function tt(t,e,n,r,i){n||(n=O),(function s(a,o,l){var c=l||a.type;bh(n,c,a,o,s),e[c]&&e[c](a,o)})(t,r,i)}function Zo(t,e,n,r,i){var s=[];n||(n=O),(function a(o,l,c){var u=c||o.type,p=o!==s[s.length-1];p&&s.push(o),bh(n,u,o,l,a),e[u]&&e[u](o,l||s,s),p&&s.pop()})(t,r,i)}function je(t,e,n,r,i){var s=n?Hv(n,r||void 0):r;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function Hv(t,e){var n=Object.create(e||O);for(var r in t)n[r]=t[r];return n}function Qo(t,e,n){n(t,e)}function Gn(t,e,n){}function bh(t,e,n,r,i){if(t[e]==null)throw new Error("No walker function defined for node type "+e);t[e](n,r,i)}var O={};O.Program=O.BlockStatement=O.StaticBlock=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e,"Statement")}};O.Statement=Qo;O.EmptyStatement=Gn;O.ExpressionStatement=O.ParenthesizedExpression=O.ChainExpression=function(t,e,n){return n(t.expression,e,"Expression")};O.IfStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Statement"),t.alternate&&n(t.alternate,e,"Statement")};O.LabeledStatement=function(t,e,n){return n(t.body,e,"Statement")};O.BreakStatement=O.ContinueStatement=Gn;O.WithStatement=function(t,e,n){n(t.object,e,"Expression"),n(t.body,e,"Statement")};O.SwitchStatement=function(t,e,n){n(t.discriminant,e,"Expression");for(var r=0,i=t.cases;r<i.length;r+=1){var s=i[r];n(s,e)}};O.SwitchCase=function(t,e,n){t.test&&n(t.test,e,"Expression");for(var r=0,i=t.consequent;r<i.length;r+=1){var s=i[r];n(s,e,"Statement")}};O.ReturnStatement=O.YieldExpression=O.AwaitExpression=function(t,e,n){t.argument&&n(t.argument,e,"Expression")};O.ThrowStatement=O.SpreadElement=function(t,e,n){return n(t.argument,e,"Expression")};O.TryStatement=function(t,e,n){n(t.block,e,"Statement"),t.handler&&n(t.handler,e),t.finalizer&&n(t.finalizer,e,"Statement")};O.CatchClause=function(t,e,n){t.param&&n(t.param,e,"Pattern"),n(t.body,e,"Statement")};O.WhileStatement=O.DoWhileStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.body,e,"Statement")};O.ForStatement=function(t,e,n){t.init&&n(t.init,e,"ForInit"),t.test&&n(t.test,e,"Expression"),t.update&&n(t.update,e,"Expression"),n(t.body,e,"Statement")};O.ForInStatement=O.ForOfStatement=function(t,e,n){n(t.left,e,"ForInit"),n(t.right,e,"Expression"),n(t.body,e,"Statement")};O.ForInit=function(t,e,n){t.type==="VariableDeclaration"?n(t,e):n(t,e,"Expression")};O.DebuggerStatement=Gn;O.FunctionDeclaration=function(t,e,n){return n(t,e,"Function")};O.VariableDeclaration=function(t,e,n){for(var r=0,i=t.declarations;r<i.length;r+=1){var s=i[r];n(s,e)}};O.VariableDeclarator=function(t,e,n){n(t.id,e,"Pattern"),t.init&&n(t.init,e,"Expression")};O.Function=function(t,e,n){t.id&&n(t.id,e,"Pattern");for(var r=0,i=t.params;r<i.length;r+=1){var s=i[r];n(s,e,"Pattern")}n(t.body,e,t.expression?"Expression":"Statement")};O.Pattern=function(t,e,n){t.type==="Identifier"?n(t,e,"VariablePattern"):t.type==="MemberExpression"?n(t,e,"MemberPattern"):n(t,e)};O.VariablePattern=Gn;O.MemberPattern=Qo;O.RestElement=function(t,e,n){return n(t.argument,e,"Pattern")};O.ArrayPattern=function(t,e,n){for(var r=0,i=t.elements;r<i.length;r+=1){var s=i[r];s&&n(s,e,"Pattern")}};O.ObjectPattern=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];s.type==="Property"?(s.computed&&n(s.key,e,"Expression"),n(s.value,e,"Pattern")):s.type==="RestElement"&&n(s.argument,e,"Pattern")}};O.Expression=Qo;O.ThisExpression=O.Super=O.MetaProperty=Gn;O.ArrayExpression=function(t,e,n){for(var r=0,i=t.elements;r<i.length;r+=1){var s=i[r];s&&n(s,e,"Expression")}};O.ObjectExpression=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];n(s,e)}};O.FunctionExpression=O.ArrowFunctionExpression=O.FunctionDeclaration;O.SequenceExpression=function(t,e,n){for(var r=0,i=t.expressions;r<i.length;r+=1){var s=i[r];n(s,e,"Expression")}};O.TemplateLiteral=function(t,e,n){for(var r=0,i=t.quasis;r<i.length;r+=1){var s=i[r];n(s,e)}for(var a=0,o=t.expressions;a<o.length;a+=1){var l=o[a];n(l,e,"Expression")}};O.TemplateElement=Gn;O.UnaryExpression=O.UpdateExpression=function(t,e,n){n(t.argument,e,"Expression")};O.BinaryExpression=O.LogicalExpression=function(t,e,n){n(t.left,e,"Expression"),n(t.right,e,"Expression")};O.AssignmentExpression=O.AssignmentPattern=function(t,e,n){n(t.left,e,"Pattern"),n(t.right,e,"Expression")};O.ConditionalExpression=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Expression"),n(t.alternate,e,"Expression")};O.NewExpression=O.CallExpression=function(t,e,n){if(n(t.callee,e,"Expression"),t.arguments)for(var r=0,i=t.arguments;r<i.length;r+=1){var s=i[r];n(s,e,"Expression")}};O.MemberExpression=function(t,e,n){n(t.object,e,"Expression"),t.computed&&n(t.property,e,"Expression")};O.ExportNamedDeclaration=O.ExportDefaultDeclaration=function(t,e,n){if(t.declaration&&n(t.declaration,e,t.type==="ExportNamedDeclaration"||t.declaration.id?"Statement":"Expression"),t.source&&n(t.source,e,"Expression"),t.attributes)for(var r=0,i=t.attributes;r<i.length;r+=1){var s=i[r];n(s,e)}};O.ExportAllDeclaration=function(t,e,n){if(t.exported&&n(t.exported,e),n(t.source,e,"Expression"),t.attributes)for(var r=0,i=t.attributes;r<i.length;r+=1){var s=i[r];n(s,e)}};O.ImportAttribute=function(t,e,n){n(t.value,e,"Expression")};O.ImportDeclaration=function(t,e,n){for(var r=0,i=t.specifiers;r<i.length;r+=1){var s=i[r];n(s,e)}if(n(t.source,e,"Expression"),t.attributes)for(var a=0,o=t.attributes;a<o.length;a+=1){var l=o[a];n(l,e)}};O.ImportExpression=function(t,e,n){n(t.source,e,"Expression"),t.options&&n(t.options,e,"Expression")};O.ImportSpecifier=O.ImportDefaultSpecifier=O.ImportNamespaceSpecifier=O.Identifier=O.PrivateIdentifier=O.Literal=Gn;O.TaggedTemplateExpression=function(t,e,n){n(t.tag,e,"Expression"),n(t.quasi,e,"Expression")};O.ClassDeclaration=O.ClassExpression=function(t,e,n){return n(t,e,"Class")};O.Class=function(t,e,n){t.id&&n(t.id,e,"Pattern"),t.superClass&&n(t.superClass,e,"Expression"),n(t.body,e)};O.ClassBody=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e)}};O.MethodDefinition=O.PropertyDefinition=O.Property=function(t,e,n){t.computed&&n(t.key,e,"Expression"),t.value&&n(t.value,e,"Expression")};var _e="$",N={createIdentifier(t){return{type:"Identifier",name:t}},createLiteral(t){return{type:"Literal",value:t}},createMemberExpression(t,e,n=!1){return{type:"MemberExpression",object:t,property:e,computed:n}},createContextIdentifier(){return this.createIdentifier("$")},createLocalContextIdentifier(){return this.createIdentifier("$$")},createContextVariableReference(t,e){let n=this.createContextIdentifier(),r=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(n,r,!1),i,!1)},createLocalContextVariableReference(t,e){let n=this.createLocalContextIdentifier(),r=this.createIdentifier(t),i=this.createIdentifier(e);return this.createMemberExpression(this.createMemberExpression(n,r,!1),i,!1)},createDynamicContextVariableReference(t,e){let n=this.createContextIdentifier(),r=this.createIdentifier(t);return this.createMemberExpression(this.createMemberExpression(n,r,!1),e,!0)},createContextVariableAccess0(t,e){let n=this.createContextVariableReference(t,e);return this.createGetCall(n,0)},createDynamicContextVariableAccess0(t,e){let n=this.createDynamicContextVariableReference(t,e);return this.createGetCall(n,0)},createArrayAccess(t,e){let n=typeof e=="number"?this.createLiteral(e):e;return this.createMemberExpression(t,n,!0)},createCallExpression(t,e){return{type:"CallExpression",callee:t,arguments:e}},createAssignmentExpression(t,e,n="="){return{type:"AssignmentExpression",operator:n,left:t,right:e}},createExpressionStatement(t){return{type:"ExpressionStatement",expression:t}},createInitCall(t,e,n){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("init"),!1),i=[t,e];return n&&i.push(n),this.createCallExpression(r,i)},createInitVarCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("initVar"),!1),r=[t,e];return this.createCallExpression(n,r)},createGetCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("get"),!1),r=typeof e=="number"?this.createLiteral(e):e;return this.createCallExpression(n,[t,r])},createSetCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("set"),!1);return this.createCallExpression(n,[t,e])},createMathEqCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__eq"),!1);return this.createCallExpression(i,[t,e])},createMathNeqCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__neq"),!1);return this.createCallExpression(i,[t,e])},createMathCompareCall(t,e,n){let r=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),i=this.createMemberExpression(r,this.createIdentifier("math"),!1),s=this.createMemberExpression(i,this.createIdentifier(t),!1);return this.createCallExpression(s,[e,n])},createMathIntDivCall(t,e){let n=this.createMemberExpression(this.createContextIdentifier(),this.createIdentifier("pine"),!1),r=this.createMemberExpression(n,this.createIdentifier("math"),!1),i=this.createMemberExpression(r,this.createIdentifier("__idiv"),!1);return this.createCallExpression(i,[t,e])},createWrapperFunction(t){return{type:"FunctionDeclaration",id:null,params:[this.createIdentifier("context")],body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:t}]}}},createVariableDeclaration(t,e){return{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:this.createIdentifier(t),init:e}]}},createAwaitExpression(t){return{type:"AwaitExpression",argument:t}}},vn=["ta","math","request","array","input","color","ticker","strategy"],nt=["hline","plot","fill","label","line","box","linefill","polyline","table","footprint","volume_row","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],Kv=["request.security","request.security_lower_tf","request.footprint"],Gv=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Nc=["plot","hline","fill","strategy.exit"],Yv=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],Ti=new Set([...vn,"fill","plot","hline","label","line","size","extend","display","format","location","shape","text","xloc","yloc","linefill","polyline","box","table","map","matrix","chart","alert","barstate","syminfo","session","timeframe","strategy","log","str","footprint","volume_row","position","font","order","currency","dayofweek","adjustment","barmerge","scale","settlement_as_close"]),Ii=new Set(["arguments","await","case","catch","class","const","debugger","default","delete","do","enum","eval","extends","finally","function","implements","Infinity","instanceof","interface","let","NaN","new","package","private","protected","public","return","static","super","this","throw","try","typeof","undefined","void","with","yield"]),Cc=new Set(["abs","add_col","add_row","avg","binary_search","binary_search_leftmost","binary_search_rightmost","buy_volume","cell","cell_set_bgcolor","cell_set_height","cell_set_text","cell_set_text_color","cell_set_text_font_family","cell_set_text_formatting","cell_set_text_halign","cell_set_text_size","cell_set_text_valign","cell_set_tooltip","cell_set_width","clear","col","columns","concat","contains","copy","covariance","delete","delta","det","diff","down_price","eigenvalues","eigenvectors","elements_count","every","fill","first","get","get_bottom","get_left","get_line1","get_line2","get_price","get_right","get_row_by_price","get_text","get_top","get_x","get_x1","get_x2","get_y","get_y1","get_y2","has_buy_imbalance","has_sell_imbalance","includes","indexof","insert","inv","is_antidiagonal","is_antisymmetric","is_binary","is_diagonal","is_identity","is_square","is_stochastic","is_symmetric","is_triangular","is_zero","join","keys","kron","last","lastindexof","max","median","merge_cells","min","mode","mult","percentile_linear_interpolation","percentile_nearest_rank","percentrank","pinv","poc","pop","pow","push","put","put_all","range","rank","remove","remove_col","remove_row","reshape","reverse","row","rows","sell_volume","set","set_bgcolor","set_border_color","set_border_style","set_border_width","set_bottom","set_bottom_right_point","set_color","set_extend","set_first_point","set_frame_color","set_frame_width","set_left","set_lefttop","set_point","set_position","set_right","set_rightbottom","set_second_point","set_size","set_style","set_text","set_text_color","set_text_font_family","set_text_formatting","set_text_halign","set_text_size","set_text_valign","set_text_wrap","set_textalign","set_textcolor","set_tooltip","set_top","set_top_left_point","set_width","set_x","set_x1","set_x2","set_xloc","set_xy","set_xy1","set_xy2","set_y","set_y1","set_y2","set_yloc","shift","size","slice","some","sort","sort_indices","standardize","stdev","submatrix","sum","swap_columns","swap_rows","total_volume","trace","transpose","unshift","up_price","vah","val","values","variance"]),Xv={footprint:new Set(["buy_volume","sell_volume","total_volume","delta","poc","vah","val","rows","get_row_by_price"]),volume_row:new Set(["up_price","down_price","buy_volume","sell_volume","total_volume","delta","has_buy_imbalance","has_sell_imbalance"])},vh=new Set(["poc","vah","val","get_row_by_price"]),wh=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Jo=[...vn,"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","runtime","footprint","volume_row","Type","bool","int","float","string","timeframe","syminfo","barstate","session","bar_index","last_bar_index","last_bar_time","timenow","ask","bid","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","scale","barmerge","adjustment","backadjustment","settlement_as_close","earnings","dividends","splits"],Zv=["na","nz","plot","plotchar","color","hline","fill"];function Qv(t){let e=null,n=_e;if(t.type==="Program"&&t.body.length>0){let d=t.body[0];if(d.type==="ExpressionStatement"&&(d.expression.type==="ArrowFunctionExpression"||d.expression.type==="FunctionExpression")){let f=d.expression;f.body.type==="BlockStatement"&&(e=f.body.body,f.params.length>0&&f.params[0].type==="Identifier"&&(n=f.params[0].name))}}if(!e)return;let r=new Set,i=new Set,s=d=>{d.type==="Identifier"?r.add(d.name):d.type==="ObjectPattern"?d.properties.forEach(f=>s(f.value)):d.type==="ArrayPattern"&&d.elements.forEach(f=>{f&&s(f)})};je(t,{},{VariableDeclarator(d,f,m){s(d.id),d.init&&m(d.init,f)},FunctionDeclaration(d,f,m){s(d.id);for(let _ of d.params)_&&_.type==="AssignmentPattern"&&_.right&&m(_.right,f);m(d.body,f)},Identifier(d,f,m){i.add(d.name)},MemberExpression(d,f,m){m(d.object,f),d.computed&&m(d.property,f)},Property(d,f,m){d.computed&&m(d.key,f),m(d.value,f)}}),e.forEach(d=>{d.type==="VariableDeclaration"?d.declarations.forEach(f=>s(f.id)):d.type==="FunctionDeclaration"&&s(d.id)});let a=wh,o=Jo,l=a.filter(d=>!r.has(d)),c=o.filter(d=>!r.has(d)),u=l.filter(d=>i.has(d)),p=c.filter(d=>i.has(d)),h=[];u.length>0&&h.push({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"ObjectPattern",properties:u.map(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},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(d=>({type:"Property",key:{type:"Identifier",name:d},value:{type:"Identifier",name:d},kind:"init",shorthand:!0}))},init:{type:"MemberExpression",object:{type:"Identifier",name:n},property:{type:"Identifier",name:"pine"},computed:!1}}]}),h.length>0&&e.unshift(...h)}function Jv(t){let e=null,n=_e;if(t.type==="Program"&&t.body.length>0){let o=t.body[0];if(o.type==="ExpressionStatement"&&(o.expression.type==="ArrowFunctionExpression"||o.expression.type==="FunctionExpression")){let l=o.expression;l.body.type==="BlockStatement"&&(e=l.body.body,l.params.length>0&&l.params[0].type==="Identifier"&&(n=l.params[0].name))}}if(!e)return;let r=new Set(wh),i=new Set(Jo),s=new Set(Zv),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===n&&l.init.property.type==="Identifier"){let c=l.init.property.name,u=null;if(c==="data"?u=r:c==="pine"?u=i: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"){let h=p.key.name,d=p.value.name;u.has(h)&&h!==d&&(a.set(d,h),p.value.name=h,p.shorthand=!0)}});else if(l.id.type==="Identifier"&&vn.includes(c)){let p=c,h=l.id.name;p!==h&&(a.set(h,p),l.id.name=p)}}})}),a.size>0&&je(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 ew(t){try{let e=Go(t,{ecmaVersion:"latest",sourceType:"module"});if(e.type==="Program"&&e.body.length===1){let n=e.body[0];if(n.type==="ExpressionStatement"){let r=n.expression;if(r.type==="ArrowFunctionExpression"||r.type==="FunctionExpression")return{isWrapped:!0,isAsync:r.async||!1,functionNode:r}}if(n.type==="FunctionDeclaration")return{isWrapped:!0,isAsync:n.async||!1,functionNode:n}}return{isWrapped:!1,isAsync:!1}}catch{return{isWrapped:!1,isAsync:!1}}}function tw(t){return t.async=!0,Xo(t)}function nw(t){t=t.trim();let{isWrapped:e,isAsync:n,functionNode:r}=ew(t);return e&&r?n?t:tw(r):`async (context) => {\n${t}\n}`}function rw(t){je(t,null,{VariableDeclaration(e,n,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(i=>{if(i.init&&i.init.type==="ArrowFunctionExpression"&&i.init.start!==0){let s={type:"FunctionDeclaration",id:i.id,params:i.init.params,body:i.init.body.type==="BlockStatement"?i.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:i.init.body}]},async:i.init.async,generator:!1};Object.assign(e,s)}}),e.body&&e.body.body&&e.body.body.forEach(i=>r(i,n))}})}function iw(t){let e=new Set;if(tt(t,{FunctionDeclaration(i){i.id?.name&&e.add(i.id.name)}}),e.size===0)return;let n=i=>i.type==="AssignmentPattern"?i.left:i,r=new Map;tt(t,{FunctionDeclaration(i){let s=new Map;for(let a of i.params){let o=n(a);o?.type==="Identifier"&&e.has(o.name)&&(s.set(o.name,`${o.name}_$arg`),o.name=`${o.name}_$arg`)}s.size!==0&&(r.set(i.id.name,s),Zo(i.body,{Identifier(a,o,l){let c=s.get(a.name);if(!c)return;let u=l[l.length-2];u?.type==="CallExpression"&&u.callee===a||u?.type==="MemberExpression"&&u.property===a&&!u.computed||u?.type==="Property"&&u.key===a&&!u.computed||u?.type==="FunctionDeclaration"&&u.id===a||(a.name=c)}}))}}),tt(t,{AssignmentExpression(i){let s=i.left;if(s?.type!=="MemberExpression"||s.property?.name!=="__pineParamTypes__")return;let a=r.get(s.object?.name);if(!(!a||i.right?.type!=="ObjectExpression"))for(let o of i.right.properties){let l=o.key?.type==="Identifier"?o.key.name:o.key?.value,c=a.get(l);c&&(o.key={type:"Literal",value:c})}}})}function sw(t,e){tt(t,{VariableDeclaration(r){for(let i of r.declarations)if(!(i.id?.type!=="Identifier"||!i.init)&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"&&i.init.callee.name==="Type"&&i.init.arguments?.length===1&&i.init.arguments[0]?.type==="ObjectExpression"){let s={};for(let a of i.init.arguments[0].properties)a.type!=="Property"||a.key?.type!=="Identifier"||(a.value?.type==="ArrayExpression"&&a.value.elements?.[0]?.type==="Literal"?s[a.key.name]=String(a.value.elements[0].value):a.value?.type==="Literal"&&(s[a.key.name]=String(a.value.value)));e.addUdtTypeName(i.id.name,s),i.init._udtName=i.id.name}}});let n=!0;for(;n;)n=!1,tt(t,{FunctionDeclaration(r){if(!r.id?.name)return;let i=r.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=lw(r.body);if(s.length===0)return;if(s.every(l=>l.type==="ArrayExpression")){let l=s[0].elements.length;if(l>0&&s.every(c=>c.elements.length===l)){let c=[],u=!0;for(let p=0;p<l;p++){let h=s.map(f=>Yr(f.elements[p],e)),d=h[0];if(!h.every(f=>f===d)){u=!1;break}c.push(d)}if(u&&c.some(p=>!!p)){e.setFunctionReturnTupleType(i,c),n=!0;return}}}let a=s.map(l=>Yr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),n=!0)}});tt(t,{VariableDeclaration(r){for(let i of r.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=Yr(i.init,e);if(s){e.markVariableAsUdtInstance(i.id.name,s);continue}let a=$a(i.init);a&&e.setVarStaticType(i.id.name,a);continue}if(i.id?.type==="ArrayPattern"&&i.init.type==="CallExpression"&&i.init.callee?.type==="Identifier"){let s=e.getFunctionReturnTupleType(i.init.callee.name);if(!s)continue;i.id.elements?.forEach((a,o)=>{if(!a||a.type!=="Identifier")return;let l=s[o];l&&e.markVariableAsUdtInstance(a.name,l)})}}},ExpressionStatement(r){let i=r.expression;if(i?.type==="Literal"&&typeof i.value=="string"&&i.value.startsWith("__pineUdtVar:")){let s=i.value.match(/^__pineUdtVar:([A-Za-z_$][\\w$]*)=([A-Za-z_$][\\w$]*)$/);if(s){let[,a,o]=s;e.isUdtTypeName(o)&&e.markVariableAsUdtInstance(a,o)}}else if(i?.type==="Literal"&&typeof i.value=="string"&&i.value.startsWith("__pineTypedVar:")){let s=i.value.slice(15),a=s.indexOf("=");if(a>0){let o=s.slice(0,a),l=s.slice(a+1);/^[A-Za-z_$][\\w$]*$/.test(o)&&l&&e.setVarStaticType(o,l)}}}}),tt(t,{ExpressionStatement(r){let i=r.expression;if(!i||i.type!=="AssignmentExpression"||i.operator!=="=")return;let s=i.left;if(s?.type!=="MemberExpression"||s.computed||s.property?.type!=="Identifier"||s.object?.type!=="Identifier")return;let a=s.object.name,o=a.startsWith("$M_")?a.slice(3):a;if(s.property.name==="__pineReceiverType__"){i.right?.type==="Literal"&&typeof i.right.value=="string"&&e.setMethodReceiverType(o,i.right.value);return}if(s.property.name!=="__pineParamTypes__"||i.right?.type!=="ObjectExpression")return;let l={},c={};for(let u of i.right.properties){if(u.type!=="Property")continue;let p;if(u.key?.type==="Identifier"?p=u.key.name:u.key?.type==="Literal"&&typeof u.key.value=="string"&&(p=u.key.value),!p||u.value?.type!=="Literal"||typeof u.value.value!="string")continue;c[p]=u.value.value;let h=u.value.value.split(/\\s+/).pop();e.isUdtTypeName(h)&&(l[p]=h)}Object.keys(l).length>0&&e.setFunctionParamUdtTypes(o,l),Object.keys(c).length>0&&e.setFunctionParamStaticTypes(o,c)}})}var aw=new Set(["table","line","label","box","linefill","polyline","array","matrix","map"]),ow={"request.footprint":"footprint","footprint.poc":"volume_row","footprint.vah":"volume_row","footprint.val":"volume_row","footprint.get_row_by_price":"volume_row"};function $a(t){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"){let e=t.callee.object.name,n=t.callee.property.name;if(aw.has(e)&&(n==="new"||n==="copy"||n==="from"||n.startsWith("new_")))return e;let r=ow[`${e}.${n}`];if(r)return r}if(t.type==="ConditionalExpression"){let e=$a(t.consequent),n=$a(t.alternate);if(e&&e===n)return e}}}function lw(t){let e=[];if(!t)return e;function n(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(let i of Object.keys(r)){if(i==="type")continue;let s=r[i];Array.isArray(s)?s.forEach(n):s&&typeof s=="object"&&s.type&&n(s)}}}return n(t),e}function Yr(t,e){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&(t.callee.property.name==="new"||t.callee.property.name==="copy")&&e.isUdtTypeName(t.callee.object.name))return t.callee.object.name;if(t.type==="CallExpression"&&t.callee?.type==="Identifier"){let n=e.getFunctionReturnType(t.callee.name);if(n)return n}if(t.type==="ConditionalExpression"){let n=Yr(t.consequent,e),r=Yr(t.alternate,e);if(n&&n===r)return n}}}function cw(t,e){tt(t,{VariableDeclaration(n){n.declarations.forEach(r=>{let i=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===_e||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===_e||r.init.object.object.name==="context2");(i||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 uw(t,e,n=!1){t.params.forEach(r=>{r.type==="Identifier"&&n&&e.addContextBoundVar(r.name,n)})}function hw(t,e){let n;return Zo(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){let i=r.expression;if(i&&i.type==="AssignmentExpression"&&i.operator==="="&&i.left?.type==="MemberExpression"&&i.left.property?.name==="__pineMethod__"&&i.left.object?.type==="Identifier"&&i.right?.value===!0){let s=i.left.object.name,a=s.startsWith("$M_")?s.slice(3):s;e.addMethodCandidate(a.replace(/\\$\\d+$/,""),s),e.addUserMethod(a),e.addUserFunction(a)}},ArrowFunctionExpression(r){let i=r.start===0;i&&r.params&&r.params.length>0&&(n=r.params[0].name,r.params[0].name=_e),uw(r,e,i)},VariableDeclaration(r,i){let s=i.length>1?i[i.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;let l=[...i].reverse().find(h=>h!==r&&(h.type==="FunctionDeclaration"||h.type==="FunctionExpression"||h.type==="ArrowFunctionExpression"));if(l&&l.type!=="FunctionDeclaration"&&!(l.type==="ArrowFunctionExpression"&&l.start===0)){o.init={type:"MemberExpression",object:{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:_e},property:{type:"Identifier",name:"toTuple"},computed:!1},arguments:[o.init,{type:"Literal",value:o.id.elements.length}],_transformed:!0},property:{type:"Literal",value:0},computed:!0};return}let c=e.generateTempVar(),u={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:c},init:o.init,_tupleArity:o.id.elements.length}]};o.id.elements?.forEach(h=>{h.type==="Identifier"&&e.addArrayPatternElement(h.name)});let p=o.id.elements.map((h,d)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Literal",value:d},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[u,...p]})}})},ForStatement(r){}}),n}var pw=Object.defineProperty,dw=(t,e,n)=>e in t?pw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fw=(t,e,n)=>dw(t,typeof e!="symbol"?e+"":e,n),mw=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),yw=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function gw(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function _w(t){return t?t.type==="Identifier"?t.name:t.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.property?.type==="Identifier"?`${t.object.name}.${t.property.name}`:null:null}function xw(t){let e=new Set;return(function n(r){if(!(!r||typeof r!="object")){r.type==="AssignmentExpression"&&r.left?.type==="Identifier"?e.add(r.left.name):r.type==="UpdateExpression"&&r.argument?.type==="Identifier"&&e.add(r.argument.name);for(let i in r){if(i==="type"||i==="start"||i==="end"||i==="loc"||i==="raw")continue;let s=r[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&n(a);else s&&typeof s=="object"&&n(s)}}})(t),e}function ja(t,e){return t!=="notint"&&e!=="notint"?"int":"notint"}var Wa=class{constructor(){fw(this,"stack",[new Map])}push(){this.stack.push(new Map)}pop(){this.stack.length>1&&this.stack.pop()}set(e,n){this.stack[this.stack.length-1].set(e,n)}get(e){for(let n=this.stack.length-1;n>=0;n--){let r=this.stack[n].get(e);if(r!==void 0)return r}}assign(e,n){for(let r=this.stack.length-1;r>=0;r--)if(this.stack[r].has(e)){this.stack[r].set(e,ja(this.stack[r].get(e),n));return}this.stack[this.stack.length-1].set(e,ja(n,n))}};function bw(t,e,n={intDivision:!0}){let r=new Wa,i=xw(t);function s(o){if(!o||typeof o!="object")return"notint";switch(o.type){case"Literal":return typeof o.value=="number"&&gw(o)?"constint":"notint";case"Identifier":return mw.has(o.name)?"int":r.get(o.name)??"notint";case"UnaryExpression":return o.operator==="-"||o.operator==="+"?s(o.argument):(s(o.argument),"notint");case"BinaryExpression":{let l=s(o.left),c=s(o.right);if(o.operator==="/"){if(n.intDivision&&l==="constint"&&c==="constint"){let u=N.createMathIntDivCall(o.left,o.right);return Object.assign(o,u),"constint"}return"notint"}return o.operator==="+"||o.operator==="-"||o.operator==="*"||o.operator==="%"?l==="constint"&&c==="constint"?"constint":l!=="notint"&&c!=="notint"?"int":"notint":"notint"}case"ConditionalExpression":{s(o.test);let l=s(o.consequent),c=s(o.alternate);return ja(l,c)}case"LogicalExpression":return s(o.left),s(o.right),"notint";case"CallExpression":{o.callee?.type==="MemberExpression"&&s(o.callee.object);let l=(o.arguments||[]).map(u=>s(u)),c=_w(o.callee);return c==="array.from"&&l.length>0&&l.every(u=>u!=="notint")&&(o.callee.property.name="__from_int"),c&&yw.has(c)?"int":"notint"}case"MemberExpression":return s(o.object),o.computed&&s(o.property),"notint";case"VariableDeclaration":{for(let l of o.declarations||[]){let c=l.init?s(l.init):"notint";l.id?.type==="Identifier"&&(c==="constint"&&(o.kind==="var"||i.has(l.id.name))&&(c="int"),r.set(l.id.name,c))}return"notint"}case"AssignmentExpression":{let l=s(o.right);return o.left?.type==="Identifier"?r.assign(o.left.name,l):s(o.left),l}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":{r.push();for(let l of o.params||[]){let c=l.type==="AssignmentPattern"?l.left:l;c?.type==="Identifier"&&r.set(c.name,"notint")}return s(o.body),r.pop(),"notint"}default:return a(o),"notint"}}function a(o){for(let l in o){if(l==="type"||l==="start"||l==="end"||l==="loc"||l==="raw")continue;let c=o[l];if(Array.isArray(c))for(let u of c)u&&typeof u.type=="string"&&s(u);else c&&typeof c.type=="string"&&s(c)}}s(t)}var vw=new Set(["ArrowFunctionExpression","FunctionExpression","FunctionDeclaration"]),ww=new Set(["&&","||","??"]);function Ic(t){return t!==null&&typeof t=="object"&&typeof t.type=="string"}function Sw(t){return t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.type==="Identifier"&&t.callee.object.name==="request"}function Bt(t,e,n){if(Ic(t)){if(e&&(t._lazyOperand=!0),vw.has(t.type)){Array.isArray(t.params)&&t.params.forEach(r=>Bt(r,e,n)),Bt(t.body,!1,n);return}if(Sw(t)){t._lazyOperand=!1,t.arguments.forEach(r=>Bt(r,!1,n));return}if(t.type==="ConditionalExpression"){Bt(t.test,e,n),Bt(t.consequent,!0,n),Bt(t.alternate,!0,n);return}if(t.type==="LogicalExpression"&&ww.has(t.operator)){if(n.lazyLogical){Bt(t.left,e,n),Bt(t.right,!0,n);return}e&&t.operator!=="??"&&(t._strictLogical=!0)}for(let r of Object.keys(t)){if(r==="parent"||r.startsWith("_"))continue;let i=t[r];Array.isArray(i)?i.forEach(s=>Bt(s,e,n)):Ic(i)&&Bt(i,e,n)}}}function Ew(t,e){Bt(t,!1,e)}var Xs={open:"float",high:"float",low:"float",close:"float",volume:"float",hl2:"float",hlc3:"float",ohlc4:"float",hlcc4:"float",bar_index:"int",last_bar_index:"int",time:"int",time_close:"int"};function Nw(t,e){return!t||!e?!1:t===e||t==="int"&&e==="float"}var Bn={type:"Identifier",name:"undefined"};function mr(t,e){let n={type:"Identifier",name:`\'${e}\'`};if(!t.isInsideFunctionScope())return n;let[r]=t.getVariable("$$");return r?{type:"BinaryExpression",operator:"+",left:N.createMemberExpression(N.createLocalContextIdentifier(),N.createIdentifier("id")),right:n}:n}function Fe(t,e){let[n,r]=e.getVariable(t);if((n.match(/^fn\\d+_/)||e.isVariableInFunctionScope(t))&&t!=="$$"){let[i]=e.getVariable("$$");if(i)return N.createLocalContextVariableReference(r,n)}return N.createContextVariableReference(r,n)}function el(t,e){let n=Fe(t,e);return N.createGetCall(n,0)}function wn(t,e){if(t.computed&&t.property.type==="Identifier"){if(e.isLoopVariable(t.property.name)){if(t.object.type==="Identifier"&&!e.isLoopVariable(t.object.name)){if(e.isLocalSeriesVar(t.object.name)){let n=N.createIdentifier(t.object.name);n._skipTransformation=!0;let r=N.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(!e.isContextBound(t.object.name)){let n=Fe(t.object.name,e),r=N.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0}}return}if(!e.isContextBound(t.property.name))if(e.isLocalSeriesVar(t.property.name)){let n=N.createIdentifier(t.property.name);n._skipTransformation=!0,t.property=N.createGetCall(n,0)}else t.property=Fe(t.property.name,e),t.property=N.createGetCall(t.property,0)}if(t.computed&&t.object.type==="Identifier"){if(e.isLoopVariable(t.object.name))return;if(e.isLocalSeriesVar(t.object.name)){let n=N.createIdentifier(t.object.name);n._skipTransformation=!0;let r=N.createGetCall(n,t.property);Object.assign(t,r),t._indexTransformed=!0;return}if(e.isContextBound(t.object.name)||(t.object=Fe(t.object.name,e)),t.property.type==="MemberExpression"){let n=t.property;n._indexTransformed||(wn(n,e),n._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=vt(t.property,e))}function ht(t,e){let n=N.createGetCall(N.createIdentifier(t.name),0);t.start!==void 0&&(n.start=t.start),t.end!==void 0&&(n.end=t.end),n._indexTransformed=!0,Object.assign(t,n)}function Le(t,e){if(!t._skipTransformation&&t.name!==_e){if(nt.includes(t.name)&&e.isContextBound(t.name)){let h=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,d=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&!t.parent.computed;if(!h&&!d){let f={type:"MemberExpression",object:{type:"Identifier",name:t.name},property:{type:"Identifier",name:"__value"},computed:!1},m=N.createGetCall(f,0);Object.assign(t,m),delete t.name;return}}if(t.name==="Math"||t.name==="NaN"||t.name==="undefined"||t.name==="Infinity"||t.name==="null"||t.name.startsWith("\'")&&t.name.endsWith("\'")||t.name.startsWith(\'"\')&&t.name.endsWith(\'"\')||t.name.startsWith("`")&&t.name.endsWith("`")||e.isLoopVariable(t.name))return;let n=!1;if(t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t)){let h=t.parent.callee;if(h.type==="MemberExpression"&&h.object&&h.object.name===_e&&["get","set","init","param","call"].includes(h.property.name)){let d=t.parent.arguments.indexOf(t);h.property.name==="call"?d>=2&&(n=!0):d===0&&(n=!0)}else{let d=h.type==="MemberExpression"&&h.object&&h.object.type==="Identifier"&&vn.includes(h.object.name);h.type==="MemberExpression"&&!d?n=!1:n=!0}}let r=t.parent&&t.parent.type==="MemberExpression"&&t.parent.object===t&&e.isContextBound(t.name),i=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee&&t.parent.callee.type==="MemberExpression"&&t.parent.callee.property.name==="param";t.parent&&t.parent.type==="AssignmentExpression"&&t.parent.left;let s=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,a=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,o=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.property===t&&t.parent.parent&&t.parent.parent.type==="CallExpression"&&t.parent.parent.callee&&t.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(t.parent.parent.callee.object.name);if(r||i||n||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===_e&&t.parent.callee.property.name==="call"&&t.parent.arguments[0]===t||e.isLocalSeriesVar(t.name)||e.isContextBound(t.name)&&!e.isRootParam(t.name))return;let h=Fe(t.name,e);Object.assign(t,h);return}let l=e.isContextBound(t.name)&&!e.isRootParam(t.name);if(l){let h=t.parent&&t.parent.type==="CallExpression"&&t.parent.arguments.includes(t),d=t.parent&&t.parent.type==="SwitchStatement"&&t.parent.discriminant===t,f=t.parent&&t.parent.type==="SwitchCase"&&t.parent.test===t;if(!h&&!d&&!f)return}if(e.isLocalSeriesVar(t.name)){if(!a){let h=N.createIdentifier(t.name),d=N.createGetCall(h,0);Object.assign(t,d)}return}let[c,u]=e.getVariable(t.name),p;if(l)p=N.createIdentifier(t.name);else{if(c===t.name&&!e.isContextBound(t.name))return;p=Fe(t.name,e)}if(a)Object.assign(t,p);else{let h=N.createGetCall(p,0);Object.assign(t,h)}}}var tl=["CallExpression","BinaryExpression","LogicalExpression","ConditionalExpression","UnaryExpression"];function bs(t,e){return t?.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&vn.includes(t.object.name)&&e.isContextBound(t.object.name)}function Sh(t,e){return t.type==="CallExpression"?(t._transformed||Me(t,e),t):vt(t,e)}function Eh(t,e){if(t.type==="Literal"||t.type==="CallExpression"&&t.callee?.object?.name===_e)return t;if(t.type==="MemberExpression"&&t.computed){wn(t,e);let n=r=>{r.type==="MemberExpression"&&(r.computed&&n(r.property),we(r,"",e))};return n(t),t}return t.type==="CallExpression"?(t._transformed||Me(t,e),t):vt(t,e)}function Ua(t,e){if(t.type!=="Identifier")return Eh(t,e);if(e.isLoopVariable(t.name))return t;if(e.isLocalSeriesVar(t.name)){let n=N.createIdentifier(t.name);return n._skipTransformation=!0,N.createGetCall(n,0)}return N.createGetCall(wr(t,e),0)}function Cw(t,e,n){let r=t.object.name,i={type:"CallExpression",callee:N.createMemberExpression(N.createIdentifier(r),N.createIdentifier(t.property.name)),arguments:r==="ta"?[n.getNextTACallId()]:[],_transformed:!0},s=n.generateParamId(),a={type:"CallExpression",callee:N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("param")),arguments:[i,Bn,{type:"Identifier",name:`\'${s}\'`}],_transformed:!0,_isParamCall:!0};n.addOuterHoistedStatement(N.createVariableDeclaration(s,a));let o=N.createIdentifier(s);o._skipTransformation=!0,o._arrayAccessed=!0;let l=N.createGetCall(o,e);return l._transformed=!0,l._historyTransformed=!0,l}function we(t,e,n){if(t.object&&t.object.type==="Identifier"&&t.object.name==="Math")return;if(t.computed&&bs(t.object,n)){let l=Cw(t.object,Ua(t.property,n),n);Object.assign(t,l),delete t.object,delete t.property,delete t.computed;return}if(t.computed&&t.object&&tl.includes(t.object.type)&&!t._historyTransformed){t.object=Sh(t.object,n),t.property=Ua(t.property,n);let l=n.generateParamId(),c={type:"CallExpression",callee:N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("param")),arguments:[t.object,Bn,mr(n,l)],_transformed:!0,_isParamCall:!0},u=N.createGetCall(c,t.property);u._transformed=!0,u._historyTransformed=!0,Object.assign(t,u),delete t.object,delete t.property,delete t.computed;return}if(t.object&&t.object.type==="Identifier"&&vn.includes(t.object.name)&&n.isContextBound(t.object.name)&&!t.computed){let l=t.parent&&t.parent.type==="CallExpression"&&t.parent.callee===t,c=t.parent&&(t.parent.type==="VariableDeclarator"&&(t.parent.id.type==="ArrayPattern"||t.parent.id.type==="ObjectPattern")||t.parent.type==="AssignmentExpression"&&(t.parent.left.type==="ArrayPattern"||t.parent.left.type==="ObjectPattern")||t.parent.type==="Property");if(!l&&!c){let u={type:"CallExpression",callee:{type:"MemberExpression",object:t.object,property:t.property,computed:!1},arguments:[],_transformed:!1};t.start!==void 0&&(u.start=t.start),t.end!==void 0&&(u.end=t.end),Object.assign(t,u);return}}if(!t.computed&&t.object&&t.object.type==="Identifier"&&n.isLocalSeriesVar(t.object.name)){let l=N.createIdentifier(t.object.name);l._skipTransformation=!0,t.object=N.createGetCall(l,0);return}let r=n.getCurrentScopeType()=="if",i=n.getCurrentScopeType()=="els",s=n.getCurrentScopeType()=="for";if(!r&&!i&&!s&&t.object&&t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)&&!t.computed)return;t._indexTransformed||(wn(t,n),t._indexTransformed=!0);let a=t.object&&t.object.type==="MemberExpression"&&t.object.object&&t.object.object.type==="MemberExpression"&&t.object.object.object&&(t.object.object.object.name===_e||t.object.object.object.name==="$$"),o=t.object&&t.object.type==="Identifier"&&n.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"&&nt.includes(t.object.name)&&n.isContextBound(t.object.name)&&(t.object={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1});let l=N.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"&&n.isUdtInstance(l.object.name)){let c=l.object.name,u=n.isLocalSeriesVar(c)?(()=>{let h=N.createIdentifier(c);return h._skipTransformation=!0,h})():Fe(c,n);l.object=N.createGetCall(u,t.property);let p=t.object;Object.assign(t,p),delete t.computed;return}}}function wr(t,e){if(t.type==="Identifier"){if(nt.includes(t.name)&&e.isContextBound(t.name)){let s=t.name;return Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:s},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name,t}if(e.isLoopVariable(t.name))return t;if(e.isRootParam(t.name)){let[s,a]=e.getVariable(t.name);return N.createContextVariableReference(a,s)}if(e.isContextBound(t.name))return t;let[n,r]=e.getVariable(t.name),i=n!==t.name;return e.isLocalSeriesVar(t.name)&&!i?t:i?Fe(t.name,e):n===t.name&&!e.isContextBound(t.name)?t:Fe(t.name,e)}return t}function vt(t,e,n=""){switch(t.type){case"BinaryExpression":return qa(t,e,n);case"LogicalExpression":return za(t,e,n);case"MemberExpression":{let r=!t.computed&&t.object.type==="Identifier"&&nt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&nt.includes(t.object.name)&&e.isContextBound(t.object.name)){let a={type:"MemberExpression",object:{type:"Identifier",name:t.object.name},property:{type:"Identifier",name:"__value"},computed:!1};return N.createGetCall(a,Ua(t.property,e))}if(t.computed&&bs(t.object,e))return we(t,"",e),t;!t.computed&&t.object.type==="CallExpression"&&!t.object._transformed?Me(t.object,e):!t.computed&&t.object.type==="MemberExpression"&&!t.object.computed&&(t.object=vt(t.object,e,n),t.object.parent=t,we(t.object,"",e));let i=t.object.type==="Identifier"&&!r?wr(t.object,e):t.object,s=i;if(!t.computed&&t.object.type==="Identifier"&&!r){let[a]=e.getVariable(t.object.name);a!==t.object.name&&!e.isLoopVariable(t.object.name)&&(s=N.createGetCall(i,0))}return{type:"MemberExpression",object:s,property:t.property,computed:t.computed}}case"Identifier":{if(e.isLoopVariable(t.name)||t.parent&&t.parent.type==="MemberExpression"&&t.parent.property===t)return t;let r=wr(t,e);return r.type==="Identifier"&&(r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name==="Math")?r:N.createGetCall(r,0)}case"UnaryExpression":return Ha(t,e,n);case"ConditionalExpression":{let r=vt(t.test,e,n),i=vt(t.consequent,e,n),s=vt(t.alternate,e,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function qa(t,e,n){let r=vt(t.left,e,n),i=vt(t.right,e,n),s={type:"BinaryExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return je(s,e,{CallExpression(a,o){a._transformed||Me(a,o)},MemberExpression(a){we(a,"",e)}}),s}function za(t,e,n){let r=vt(t.left,e,n),i=vt(t.right,e,n),s={type:"LogicalExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return je(s,e,{CallExpression(a,o){a._transformed||Me(a,o)}}),s}function Iw(t,e,n){Nh(t,e);let r=N.createMemberExpression(N.createIdentifier(n),N.createIdentifier("param")),i=e.generateParamId(),s={type:"CallExpression",callee:r,arguments:[t,Bn,mr(e,i)],_transformed:!0,_isParamCall:!0};if(!e.shouldSuppressHoisting()){let a=i;e.addLocalSeriesVar(a);let o=N.createVariableDeclaration(a,s);return e.addHoistedStatement(o),N.createIdentifier(a)}return s}function Nh(t,e){je(t,{parent:t,inNamespaceCall:!1},{Identifier(n,r,i){if(n.name=="NaN")return;if(nt.includes(n.name)&&e.isContextBound(n.name)){if(r.parent&&r.parent.type==="MemberExpression"&&r.parent.object===n&&!r.parent.computed)return;let a={type:"MemberExpression",object:{type:"Identifier",name:n.name},property:{type:"Identifier",name:"__value"},computed:!1},o=N.createGetCall(a,0);Object.assign(n,o),delete n.name;return}n.parent=r.parent,Le(n,e);let s=n.parent&&n.parent.type==="BinaryExpression";(n.parent&&n.parent.type==="ConditionalExpression"||s)&&(n.type==="MemberExpression"?wn(n,e):n.type==="Identifier"&&(n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.object&&n.parent.callee.object.name===_e&&n.parent.callee.property.name==="get"||ht(n)))},MemberExpression(n,r,i){we(n,"",e),n.object&&i(n.object,{parent:n,inNamespaceCall:r.inNamespaceCall})},ConditionalExpression(n,r,i){let s={...r,parent:n};n.test&&i(n.test,s),n.consequent&&i(n.consequent,s),n.alternate&&i(n.alternate,s)},BinaryExpression(n,r,i){let s={...r,parent:n};i(n.left,s),i(n.right,s)},LogicalExpression(n,r,i){let s={...r,parent:n};i(n.left,s),i(n.right,s)},UnaryExpression(n,r,i){let s={...r,parent:n};i(n.argument,s)},CallExpression(n,r,i){let s=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&e.isContextBound(n.callee.object.name);Me(n,e),!(n.type!=="CallExpression"||nl(n))&&n.arguments.forEach(a=>i(a,{parent:n,inNamespaceCall:s||r.inNamespaceCall}))}})}function Ha(t,e,n){let r=vt(t.argument,e,n),i={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return je(i,e,{CallExpression(s,a){s._transformed||Me(s,a)},MemberExpression(s){we(s,"",e)}}),i}function kc(t,e){let n=t;for(;n&&n.type==="MemberExpression"&&n.object;){if(n.object.type==="Identifier"){let r=n.object,[i]=e.getVariable(r.name);i!==r.name&&!e.isContextBound(r.name)&&!e.isRootParam(r.name)&&!e.isLoopVariable(r.name)&&!e.isLocalSeriesVar(r.name)&&!nt.includes(r.name)&&!vn.includes(r.name)&&(n.object=el(r.name,e));break}n=n.object}}function yr(t,e,n){switch(t?.type){case"BinaryExpression":t=qa(t,n,e);break;case"LogicalExpression":t=za(t,n,e);break;case"ConditionalExpression":return Iw(t,n,e);case"UnaryExpression":t=Ha(t,n,e);break;case"ArrayExpression":t.elements=t.elements.map(c=>{if(c.type==="Identifier"){if(n.isContextBound(c.name)&&!n.isRootParam(c.name))return nt.includes(c.name)&&c.name!=="na"?N.createMemberExpression(N.createIdentifier(c.name),N.createIdentifier("__value")):c;if(n.isLocalSeriesVar(c.name)){let u=N.createIdentifier(c.name);return N.createGetCall(u,0)}return el(c.name,n)}return c.type==="CallExpression"?(Me(c,n),c):c.type==="BinaryExpression"?qa(c,n,e):c.type==="LogicalExpression"?za(c,n,e):c.type==="ConditionalExpression"?(Nh(c,n),c):c.type==="UnaryExpression"?Ha(c,n,e):(c.type==="MemberExpression"&&(we(c,e,n),c.computed||kc(c,n)),c)});break}t?.type==="MemberExpression"&&t.computed&&bs(t.object,n)&&we(t,"",n);let r=t.type==="MemberExpression"&&t.computed&&t.property,i=t.type==="MemberExpression"&&!t.computed;if(r){if(t.object&&t.object.type==="MemberExpression"){let x=t.object;for(;x.object&&x.object.type==="MemberExpression";)x=x.object;if(x.object?.type==="Identifier"&&n.isUdtInstance(x.object.name)){let w=x.object.name,S=n.isLocalSeriesVar(w)?(()=>{let v=N.createIdentifier(w);return v._skipTransformation=!0,v})():Fe(w,n);return x.object=N.createGetCall(S,t.property),t.object}}let c=tl.includes(t.object.type);c?t.object=Sh(t.object,n):t.object.type==="MemberExpression"&&(we(t.object,"",n),kc(t.object,n),c=t.object.type==="CallExpression");let u=t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)?nt.includes(t.object.name)?N.createMemberExpression(N.createIdentifier(t.object.name),N.createIdentifier("__value")):t.object:wr(t.object,n),p;if(t.property.type==="Identifier"&&!n.isContextBound(t.property.name)&&!n.isLoopVariable(t.property.name))p=N.createGetCall(wr(t.property,n),0);else if(t.property.type==="Identifier"&&n.isContextBound(t.property.name)&&!n.isLoopVariable(t.property.name)){let x=t.property.name,w=nt.includes(x)?N.createMemberExpression(N.createIdentifier(x),N.createIdentifier("__value")):N.createIdentifier(x);p=N.createGetCall(w,0)}else if(t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression")p=vt(t.property,n,e);else if(t.property.type==="MemberExpression"){wn(t.property,n);let x=w=>{w.type==="MemberExpression"&&(w.computed&&x(w.property),we(w,"",n))};x(t.property),p=t.property}else t.property.type==="CallExpression"&&(t.property._transformed||Me(t.property,n)),p=t.property;let h=u,d=p;if(c){let x=n.generateParamId(),w={type:"CallExpression",callee:N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("param")),arguments:[t.object,Bn,mr(n,x)],_transformed:!0,_isParamCall:!0};h=N.createGetCall(w,p),h._transformed=!0,h._historyTransformed=!0,d=Bn}let f=N.createMemberExpression(N.createIdentifier(e),N.createIdentifier("param")),m=n.generateParamId(),_={type:"CallExpression",callee:f,arguments:[h,d,mr(n,m)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let x=m;n.addLocalSeriesVar(x);let w=N.createVariableDeclaration(x,_);return n.addHoistedStatement(w),N.createIdentifier(x)}return _}if(i){if(t.object.type==="Identifier"&&vn.includes(t.object.name)&&n.isContextBound(t.object.name)&&!t.computed){let c=t.object.name,u={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:t.property.name},computed:!1},arguments:[],_transformed:!0};c==="ta"&&u.arguments.push(n.getNextTACallId());let p=n.generateTempVar();n.addLocalSeriesVar(p);let h=N.createVariableDeclaration(p,u);return n.addOuterHoistedStatement(h),Object.assign(t,N.createIdentifier(p)),t}if(t.object.type==="Identifier"){let c=t.object.name,[u,p]=n.getVariable(c);if(u!==c&&!n.isLoopVariable(c)){let h=Fe(c,n),d=N.createGetCall(h,0);t.object=d}else if(n.isLocalSeriesVar(c)){let h=N.createIdentifier(c);h._skipTransformation=!0,t.object=N.createGetCall(h,0)}}else t.object.type==="MemberExpression"?yr(t.object,e,n):t.object.type==="CallExpression"&&(t.object._transformed||Me(t.object,n))}if(t.type==="ObjectExpression"&&(t.properties=t.properties.map(c=>{if(c.value.name){if(nt.includes(c.value.name)&&c.value.name!=="na"&&n.isContextBound(c.value.name)){let u=N.createMemberExpression(N.createIdentifier(c.value.name),N.createIdentifier("__value"));return{...c,shorthand:!1,value:N.createGetCall(u,0)}}return n.isContextBound(c.value.name)||n.isLocalSeriesVar(c.value.name)||n.isLoopVariable(c.value.name)?{type:"Property",key:{type:"Identifier",name:c.key.name},value:N.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:Fe(c.value.name,n),kind:"init",method:!1,shorthand:!1,computed:!1}}else c.value.type!=="Literal"&&(c.value=yr(c.value,e,n));return c})),t.type==="Identifier"){if(nt.includes(t.name)&&n.isContextBound(t.name)){let c=t.name;Object.assign(t,{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Identifier",name:"__value"},computed:!1}),delete t.name}else if(n.isContextBound(t.name)&&!n.isRootParam(t.name)){let c=N.createMemberExpression(N.createIdentifier(e),N.createIdentifier("param")),u=n.generateParamId(),p={type:"CallExpression",callee:c,arguments:[t,Bn,mr(n,u)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let h=u;n.addLocalSeriesVar(h);let d=N.createVariableDeclaration(h,p);return n.addHoistedStatement(d),N.createIdentifier(h)}return p}}t?.type==="CallExpression"&&Me(t,n,e);let s=N.createMemberExpression(N.createIdentifier(e),N.createIdentifier("param")),a=t.type==="Identifier"?wr(t,n):t,o=n.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,Bn,mr(n,o)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let c=o;n.addLocalSeriesVar(c);let u=N.createVariableDeclaration(c,l);return n.addHoistedStatement(u),N.createIdentifier(c)}return l}function Ur(t){if(!t)return!1;if(Ch(t))return!0;if(t.type==="MemberExpression")return Ur(t.object);if(t.type==="ChainExpression")return Ur(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return Ur(e.object);if(e?.type==="ChainExpression")return Ur(e.expression)}return!1}function kw(t,e){if(t?._orderflowType)return t._orderflowType;if(t?.type!=="CallExpression"||t.callee?.type!=="MemberExpression"||t.callee.computed||!vh.has(t.callee.property?.name))return;let n=t.callee.object;return n?.name&&!e.getVariableUdtType(n.name)&&e.getVarStaticType(n.name)==="footprint"?"volume_row":void 0}function Ch(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function Ka(t,e,n){t&&(t.type==="Identifier"?(t.parent=e,Le(t,n)):t.type==="MemberExpression"?(Ka(t.object,t,n),t.parent=e,we(t,"",n),t.type==="CallExpression"&&!t._transformed&&Me(t,n)):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&Ka(t.callee.object,t.callee,n),t._transformed||Me(t,n)))}function nl(t){return!!t&&t.type==="CallExpression"&&t._transformed===!0&&t._lazyOperand===!0}function Me(t,e,n){if(!t._transformed){if(t._lazyOperand===!0&&!e.shouldSuppressHoisting()){e.setSuppressHoisting(!0);try{Ac(t,e,n)}finally{e.setSuppressHoisting(!1)}return}Ac(t,e)}}function Ac(t,e,n){t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(vn.includes(t.callee.name)||nt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=N.createMemberExpression(t.callee,N.createIdentifier("any")));let r=t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.object.name in Xs&&t.callee.property?.type==="Identifier"&&e.isUserMethod(t.callee.property.name),i=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&!r&&(e.isContextBound(t.callee.object.name)||t.callee.object.name==="math"||t.callee.object.name==="ta"),s=!i&&t.callee?.type==="MemberExpression";if(i){if(t.callee.object.name===_e&&["get","init","param"].includes(t.callee.property.name))return;let o=t.callee.object.name;o==="syminfo"&&!t.callee.computed&&["ticker","prefix"].includes(t.callee.property?.name)&&(t.callee.property=N.createIdentifier(`__${t.callee.property.name}`));let l=[];t.arguments.forEach(m=>{if(m._isParamCall){l.push(m);return}l.push(yr(m,o,e))}),t.arguments=l;let c=t.callee.property.name,u=`${o}.${c}`;if(Nc.includes(o)||Nc.includes(u)){let m=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:m,kind:"init",computed:!1,shorthand:!1}]})}if(o==="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}]}),o==="alert"){let m=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:m,kind:"init",computed:!1,shorthand:!1}]})}if(o==="ta"||u==="math.random")if(e.isInsideFunctionScope()){let m=e.getNextTACallId(),[_]=e.getVariable("$$"),x;_?x=N.createMemberExpression(N.createLocalContextIdentifier(),N.createIdentifier("id")):x=N.createLiteral("");let w={type:"BinaryExpression",operator:"+",left:x,right:m};t.arguments.push(w)}else t.arguments.push(e.getNextTACallId());let p=t.callee.property.name,h=`${o}.${p}`,d=Kv.includes(h),f=t._insideAwait===!0;if(d&&!f){let m=Object.assign({},t),_=N.createAwaitExpression(m);Object.assign(t,_)}if(!e.shouldSuppressHoisting()){let m=e.generateTempVar();e.addLocalSeriesVar(m);let _=t._insideAwait===!0,x=Object.assign({},t);_&&(x=N.createAwaitExpression(x));let w=N.createVariableDeclaration(m,x);e.addHoistedStatement(w);let S=N.createIdentifier(m);Object.assign(t,S),t._wasHoisted=!0,t._wasInsideAwait=_;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(o=>o._isParamCall?o:yr(o,_e,e)),t.callee.name==="Type"&&t._udtName&&e.isMethodReceiverTypeName(t._udtName)&&t.arguments.push({type:"Literal",value:t._udtName,raw:JSON.stringify(t._udtName)}),!e.isContextBound(t.callee.name)){let o=e.getNextUserCallId(),l=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("call")),c=t.callee.name,u=t.callee;e.isUserMethod(c)&&!e.isRegularUserFunction(c)&&(u=N.createIdentifier(`$M_${c}`),u._skipTransformation=!0);let p=[u,o,...t.arguments];t.callee=l,t.arguments=p}t._transformed=!0}let a;if(!i&&t.callee&&t.callee.type==="MemberExpression"){let o=t.callee.property.name,l=e.isUserFunction(o),c=t.callee.object,u=e.isUserMethod(o),p;if(c.name)p=e.getVariableUdtType(c.name)??e.getVarStaticType(c.name);else if(c.type==="MemberExpression"&&!c.computed&&c.property?.type==="Identifier"&&c.object?.name){let C=e.getVariableUdtType(c.object.name);if(C){let I=e.getUdtTypeFields(C)?.[c.property.name];p=Va(I)}}let h=c.type==="Literal"?typeof c.value=="string"?"string":typeof c.value=="boolean"?"bool":void 0:c.type==="Identifier"&&c.name in Xs&&e.isContextBound(c.name)?Xs[c.name]:void 0,d=p??h,f=e.getMethodCandidates(o),m=C=>e.getMethodReceiverType(C.slice(3)),_=f.find(C=>Nw(d,m(C))),x=_!==void 0,w=p??kw(c,e);w&&Xv[w]?.has(o)&&(a=w);let S=!!c.name&&e.isUdtInstance(c.name),v=p===void 0&&!Cc.has(o),E=d===void 0&&!S&&(Cc.has(o)||f.length>1);if(l&&u&&(!e.isContextBound(o)||x)&&(x||S||v||E)){let C=t.callee.object;t.callee.property;let I=t.arguments.map(D=>D._isParamCall?D:yr(D,_e,e));C.type==="CallExpression"&&Me(C,e);let F=yr(C,_e,e),$=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("call")),j=e.getNextUserCallId();if(E){let D=(f.length?f:[`$M_${o}`]).map(M=>{let W=N.createIdentifier(M);W._skipTransformation=!0;let k=m(M),V=k&&e.isUdtTypeName(k)?{type:"Literal",value:k,raw:JSON.stringify(k)}:{type:"Literal",value:null,raw:"null"};return{type:"ArrayExpression",elements:[W,V]}});t.callee=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("callMethod")),t.arguments=[{type:"Literal",value:o,raw:JSON.stringify(o)},j,{type:"ArrayExpression",elements:D},F,...I],t._transformed=!0;return}let A=N.createIdentifier(_??f[0]??`$M_${o}`);A._skipTransformation=!0;let ue=[A,j,F,...I];t.callee=$,t.arguments=ue,t._transformed=!0;return}t.callee.object.type==="Identifier"?Le(t.callee.object,e):Ka(t.callee.object,t.callee,e)}if(t.arguments.forEach(o=>{je(o,{parent:t},{Identifier(l,c,u){l.parent=c.parent,Le(l,e);let p=l.parent&&l.parent.type==="BinaryExpression",h=l.parent&&l.parent.type==="ConditionalExpression",d=s&&l.parent?.type==="Property"&&l.parent.value===l;(h||p||d)&&(l.type==="MemberExpression"?wn(l,e):l.type==="Identifier"&&(l.parent&&l.parent.type==="CallExpression"&&l.parent.callee&&l.parent.callee.object&&l.parent.callee.object.name===_e&&l.parent.callee.property.name==="get"||ht(l)))},BinaryExpression(l,c,u){let p={...c,parent:l};u(l.left,p),u(l.right,p)},LogicalExpression(l,c,u){let p={...c,parent:l};u(l.left,p),u(l.right,p)},UnaryExpression(l,c,u){let p={...c,parent:l};u(l.argument,p)},ConditionalExpression(l,c,u){let p=s?{...c,parent:l}:c;u(l.test,p),u(l.consequent,p),u(l.alternate,p)},ObjectExpression(l,c,u){for(let p of l.properties)u(p.value,s?{...c,parent:p}:c)},CallExpression(l,c,u){l.callee&&l.callee.type==="MemberExpression"&&l.callee.object&&(l.callee.object.parent=l.callee,u(l.callee.object,{parent:l.callee})),l._transformed||Me(l,e)},MemberExpression(l,c,u){we(l,"",e),l.object&&u(l.object,{parent:l})}})}),a&&!t._transformed){let o=t.callee.property.name,l=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("pine")),c=N.createMemberExpression(l,N.createIdentifier(a));t.arguments=[t.callee.object,...t.arguments],t.callee=N.createMemberExpression(c,N.createIdentifier(o)),a==="footprint"&&vh.has(o)&&(t._orderflowType="volume_row"),t._transformed=!0;return}if(t.callee&&t.callee.type==="MemberExpression"){let o=t.callee.object,l=Ch(o),c=o?.type==="MemberExpression"&&Ur(o),u=o?.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name===_e&&["call","callMethod"].includes(o.callee.property?.name),p=o?.type==="MemberExpression"&&!o.computed&&o.property?.type==="Identifier"||u,h=!t.callee.computed&&t.callee.property?.name==="delete"&&p;if(!t.callee.computed&&/^(get|set)_\\w+$/.test(t.callee.property?.name??"")&&(l||c||p)&&(t.callee.object={type:"CallExpression",callee:N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("drawingOrNa")),arguments:[o],_transformed:!0}),l||c||h){let d=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:d},t.optional=!0}}}function rl(t){let e={type:"VariableDeclaration",kind:"let",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:t},init:{type:"Literal",value:0}}]},n={type:"IfStatement",test:{type:"BinaryExpression",operator:">",_skipCompare:!0,left:{type:"UpdateExpression",operator:"++",prefix:!0,argument:{type:"Identifier",name:t}},right:{type:"Identifier",name:"__maxLoops"}},consequent:{type:"ThrowStatement",argument:{type:"NewExpression",callee:{type:"Identifier",name:"Error"},arguments:[{type:"Literal",value:`Loop exceeded maximum iterations (${t})`}]}},alternate:null};return{counterDecl:e,guardCheck:n}}function Ji(t,e){let n=null;if(t.left.type==="Identifier")n=Fe(t.left.name,e);else if(t.left.type==="MemberExpression"&&t.left.computed){if(t.left.object.type==="Identifier"){let r=t.left.object.name,[i,s]=e.getVariable(r),a=i!==r,o=e.isContextBound(r);(a||o)&&!e.isLoopVariable(r)&&t.left.property.type==="Literal"&&t.left.property.value===0&&(n=Fe(r,e))}}else if(t.left.type==="MemberExpression"&&!t.left.computed){let r=null,i=t.left;for(;i.type==="MemberExpression"&&!i.computed;){if(i.object.type==="Identifier"){r=i;break}i=i.object}if(r){let s=r.object.name,[a,o]=e.getVariable(s);if(a!==s&&!e.isLoopVariable(s)){let l=Fe(s,e),c=N.createGetCall(l,0);r.object=c}else if(e.isLocalSeriesVar(s)){let l=N.createIdentifier(s);l._skipTransformation=!0,r.object=N.createGetCall(l,0)}}}if(je(t.right,{parent:t.right,inNamespaceCall:!1},{Identifier(r,i,s){let a=i.parent&&i.parent.type==="MemberExpression"&&!i.parent.computed&&i.parent.object===r;if(nt.includes(r.name)&&e.isContextBound(r.name)&&!a){let m={type:"MemberExpression",object:{type:"Identifier",name:r.name},property:{type:"Identifier",name:"__value"},computed:!1},_=N.createGetCall(m,0);Object.assign(r,_),delete r.name;return}r.parent=i.parent,Le(r,e);let 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",d=r.name==="NaN",f=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.object&&r.parent.callee.object.name===_e&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?wn(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!d&&!f&&ht(r))},MemberExpression(r,i,s){we(r,"",e),r.type==="CallExpression"?r.arguments.forEach(a=>s(a,{parent:r,inNamespaceCall:i.inNamespaceCall})):r.object&&s(r.object,{parent:r,inNamespaceCall:i.inNamespaceCall})},CallExpression(r,i,s){let a=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);Me(r,e),!(r.type!=="CallExpression"||nl(r))&&(r.callee.type==="MemberExpression"&&s(r.callee,{parent:r,inNamespaceCall:a||i.inNamespaceCall}),r.arguments.forEach(o=>s(o,{parent:r,inNamespaceCall:a||i.inNamespaceCall})))}}),n){let r=t.right;if(t.operator!=="="){let s=t.operator.replace("=",""),a=N.createGetCall(n,0);r={type:"BinaryExpression",operator:s,left:a,right:t.right,start:t.start,end:t.end}}let i=N.createSetCall(n,r);t.start&&(i.start=t.start),t.end&&(i.end=t.end),Object.assign(t,i)}}function Ih(t,e){t._skipTransformation||t.declarations.forEach(n=>{if(n.init?.type==="CallExpression"&&n.id?.type==="Identifier"){let h=n.init.callee;(h?.type==="MemberExpression"&&h.object?.type==="Identifier"&&h.object.name==="input"||h?.type==="Identifier"&&h.name==="input")&&(n.init._varId=n.id.name)}if(n.init&&n.init.type==="Identifier"&&nt.includes(n.init.name)&&e.isContextBound(n.init.name)){let h=n.init.name;Object.assign(n.init,{type:"MemberExpression",object:{type:"Identifier",name:h},property:{type:"Identifier",name:"__value"},computed:!1}),delete n.init.name}let r=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===_e||n.init.object.name==="context2"),i=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===_e||n.init.object.object.name==="context2"),s=n.init&&n.init.type==="ArrowFunctionExpression";if(r){n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),n.init.object.name=_e;return}if(i){n.id.name&&e.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(h=>{h.key.name&&e.addContextBoundVar(h.key.name)}),n.init.object.object.name=_e;return}e.addVariable(n.id.name,t.kind);let a=t.kind,o=e.isArrayPatternElement(n.id.name)&&n.init&&n.init.type==="MemberExpression"&&n.init.computed;n.init&&!s&&!o&&(n.init.type==="CallExpression"&&n.init.callee.type==="MemberExpression"&&n.init.callee.object&&n.init.callee.object.type==="Identifier"&&e.isContextBound(n.init.callee.object.name)?Me(n.init,e):je(n.init,{parent:n.init},{Identifier(h,d){h.parent=d.parent,Le(h,e);let f=h.parent&&h.parent.type==="BinaryExpression",m=h.parent&&h.parent.type==="UnaryExpression",_=h.parent&&h.parent.type==="ConditionalExpression",x=h.parent&&h.parent.type==="CallExpression"&&h.parent.callee&&h.parent.callee.object&&h.parent.callee.object.name===_e&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(f||m||_)&&!x&&ht(h)},CallExpression(h,d,f){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")&&f(h.callee,{parent:h}),Me(h,e),!(h.type!=="CallExpression"||nl(h))&&(h.callee.type==="MemberExpression"&&f(h.callee,{parent:h}),h.arguments.forEach(m=>f(m,{parent:h})))},BinaryExpression(h,d,f){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),f(h.left,{parent:h}),f(h.right,{parent:h})},LogicalExpression(h,d,f){h.left.type==="Identifier"&&(h.left.parent=h),h.right.type==="Identifier"&&(h.right.parent=h),f(h.left,{parent:h}),f(h.right,{parent:h})},UnaryExpression(h,d,f){h.argument.type==="Identifier"&&(h.argument.parent=h),f(h.argument,{parent:h})},MemberExpression(h,d,f){h.object&&h.object.type==="Identifier"&&(h.object.parent=h),h.property&&h.property.type==="Identifier"&&(h.property.parent=h),we(h,"",e),h.type==="CallExpression"?h.arguments.forEach(m=>f(m,{parent:h})):h.object&&f(h.object,{parent:h})},AwaitExpression(h,d,f){h.argument&&(h.argument._insideAwait=!0,f(h.argument,{parent:h}),h.argument.type==="Identifier"&&h.argument._wasInsideAwait&&Object.assign(h,h.argument))},ArrowFunctionExpression(h,d,f){if(h.body)if(h.body.type==="BlockStatement"){let m=[];h.body.body.forEach(_=>{e.enterHoistingScope(),f(_,{parent:h.body,insideIIFE:!0});let x=e.exitHoistingScope();m.push(...x),m.push(_)}),h.body.body=m}else f(h.body,{parent:h,insideIIFE:!0})},FunctionExpression(h,d,f){if(h.body&&h.body.type==="BlockStatement"){let m=[];h.body.body.forEach(_=>{e.enterHoistingScope(),f(_,{parent:h.body,insideIIFE:!0});let x=e.exitHoistingScope();m.push(...x),m.push(_)}),h.body.body=m}},BlockStatement(h,d,f){let m=[];h.body.forEach(_=>{e.enterHoistingScope(),f(_,{...d,parent:h});let x=e.exitHoistingScope();m.push(...x),m.push(_)}),h.body=m},SwitchStatement(h,d,f){h.discriminant&&(h.discriminant.parent=h,f(h.discriminant,{parent:h})),h.cases&&h.cases.forEach(m=>{m.parent=h,f(m,{parent:h})})},SwitchCase(h,d,f){if(h.test&&(h.test.parent=h,f(h.test,{parent:h})),h.consequent){let m=[];h.consequent.forEach(_=>{e.enterHoistingScope(),_.parent=h,f(_,{parent:h});let x=e.exitHoistingScope();m.push(...x),m.push(_)}),h.consequent=m}},AssignmentExpression(h,d,f){if(d.insideIIFE){if(h.left.type==="Identifier"){let[m]=e.getVariable(h.left.name);if(m===h.left.name&&!e.isContextBound(h.left.name)){f(h.right,{parent:h});return}}Ji(h,e)}}}));let l=Fe(n.id.name,e),c=!o&&n.init&&n.init.type==="MemberExpression"&&n.init.computed&&n.init.property&&(n.init.property.type==="Literal"||n.init.property.type==="MemberExpression");if(n.init?.property?.type==="MemberExpression"&&(n.init.property._indexTransformed||(wn(n.init.property,e),n.init.property._indexTransformed=!0)),a==="var"){let h=e.getCurrentHoistingScope();if(h){for(let d of h)if(d.type==="VariableDeclaration")for(let f of d.declarations){if(!f.init||f.init.type!=="CallExpression")continue;let m=f.init.callee;if(m?.type!=="MemberExpression")continue;let _,x=m.property?.name;if(m.object?.type==="Identifier"?_=m.object.name:m.object?.type==="MemberExpression"&&m.object.property?.name&&(_=m.object.property.name),_&&x){let w=`${_}.${x}`;Yv.includes(w)&&(f.init={type:"ArrowFunctionExpression",params:[],body:f.init,expression:!0,async:!1})}}}}let u;if(n.init)if(s||o)u=n.init;else if(a==="var")u=N.createInitVarCall(l,n.init);else if(n._tupleArity!==void 0){let h=N.createCallExpression(N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("toTuple")),[n.init,N.createLiteral(n._tupleArity)]);u=N.createInitCall(l,h)}else u=N.createInitCall(l,c?n.init.object:n.init,c?n.init.property:void 0);else u=N.createIdentifier("undefined");let p=N.createExpressionStatement(N.createAssignmentExpression(l,u));if(o){let h=n.init.object.name,d=Fe(h,e),f=n.init.property.value,m={type:"MemberExpression",object:N.createGetCall(d,0),property:{type:"Literal",value:f},computed:!0};p.expression.right=N.createCallExpression(N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("init")),[l,m])}s&&(e.pushScope("fn"),je(n.init.body,e,{IfStatement(h,d,f){d.pushScope("if"),h.test&&il(h.test,d),f(h.consequent,d),h.alternate&&(d.pushScope("els"),f(h.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(h,d){Ih(h,d)},Identifier(h,d){Le(h,d)},AssignmentExpression(h,d){Ji(h,d)},SwitchStatement(h,d,f){h.discriminant.parent=h,f(h.discriminant,d),h.cases.forEach(m=>{m.parent=h,f(m,d)})},SwitchCase(h,d,f){h.test&&(h.test.parent=h,f(h.test,d));let m=[];h.consequent.forEach(_=>{d.enterHoistingScope(),f(_,d);let x=d.exitHoistingScope();m.push(...x),m.push(_)}),h.consequent=m},BlockStatement(h,d,f){let m=[];h.body.forEach(_=>{d.enterHoistingScope(),f(_,d);let x=d.exitHoistingScope();m.push(...x),m.push(_)}),h.body=m}}),e.popScope()),Object.assign(t,p)})}function Aw(t,e,n){if(e.setSuppressHoisting(!0),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0],a=s.id.name;e.addLoopVariable(a,a),t.init={type:"VariableDeclaration",kind:t.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:s.init}]},s.init&&je(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,ht(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),we(o,"",e),e.popScope(),o.type==="MemberExpression"&&o.object&&(o.object.type!=="Identifier"||!e.isContextBound(o.object.name))&&c(o.object,l)},CallExpression(o,l,c){o.callee.parent=o,c(o.callee,l);for(let u of o.arguments)c(u,l)}})}t.test&&je(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,ht(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),we(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),t.update&&je(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,ht(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),we(s,"",e),e.popScope(),s.type==="MemberExpression"&&s.object&&(s.object.type!=="Identifier"||!e.isContextBound(s.object.name))&&o(s.object,a)},CallExpression(s,a,o){s.callee.parent=s,o(s.callee,a);for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=rl(r);if(e.addHoistedStatement(i.counterDecl),e.pushScope("for"),n(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck),t.init&&t.init.type==="VariableDeclaration"){let s=t.init.declarations[0];e.removeLoopVariable(s.id.name)}}function Mw(t,e,n){e.setSuppressHoisting(!0),t.test&&il(t.test,e),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=rl(r);e.addHoistedStatement(i.counterDecl),e.pushScope("whl"),n(t.body,e),e.popScope(),t.body.type==="BlockStatement"&&t.body.body.unshift(i.guardCheck)}function il(t,e){je(t,e,{MemberExpression(n,r,i){(n.object&&n.object.type==="Identifier"&&!e.isContextBound(n.object.name)&&!n.computed||n.object&&!n.computed&&(n.object.type==="CallExpression"||n.object.type==="MemberExpression"))&&(n.object.parent=n,i(n.object,r)),we(n,"",e)},CallExpression(n,r){Me(n,r)},BinaryExpression(n,r,i){n.left.type==="Identifier"&&(n.left.parent=n),n.right.type==="Identifier"&&(n.right.parent=n),i(n.left,r),i(n.right,r)},LogicalExpression(n,r,i){n.left.type==="Identifier"&&(n.left.parent=n),n.right.type==="Identifier"&&(n.right.parent=n),i(n.left,r),i(n.right,r)},UnaryExpression(n,r,i){n.argument.type==="Identifier"&&(n.argument.parent=n),i(n.argument,r)},Identifier(n,r){let i=n.parent,s=i&&i.type==="UnaryExpression",a=i&&i.type==="BinaryExpression",o=i&&i.type==="LogicalExpression",l=i&&i.type==="ConditionalExpression";Le(n,r),n.type==="Identifier"&&(s||a||o||l)&&(i&&i.type==="CallExpression"&&i.callee&&i.callee.object&&i.callee.object.name===_e&&i.callee.property?.name==="get"||ht(n));let c=e.getCurrentScopeType()==="if";e.isContextBound(n.name)&&!e.isRootParam(n.name)&&c&&ht(n)}})}function Tw(t,e,n){if(t.test&&(e.pushScope("if"),il(t.test,e),e.popScope()),e.pushScope("if"),n(t.consequent,e),e.popScope(),t.alternate){if(e.pushScope("els"),t.alternate.type==="IfStatement"){let r={type:"BlockStatement",body:[t.alternate]};n(r,e),t.alternate=r.body.length===1&&r.body[0].type==="IfStatement"?r.body[0]:r}else n(t.alternate,e);e.popScope()}}function Mc(t,e,n){let r=t.object;if(!(!r||t.computed))if(r.type==="Identifier"){if(e.isContextBound(r.name))return;r.parent=t,Le(r,e)}else(r.type==="MemberExpression"||r.type==="CallExpression"&&!Pw(r))&&(r.parent=t,n(r,e))}function Pw(t){return t.callee?.type==="MemberExpression"&&t.callee.object?.type==="Identifier"&&t.callee.object.name===_e}function Dw(t){let e=t.object;return e?.type==="MemberExpression"&&e.object?.type==="Identifier"&&e.object.name===_e&&["const","let","var","params"].includes(e.property?.name)}function Ow(t,e){let n=e.getCurrentScopeType();if(t.argument){if(t.argument.type==="ArrayExpression")t.argument.elements=t.argument.elements.map(r=>{if(r.type==="Identifier"){if(e.isContextBound(r.name)&&!e.isRootParam(r.name))return N.createGetCall(r,0);if(e.isLocalSeriesVar(r.name)){let i=N.createIdentifier(r.name);return i._skipTransformation=!0,N.createGetCall(i,0)}return el(r.name,e)}else{if(r.type==="MemberExpression"&&Dw(r))return N.createGetCall(r,0);if(r.type==="MemberExpression"&&r.computed)return we(r,"",e),r;if(r.type==="MemberExpression"||r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")return je(r,e,{Identifier(i,s){Le(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(ht(i),i._arrayAccessed=!0)},MemberExpression(i,s,a){Mc(i,s,a),we(i,"",e)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),Me(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)}}),r}return 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:N.createIdentifier(r.key.name),value:Fe(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=Fe(r.value.name,e))),r));else if(t.argument.type==="Identifier")Le(t.argument,e),t.argument.type==="Identifier"&&ht(t.argument);else if(t.argument.type==="MemberExpression"){if(t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&!(t.argument.computed&&e.isLocalSeriesVar(t.argument.object.name)))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)&&we(t.argument,"",e)}}if(n==="fn"){t.argument.type==="Identifier"&&e.isContextBound(t.argument.name)&&!e.isRootParam(t.argument.name)?t.argument=N.createArrayAccess(t.argument,0):t.argument.type==="MemberExpression"?t.argument.computed&&(tl.includes(t.argument.object.type)||bs(t.argument.object,e))?(we(t.argument,"",e),t.argument._historyTransformed&&(t.argument.arguments[1]=Eh(t.argument.arguments[1],e))):t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)?t.argument.computed?we(t.argument,"",e):t.argument._indexTransformed||(wn(t.argument,e),t.argument._indexTransformed=!0):t.argument.computed&&t.argument.object.type==="Identifier"&&e.isLocalSeriesVar(t.argument.object.name)&&we(t.argument,"",e):(t.argument.type==="BinaryExpression"||t.argument.type==="LogicalExpression"||t.argument.type==="ConditionalExpression"||t.argument.type==="CallExpression"||t.argument.type==="UnaryExpression"||t.argument.type==="AssignmentExpression")&&je(t.argument,e,{Identifier(i,s){Le(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(ht(i),i._arrayAccessed=!0)},MemberExpression(i,s,a){Mc(i,s,a),we(i,"",e)},AssignmentExpression(i,s){Ji(i,s)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),Me(i,s),i.type==="CallExpression"&&i.arguments.forEach(o=>a(o,s))},BinaryExpression(i,s,a){a(i.left,s),a(i.right,s)},ArrowFunctionExpression(i,s,a){if(i.body)if(i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}else a(i.body,s)},FunctionExpression(i,s,a){if(i.body&&i.body.type==="BlockStatement"){let o=[];i.body.body.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.body.body=o}},SwitchStatement(i,s,a){i.discriminant.parent=i,a(i.discriminant,s),i.cases.forEach(o=>{o.parent=i,a(o,s)})},SwitchCase(i,s,a){i.test&&(i.test.parent=i,a(i.test,s));let o=[];i.consequent.forEach(l=>{e.enterHoistingScope(),a(l,s);let c=e.exitHoistingScope();o.push(...c),o.push(l)}),i.consequent=o},BlockStatement(i,s,a){let o=[];i.body.forEach(l=>{s.enterHoistingScope(),a(l,s);let c=s.exitHoistingScope();o.push(...c),o.push(l)}),i.body=o}});let r=N.createCallExpression(N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("precision")),[t.argument]);t.argument=r}}}function Rw(t,e,n){let r=N.createVariableDeclaration("$$",N.createCallExpression(N.createMemberExpression(N.createContextIdentifier(),N.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(u=>{u.type==="Identifier"?e.addLocalSeriesVar(u.name):u.type==="AssignmentPattern"&&u.left?.type==="Identifier"&&e.addLocalSeriesVar(u.left.name)});let i=t.id?.name,s=i?.startsWith("$M_")?i.slice(3):i,a=s?e.getFunctionParamUdtTypes(s):void 0,o={};if(a)for(let[u,p]of Object.entries(a))o[u]=e.getVariableUdtType(u),e.markVariableAsUdtInstance(u,p);let l=s?e.getFunctionParamStaticTypes(s):void 0,c={};if(l)for(let[u,p]of Object.entries(l))c[u]=e.getVarStaticType(u),e.setVarStaticType(u,p);if(n(t.body,e),t.params.forEach(u=>{u.type==="Identifier"?e.removeLocalSeriesVar(u.name):u.type==="AssignmentPattern"&&u.left?.type==="Identifier"&&e.removeLocalSeriesVar(u.left.name)}),a)for(let u of Object.keys(a)){e.unmarkVariableAsUdtInstance(u);let p=o[u];p!==void 0&&e.markVariableAsUdtInstance(u,p)}if(l)for(let u of Object.keys(l)){e.unsetVarStaticType(u);let p=c[u];p!==void 0&&e.setVarStaticType(u,p)}e.popScope()}}function Lw(t){let e={...O,LineComment:()=>{}};function n(o){return o?o.type==="Identifier"?o.name:o.type==="CallExpression"&&o.callee?.type==="MemberExpression"&&o.callee.object?.name==="$"&&o.callee.property?.name==="get"&&o.arguments?.[0]?.type==="Identifier"?o.arguments[0].name:null:null}let r=new Map;tt(t,{FunctionDeclaration(o){o.id?.name&&r.set(o.id.name,o)}},e);function i(o){let l=!1,c={...e,FunctionDeclaration:()=>{},FunctionExpression:()=>{},ArrowFunctionExpression:()=>{}};return tt(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,tt(t,{ArrowFunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)},FunctionExpression(c){!c.async&&i(c.body)&&(c.async=!0,s=!0)}},e);let o=[];tt(t,{CallExpression(c){!c._asyncWrapped&&(c.callee?.type==="ArrowFunctionExpression"||c.callee?.type==="FunctionExpression")&&c.callee.async===!0&&o.push(c)}},e);for(let c of o){let u={};for(let p of Object.keys(c))u[p]=c[p];u._asyncWrapped=!0;for(let p of Object.keys(c))delete c[p];c.type="AwaitExpression",c.argument=u,s=!0}let l=new Set;for(let[c,u]of r)i(u.body)&&(u.async||(u.async=!0,s=!0),l.add(c));if(l.size>0){let c=[];tt(t,{CallExpression(u){if(!u._asyncWrapped&&u.callee?.type==="MemberExpression"&&u.callee.object?.name==="$"&&u.callee.property?.name==="call"&&u.arguments?.length>0){let p=n(u.arguments[0]);p&&l.has(p)&&c.push(u)}}},e);for(let u of c){let p={};for(let h of Object.keys(u))p[h]=u[h];p._asyncWrapped=!0;for(let h of Object.keys(u))delete u[h];u.type="AwaitExpression",u.argument=p,s=!0}}}}var Fw={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},Vw=new Set(["<","<=",">",">="]);function Bw(t,e){if(t._skipCompare)return!0;for(let n=0;n<e.length-1;n++){let r=e[n],i=e[n+1];if(r.type==="ForStatement"&&(i===r.test||i===r.update)||(r.type==="WhileStatement"||r.type==="DoWhileStatement")&&i===r.test)return!0}return!1}function $w(t){let e={...O,LineComment:()=>{}};Zo(t,{BinaryExpression(n,r,i){let s=Fw[n.operator];if(!s||Vw.has(n.operator)&&Bw(n,i))return;let a=N.createMathCompareCall(s,n.left,n.right);a._transformed=!0,Object.assign(n,a)}},e)}var jw={"&&":"__and","||":"__or"};function Ww(t){let e={...O,LineComment:()=>{}};tt(t,{LogicalExpression(n){if(!n._strictLogical)return;let r=jw[n.operator];if(!r)return;let i=N.createMathCompareCall(r,n.left,n.right);i._transformed=!0,Object.assign(n,i),delete n.operator,delete n.left,delete n.right}},e)}var Uw={"+":"__union","-":"__minus"};function Tc(t){return t?.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.object.name==="display"?!0:t?.type==="CallExpression"&&t._displaySetOp===!0}function qw(t){let e={...O,LineComment:()=>{}};tt(t,{BinaryExpression(n){let r=Uw[n.operator];if(!r||!Tc(n.left)&&!Tc(n.right))return;let i=N.createMemberExpression(N.createIdentifier("display"),N.createIdentifier(r),!1),s=N.createCallExpression(i,[n.left,n.right]);s._displaySetOp=!0,Object.assign(n,s)}},e)}function zw(t,e,n,r={debug:!1,ln:!1},i=[]){let s=a=>{if(!r.debug||!a.loc||!i.length)return null;let o=a.loc.start.line-1;if(o>=0&&o<i.length){let l=i[o].trim();if(l)return{type:"LineComment",value:`${r.ln?` [Line ${a.loc.start.line}]`:""} ${l}`}}return null};je(t,e,{Program(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let p=o.exitHoistingScope(),h=s(u);h&&c.push(h),c.push(...p),c.push(u)}),a.body=c},BlockStatement(a,o,l){let c=[];a.body.forEach(u=>{o.enterHoistingScope(),l(u,o);let 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),Ow(a,o)},VariableDeclaration(a,o){Ih(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)),Me(a,o)},ArrowFunctionExpression(a,o,l){a.body&&l(a.body,o)},FunctionExpression(a,o,l){a.body&&l(a.body,o)},ForOfStatement(a,o,l){if(a.left&&a.left.type==="VariableDeclaration"){a.left._skipTransformation=!0;let 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"&&ht(a.right)):l(a.right,o);let p=a.left&&a.left.type==="VariableDeclaration"&&a.left.declarations[0].id.type==="ArrayPattern"?"entries":"iter",h={...a.right},d=N.createCallExpression(N.createMemberExpression(N.createIdentifier("$"),N.createIdentifier(p),!1),[h]);Object.assign(a.right,d)}let c=o.getNextLoopGuardName(),u=rl(c);if(o.addHoistedStatement(u.counterDecl),a.body&&l(a.body,o),a.body&&a.body.type==="BlockStatement"&&a.body.body.unshift(u.guardCheck),a.left&&a.left.type==="VariableDeclaration"){let 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"&&ht(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)),we(a,n,o)},AssignmentExpression(a,o,l){if(Ji(a,o),a.type==="CallExpression"&&a.arguments){let c=u=>{u&&(u.type==="CallExpression"&&u.callee&&(u.callee.type==="ArrowFunctionExpression"||u.callee.type==="FunctionExpression")&&l(u.callee,o),u.type==="BinaryExpression"&&(c(u.left),c(u.right)))};a.arguments.forEach(u=>c(u))}},FunctionDeclaration(a,o,l){Rw(a,o,l)},ForStatement(a,o,l){Aw(a,o,l)},WhileStatement(a,o,l){Mw(a,o,l)},IfStatement(a,o,l){Tw(a,o,l)},SwitchStatement(a,o,l){a.discriminant.parent=a,l(a.discriminant,o),a.cases.forEach(c=>{c.parent=a,l(c,o)})},SwitchCase(a,o,l){a.test&&(a.test.parent=a,l(a.test,o));let c=[];a.consequent.forEach(u=>{o.enterHoistingScope(),l(u,o);let 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))}})}var Hw=Object.defineProperty,Kw=(t,e,n)=>e in t?Hw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Zs=(t,e,n)=>Kw(t,typeof e!="symbol"?e+"":e,n),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"},Gw=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","as","import","export","method","enum"]),Yw=new Set(["type","method","enum"]),Pc=new Set(["catch","class","do","ellipse","is","polygon","range","return","struct","text","throw","try"]),Xw=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],Ga=class{constructor(e,n,r,i,s=0,a=null){this.type=e,this.value=n,this.line=r,this.column=i,this.indent=s,this.raw=a,Zs(this,"wrapped",null),Zs(this,"grouped",!1),Zs(this,"startColumn")}},Zw=Object.defineProperty,Qw=(t,e,n)=>e in t?Zw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kt=(t,e,n)=>Qw(t,typeof e!="symbol"?e+"":e,n),kh=class qr{constructor(e){kt(this,"source"),kt(this,"pos"),kt(this,"line"),kt(this,"column"),kt(this,"tokens"),kt(this,"indentStack"),kt(this,"atLineStart"),kt(this,"parenDepth"),kt(this,"bracketDepth"),kt(this,"braceDepth"),kt(this,"pendingWrap",null),this.source=e,this.pos=0,this.line=1,this.column=1,this.tokens=[],this.indentStack=[0],this.atLineStart=!0,this.parenDepth=0,this.bracketDepth=0,this.braceDepth=0}tokenize(){for(;this.pos<this.source.length;){let e=this.peek();if(e==="\\r"){this.advance();continue}if(e===`\n`){this.handleNewline();continue}if(this.atLineStart&&e!==`\n`){this.handleIndentation(),this.atLineStart=!1;continue}if(e===" "||e===" "){this.advance();continue}if(this.pos>=this.source.length)break;if(e==="/"&&this.peek(1)==="/"){this.readComment();continue}if(e===\'"\'||e==="\'"){this.readString();continue}if(e==="#"){this.readColorLiteral();continue}if(this.isDigit(e)){this.readNumber();continue}if(this.isIdentifierStart(e)){this.readIdentifier();continue}if(!this.readOperatorOrPunctuation())throw new Error(`Unexpected character \'${e}\' at ${this.line}:${this.column}`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.addToken(g.DEDENT,"",this.getCurrentIndent());return this.addToken(g.EOF,""),this.resolveContextualKeywords(),this.tokens}resolveContextualKeywords(){let e=r=>r.type===g.NEWLINE||r.type===g.INDENT||r.type===g.DEDENT||r.type===g.COMMENT,n=r=>!!r&&(r.type===g.IDENTIFIER||r.type===g.KEYWORD);for(let r=0;r<this.tokens.length;r++){let i=this.tokens[r];if(i.type!==g.KEYWORD||!Yw.has(i.value))continue;let s=r-1;for(;s>=0&&this.tokens[s].type===g.COMMENT;)s--;let a=s>=0?this.tokens[s]:null;!i.wrapped&&(a===null||e(a)||a.type===g.KEYWORD&&a.value==="export")&&n(this.tokens[r+1])||(i.type=g.IDENTIFIER)}}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(g.NEWLINE,`\n`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0;for(;this.pos<this.source.length;){let i=this.peek();if(i===" ")e+=1,this.advance();else if(i===" ")e+=qr.TAB_WIDTH,this.advance();else break}if(this.peek()===`\n`||this.peek()==="\\r"||this.peek()==="\\0"||this.peek()==="/"&&this.peek(1)==="/")return;if(e%qr.TAB_WIDTH!==0||this.isContinuationFromPrevToken()){this.joinWithPreviousLine(e);return}let n=e/qr.TAB_WIDTH,r=this.indentStack[this.indentStack.length-1];if(n>r){if(n>r+1){let i=(r+1)*qr.TAB_WIDTH;throw new Error(`Indentation error at ${this.line}:${this.column} - line is indented by ${e} columns, but a local block must be indented by exactly one level (${i} columns: four spaces or one tab) deeper than the enclosing block`)}this.indentStack.push(n),this.addToken(g.INDENT,"",n)}else if(n<r){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>n;)this.indentStack.pop(),this.addToken(g.DEDENT,"",this.indentStack[this.indentStack.length-1]);if(this.indentStack[this.indentStack.length-1]!==n)throw new Error(`Indentation error at ${this.line}:${this.column} - misaligned dedent`)}}joinWithPreviousLine(e){let n=null;for(;this.tokens.length>0;){let r=this.tokens[this.tokens.length-1];if(r.type!==g.NEWLINE&&r.type!==g.COMMENT)break;this.tokens.pop()}this.tokens.length!==0&&(n=this.tokens[this.tokens.length-1].line,this.pendingWrap={width:e,fromLine:n,column:this.column})}isContinuationFromPrevToken(){for(let e=this.tokens.length-1;e>=0;e--){let n=this.tokens[e];if(!(n.type===g.NEWLINE||n.type===g.COMMENT))return n.type===g.OPERATOR?n.value!=="=>":n.type===g.COMMA||n.type===g.COLON||n.type===g.KEYWORD&&(n.value==="and"||n.value==="or")}return!1}readComment(){this.column;let e="";for(this.advance(),this.advance();this.pos<this.source.length&&this.peek()!==`\n`;)e+=this.advance();this.parenDepth>0||this.bracketDepth>0||this.braceDepth>0||this.addToken(g.COMMENT,e.trim())}readString(){if(this.peek(1)===this.peek()&&this.peek(2)===this.peek()){this.readMultilineString();return}let e=this.advance(),n=this.column-1,r="";for(;this.pos<this.source.length&&this.peek()!==e;)this.peek()==="\\\\"?r+=this.readEscape(e):r+=this.advance();if(this.peek()!==e)throw new Error(`Unterminated string at ${this.line}:${n}`);this.advance(),this.addToken(g.STRING,r),this.tokens[this.tokens.length-1].startColumn=n}readEscape(e){this.advance();let n=this.advance();switch(n){case"n":return`\n`;case"t":return" ";case"r":return"\\r";case"\\\\":return"\\\\";case e:return e;default:return n}}readMultilineString(){let e=this.peek(),n=this.line,r=this.column;this.advance(),this.advance(),this.advance();let i="";for(;this.pos<this.source.length;){let s=this.peek();if(s===e&&this.peek(1)===e&&this.peek(2)===e){this.advance(),this.advance(),this.advance(),this.addToken(g.STRING,i);return}if(s==="\\r"){this.advance();continue}if(s===`\n`){this.advance(),this.line++,this.column=1,i+=`\n`;continue}if(s==="\\\\"){i+=this.readEscape(e);continue}i+=this.advance()}throw new Error(`Unterminated multiline string at ${n}:${r}`)}readColorLiteral(){let e=this.column,n="#";for(this.advance();this.pos<this.source.length&&n.length<9;){let r=this.peek();if(r>="0"&&r<="9"||r>="A"&&r<="F"||r>="a"&&r<="f")n+=this.advance();else break}if(n.length!==7&&n.length!==9)throw new Error(`Invalid color literal \'${n}\' at ${this.line}:${e}`);this.addToken(g.STRING,n)}readNumber(){this.column;let e="",n=!1;for(this.peek()==="."&&this.isDigit(this.peek(1))&&(n=!0,e+=this.advance());this.pos<this.source.length;){let r=this.peek();if(this.isDigit(r))e+=this.advance();else if(r==="."&&!n){let i=this.peek(1);if(this.isDigit(i)||!this.isIdentifierStart(i)){if(n=!0,e+=this.advance(),!this.isDigit(this.peek()))break}else break}else break}if(this.pos<this.source.length){let r=this.peek();if(r==="e"||r==="E"){let i=this.peek(1);if(this.isDigit(i))for(e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance();else if(i==="+"||i==="-"){let s=this.peek(2);if(this.isDigit(s))for(e+=this.advance(),e+=this.advance();this.pos<this.source.length&&this.isDigit(this.peek());)e+=this.advance()}}}this.addToken(g.NUMBER,parseFloat(e),null,e)}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();Gw.has(e)?this.addToken(g.KEYWORD,e):e==="true"||e==="false"?this.addToken(g.BOOLEAN,e==="true"):this.addToken(g.IDENTIFIER,e)}readOperatorOrPunctuation(){let e=this.peek(),n=this.peek(1),r=e+n;if(Xw.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"[":{let i=this.parenDepth>0||this.bracketDepth>0||this.braceDepth>0;return this.bracketDepth++,this.advance(),this.addToken(g.LBRACKET,e),this.tokens[this.tokens.length-1].grouped=i,!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){let n=this.pos+e;return n<this.source.length?this.source[n]:"\\0"}advance(){let e=this.source[this.pos++];return this.column++,e}skipWhitespaceInline(){if(!this.atLineStart)for(;this.pos<this.source.length&&(this.peek()===" "||this.peek()===" ");)this.advance()}isDigit(e){return e>="0"&&e<="9"}isIdentifierStart(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}isIdentifierChar(e){return this.isIdentifierStart(e)||this.isDigit(e)}getCurrentIndent(){return this.indentStack[this.indentStack.length-1]}addToken(e,n,r=null,i=null){let s=new Ga(e,n,this.line,this.column,r!==null?r:this.getCurrentIndent(),i);this.pendingWrap&&(s.wrapped=this.pendingWrap,this.pendingWrap=null),this.tokens.push(s)}};kt(kh,"TAB_WIDTH",4);var Jw=kh,eS=Object.defineProperty,tS=(t,e,n)=>e in t?eS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,wt=(t,e,n)=>tS(t,typeof e!="symbol"?e+"":e,n),de=class{constructor(e){this.type=e}},Ya=class extends de{constructor(e){super("Program"),this.body=e}},Qe=class extends de{constructor(e){super("ExpressionStatement"),this.expression=e}},Xt=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(Xt||{}),Mt=class extends de{constructor(e,n="let"){super("VariableDeclaration"),this.declarations=e,this.kind=n}},bt=class extends de{constructor(e,n,r=null){super("VariableDeclarator"),this.id=e,this.init=n,this.varType=r}},es=class extends de{constructor(e,n,r,i=null){super("FunctionDeclaration"),this.id=e,this.params=n,this.body=r,this.returnType=i}},Xa=class extends de{constructor(e,n){super("TypeDefinition"),this.name=e,this.fields=n}},Xr=class extends de{constructor(e,n,r=null){super("IfStatement"),this.test=e,this.consequent=n,this.alternate=r,wt(this,"_line")}},ts=class extends de{constructor(e,n,r,i){super("ForStatement"),this.init=e,this.test=n,this.update=r,this.body=i,wt(this,"isForIn")}},Za=class extends de{constructor(e,n){super("WhileStatement"),this.test=e,this.body=n}},Tt=class extends de{constructor(e){super("BlockStatement"),this.body=e}},ns=class extends de{constructor(e){super("ReturnStatement"),this.argument=e}},he=class extends de{constructor(e){super("Identifier"),this.name=e,wt(this,"varType"),wt(this,"returnType"),wt(this,"isMethod")}},Je=class extends de{constructor(e,n=null){super("Literal"),this.value=e,this.raw=n}},$t=class extends de{constructor(e,n,r){super("BinaryExpression"),this.operator=e,this.left=n,this.right=r}},Zr=class extends de{constructor(e,n,r=!0){super("UnaryExpression"),this.operator=e,this.argument=n,this.prefix=r}},kn=class extends de{constructor(e,n,r){super("AssignmentExpression"),this.operator=e,this.left=n,this.right=r}},rs=class extends de{constructor(e,n,r=!1){super("UpdateExpression"),this.operator=e,this.argument=n,this.prefix=r}},Qa=class extends de{constructor(e,n){super("CallExpression"),this.callee=e,this.args=n,wt(this,"arguments"),this.callee=e,this.arguments=n}},is=class extends de{constructor(e,n,r=!1){super("MemberExpression"),this.object=e,this.property=n,this.computed=r}},Jt=class extends de{constructor(e,n,r){super("ConditionalExpression"),this.test=e,this.consequent=n,this.alternate=r,wt(this,"needsIIFE"),wt(this,"consequentStmts"),wt(this,"alternateStmts")}},Ja=class extends de{constructor(e){super("ArrayExpression"),this.elements=e}},ai=class extends de{constructor(e){super("ObjectExpression"),this.properties=e}},Ir=class extends de{constructor(e,n){super("Property"),this.key=e,this.value=n,wt(this,"kind"),wt(this,"method"),wt(this,"shorthand"),wt(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},ss=class extends de{constructor(e){super("ArrayPattern"),this.elements=e}},as=class extends de{constructor(e,n){super("AssignmentPattern"),this.left=e,this.right=n}},eo=class extends de{constructor(e,n){super("SwitchExpression"),this.discriminant=e,this.cases=n}},to=class extends de{constructor(e,n,r){super("SwitchCase"),this.test=e,this.consequent=n,this.statements=r,this.statements=r}},nS=Object.defineProperty,rS=(t,e,n)=>e in t?nS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,At=(t,e,n)=>rS(t,typeof e!="symbol"?e+"":e,n),Ah=class Mh{constructor(e){At(this,"tokens"),At(this,"pos"),At(this,"functionNames",new Set),At(this,"typeNames",new Set),At(this,"typeVariableNames",new Set),At(this,"paramScopes",[]),At(this,"loopValueCounter",0),At(this,"onceCounter",0),At(this,"functionTupleArity",new Map),At(this,"functionParamNames",new Map),At(this,"tupleLiteralStart",new WeakMap),this.tokens=e,this.pos=0}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}isCurrentFunctionParam(e){for(let n of this.paramScopes)if(n.has(e))return!0;return!1}advance(){return this.tokens[this.pos++]}match(e,n=null){let r=this.peek();return!(r.type!==e||n!==null&&r.value!==n)}expect(e,n=null){let r=this.peek();if(r.type!==e)throw new Error(`Expected ${e} but got ${r.type} at ${r.line}:${r.column}${this.layoutHint(r)}`);if(n!==null&&r.value!==n)throw new Error(`Expected \'${n}\' but got \'${r.value}\' at ${r.line}:${r.column}${this.layoutHint(r)}`);return this.advance()}unexpected(e){if(e.type===g.INDENT){let i=this.tokens[this.tokens.indexOf(e)+1]??e;return new Error(`Unexpected indentation at ${e.line}:${e.column} - \'${i.value}\' is indented as a local block, but the previous statement does not open one. A line indented by a multiple of four columns starts a new statement; to wrap a long line, indent the continuation by a number of columns that is not a multiple of four`)}let n=e.type===g.NEWLINE?"end of line":e.value,r=e.wrapped?e.wrapped.column:e.column;return new Error(`Unexpected token ${e.type} \'${n}\' at ${e.line}:${r}${this.layoutHint(e)}`)}layoutHint(e){let n=e.wrapped;if(!n)return"";let r=n.width%4!==0?`is indented by ${n.width} columns, which is not a multiple of four, so it continues line ${n.fromLine} (Pine line wrapping)`:`continues line ${n.fromLine}, which ends with an operator`;return` - line ${e.line} ${r}. A statement inside a local block must be indented by four spaces or one tab per level`}rejectDanglingWrappedLine(){let e=this.peek();if(e.wrapped&&e.type!==g.COMMA)throw this.unexpected(e)}startsNewLine(){let e=this.peek();if(e.wrapped||e.grouped)return!1;let n=this.pos-1;for(;n>=0&&this.tokens[n].type===g.DEDENT;)n--;if(n<0)return!0;let r=this.tokens[n];return r.type===g.NEWLINE||r.line!==e.line}reservedNameError(e){let n=e.column-String(e.value).length;return new Error(`"${e.value}" cannot be used as a variable or function name. at ${e.line}:${n}`)}isReservedName(e){return e.type===g.KEYWORD||e.type===g.IDENTIFIER&&Pc.has(e.value)}expectName(){let e=this.peek();if(this.isReservedName(e))throw this.reservedNameError(e);if(e.type!==g.IDENTIFIER)throw new Error(`Expected ${g.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`);return this.advance()}assertDeclarableName(e,n){if(e?.type==="Identifier"&&Pc.has(e.name))throw this.reservedNameError(n)}assertParamDefault(e,n){if(e?.type==="CallExpression")throw new Error(`The default value cannot be a function, variable or calculation. at ${this.startOf(n)}`);if(e?.type==="BinaryExpression"||e?.type==="LogicalExpression"||e?.type==="ConditionalExpression")throw new Error(`The default value assigned to a parameter must be either a literal value (e.g., "5") or a built-in variable (e.g., "close"). at ${this.startOf(n)}`)}startOf(e){return`${e.line}:${e.column-String(e.value).length}`}dottedName(e){if(e?.type==="Identifier")return e.name;if(e?.type==="MemberExpression"&&!e.computed&&e.property?.type==="Identifier"){let n=this.dottedName(e.object);return n===null?null:`${n}.${e.property.name}`}return null}tupleArityOf(e){if(!(e?.type!=="CallExpression"||e.callee?.type!=="Identifier"))return this.functionTupleArity.get(e.callee.name)??void 0}assertNotTupleLiteral(e){if(e?.type==="ArrayExpression"){let n=this.tupleLiteralStart.get(e);throw new Error(`Syntax error at input "["${n?` at ${this.startOf(n)}`:""}`)}}assertNotTupleAssignment(e,n,r){if(this.assertNotTupleLiteral(n),e?.type==="Identifier"&&this.tupleArityOf(n)!==void 0)throw new Error(`Invalid assignment. Cannot assign a tuple to a variable "${e.name}". at ${this.startOf(r)}`)}rejectReservedAssignmentTarget(){let e=this.peek(),n=this.peek(1);if(this.isReservedName(e)&&n.type===g.OPERATOR&&n.value==="=")throw this.reservedNameError(e)}isNameSlot(e){return e.type===g.IDENTIFIER?!0:e.type===g.KEYWORD&&!Mh.STATEMENT_KEYWORDS.has(e.value)}peekOperatorEx(e){let n=this.peek();return n.type!==g.OPERATOR||!e.includes(n.value)?null:n.value}isLayoutToken(){return this.match(g.NEWLINE)||this.match(g.COMMENT)}skipNewlines(e=!1){for(;this.isLayoutToken();)this.advance();e&&this.match(g.INDENT)&&this.advance()}parse(){let e=[];for(this.collectTopLevelFunctionNames();!this.match(g.EOF);){if(this.skipNewlines(),this.match(g.DEDENT)){this.advance();continue}if(this.match(g.EOF))break;let n=this.parseStatement();n&&e.push(n),this.skipNewlines()}return new Ya(e)}collectTopLevelFunctionNames(){let e=0;for(let r=0;r<this.tokens.length;r++){let i=this.tokens[r];i.type===g.INDENT?e++:i.type===g.DEDENT&&e--;let s=r===0||this.tokens[r-1].type===g.NEWLINE||this.tokens[r-1].type===g.DEDENT;if(e===0&&i.type===g.KEYWORD&&i.value==="type"&&r+1<this.tokens.length){let o=this.tokens[r-1];(s||o?.type===g.KEYWORD&&o.value==="export")&&this.typeNames.add(this.tokens[r+1].value)}if(e!==0||!s||i.type!==g.IDENTIFIER||(this.pos=r,!this.isFunctionDeclaration()))continue;let a=this.peek(1).type!==g.LPAREN;this.functionNames.add(this.peek(a?1:0).value)}this.pos=0;let n=0;for(let r=0;r<this.tokens.length-1;r++){let i=this.tokens[r];i.type===g.LPAREN||i.type===g.LBRACKET?n++:(i.type===g.RPAREN||i.type===g.RBRACKET)&&n--;let s=this.tokens[r+1];n===0&&i.type===g.IDENTIFIER&&this.typeNames.has(i.value)&&s.type===g.OPERATOR&&s.value==="="&&this.typeVariableNames.add(i.value)}}variableName(e){return this.functionNames.has(e)||this.typeVariableNames.has(e)?e+"_var":e}isTypeMemberAccess(){return this.peek().type===g.DOT&&this.peek(1).type===g.IDENTIFIER&&(this.peek(1).value==="new"||this.peek(1).value==="copy")&&this.peek(2).type===g.LPAREN}isOnceStatement(){if(this.peek().type!==g.IDENTIFIER||this.peek().value!=="once")return!1;let e=this.peek(1);if(e.type===g.COMMA||e.type===g.DOT||e.type===g.OPERATOR&&["=",":=","+=","-=","*=","/=","%="].includes(e.value))return!1;let n=1,r=0;for(;;n++){let i=this.peek(n);if(i.type===g.EOF)return!1;if(i.type===g.LPAREN||i.type===g.LBRACKET)r++;else if(i.type===g.RPAREN||i.type===g.RBRACKET)r--;else{if(r<=0&&(i.type===g.NEWLINE||i.type===g.INDENT))break;if(i.type===g.OPERATOR&&i.value==="=>")return!1}}for(;this.peek(n).type===g.NEWLINE||this.peek(n).type===g.COMMENT;)n++;return this.peek(n).type===g.INDENT}parseOnceStatement(){this.advance();let e=this.match(g.NEWLINE)||this.match(g.INDENT)?null:this.parseExpression();this.skipNewlines();let n=this.parseBlock(),r=`__once_${this.onceCounter++}`,i=new he(r);i.varType="bool";let s=new Mt([new bt(i,new Je(!1),"bool")],Xt.VAR);n.body.unshift(new Qe(new kn("=",new he(r),new Je(!0))));let a=e?new Tt([new Xr(e,n)]):n,o=new Xr(new Zr("!",new he(r)),a),l=new Tt([s,o]);return l._sequence=!0,l}parseStatement(e=!0){this.skipNewlines();let n=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.isOnceStatement())r=this.parseOnceStatement();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")){let i=this.advance().value;r=new Qe(new he(i))}else this.isTupleDestructuring()?r=this.parseTupleDestructuring():this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration()&&(r=this.parseTypedVarDeclaration());if(!r){this.rejectReservedAssignmentTarget();let i=this.peek(),s=this.parseExpression();if(this.match(g.OPERATOR)){let a=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(a)){this.advance(),this.skipNewlines(!0);let o=this.parseExpression();a==="="&&s.type==="Identifier"?(this.assertDeclarableName(s,i),this.assertNotTupleAssignment(s,o,i),r=new Mt([new bt(s,o)],Xt.LET)):r=new Qe(new kn(a===":="?"=":a,s,o))}else r=new Qe(s)}else r=new Qe(s)}if(r&&(r._line=n,e&&this.match(g.COMMA))){let i=[r];for(;this.match(g.COMMA);){this.advance(),this.skipNewlines(!0);let a=this.parseStatement(!1);a&&i.push(a)}this.rejectDanglingWrappedLine();let s=new Tt(i);return s._sequence=!0,s}return this.rejectDanglingWrappedLine(),r}isFunctionDeclaration(){let e=this.pos;try{let n=0;if(this.peek(n).type===g.IDENTIFIER&&this.isNameSlot(this.peek(n+1))&&n++,!this.isNameSlot(this.peek(n))||(n++,this.peek(n).type!==g.LPAREN))return!1;n++;let r=1;for(;r>0&&this.peek(n).type!==g.EOF;)this.peek(n).type===g.LPAREN&&r++,this.peek(n).type===g.RPAREN&&r--,n++;return this.peek(n).type===g.OPERATOR&&this.peek(n).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();let n=[];for(n.push(this.parseTypeExpression());this.match(g.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseTypeExpression());return this.expect(g.OPERATOR,">"),e+"<"+n.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");let e=this.expectName().value;this.skipNewlines(),this.expect(g.INDENT);let n=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){if(this.match(g.COMMENT)){this.advance();continue}let s=this.expectName().value,a=null;this.match(g.OPERATOR,"=")&&(this.advance(),a=this.expect(g.STRING).value),n.push({name:s,title:a}),this.skipNewlines()}this.match(g.DEDENT)&&this.advance();let r=n.map(s=>new Ir(new he(s.name),new Je(s.title!==null?s.title:s.name))),i=new ai(r);return new Mt([new bt(new he(e),i)],Xt.CONST)}parseTypeDefinition(){this.expect(g.KEYWORD,"type");let e=this.expectName().value;this.match(g.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(g.INDENT);let n=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){this.match(g.KEYWORD,"varip")&&this.advance();let r=this.parseTypeExpression(),i=this.expectName().value,s=null;this.match(g.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),n.push({type:r,name:i,defaultValue:s}),this.skipNewlines()}return this.match(g.DEDENT)&&this.advance(),new Xa(e,n)}parseVarDeclaration(){let e=this.advance(),n=e.value,r=null,i=null;if(this.peek().type===g.IDENTIFIER&&["const","simple","series"].includes(this.peek().value)&&this.peek(1).type===g.IDENTIFIER&&this.advance(),this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET)r=this.advance().value,this.advance(),r+="[]",this.advance(),i=this.expectName().value;else if(this.peek().type===g.IDENTIFIER&&(this.peek(1).type===g.DOT||this.isNameSlot(this.peek(1))||this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<")){for(r=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)this.advance(),r+="."+this.advance().value;if(this.match(g.LBRACKET)&&this.peek(1).type===g.RBRACKET)this.advance(),this.advance(),r+="[]",i=this.expectName().value;else if(this.match(g.OPERATOR,"<")){for(this.advance(),r+="<";!this.match(g.OPERATOR,">");)if(this.match(g.IDENTIFIER))for(r+=this.advance().value;this.match(g.DOT)&&this.peek(1).type===g.IDENTIFIER;)r+=".",this.advance(),r+=this.advance().value;else if(this.match(g.COMMA))r+=this.advance().value,this.skipNewlines();else break;this.match(g.OPERATOR,">")&&(r+=">",this.advance()),i=this.expectName().value}else i=this.expectName().value}else if(this.isNameSlot(this.peek()))i=this.expectName().value;else throw this.match(g.OPERATOR,"=")||this.match(g.LPAREN)?this.reservedNameError(e):new Error(`Expected identifier after ${n} at ${this.peek().line}:${this.peek().column}`);i=this.variableName(i),this.expect(g.OPERATOR,"="),this.skipNewlines(!0);let s=this.parseExpression(),a=new he(i);r&&(a.varType=r);let o=[new bt(a,s,r)];for(;this.match(g.COMMA)&&this.peek(1).type===g.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();let l=this.parseVarDeclaration();o.push(...l.declarations)}return new Mt(o,n)}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.isNameSlot(this.peek(e))?(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="):!1;if(this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"){e++;let n=1;for(;n>0&&this.peek(e).type!==g.EOF;)this.peek(e).type===g.OPERATOR&&this.peek(e).value==="<"?n++:this.peek(e).type===g.OPERATOR&&this.peek(e).value===">"&&n--,e++;return this.isNameSlot(this.peek(e))?(e++,this.peek(e).type===g.OPERATOR&&this.peek(e).value==="="):!1}if(!this.isNameSlot(this.peek(e)))return!1;for(e++;this.isNameSlot(this.peek(e));)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.isNameSlot(this.peek(1));)e+=" "+this.advance().value;let n=this.variableName(this.expectName().value);this.expect(g.OPERATOR,"="),this.skipNewlines(!0);let r=this.parseExpression(),i=new he(n);i.varType=e;let s=[new bt(i,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.variableName(this.expectName().value);this.expect(g.OPERATOR,"="),this.skipNewlines(!0);let o=this.parseExpression(),l=new he(a);l.varType=e,s.push(new bt(l,o,e))}return new Mt(s,Xt.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===g.IDENTIFIER&&this.isNameSlot(this.peek(1))&&(e=this.advance().value);let n=this.expectName().value;this.functionNames.add(n),this.expect(g.LPAREN);let r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let u=this.peek(),p=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)p&&(p+=" "),p=(p||"")+this.advance().value;if(this.isDottedParamType()){let f=this.parseTypeExpression();p=p?p+" "+f:f}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){let f=this.parseTypeExpression();p=p?p+" "+f:f}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){let f=this.parseTypeExpression();p=p?p+" "+f:f}let h=this.expectName().value,d=new he(h);if(p&&(d.varType=p),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();let f=this.parseExpression();this.assertParamDefault(f,u),r.push(new as(d,f))}else r.push(d);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let u of r){let p=u.type==="AssignmentPattern"?u.left:u;p&&p.name&&i.add(p.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new he(n);e&&(a.returnType=e);let o=s.body[s.body.length-1],l=o?.type==="ReturnStatement"?o.argument:null,c=l?.type==="ArrayExpression"?l.elements.length:this.tupleArityOf(l)??null;return this.functionTupleArity.set(n,this.functionTupleArity.has(n)&&this.functionTupleArity.get(n)!==c?null:c),this.functionParamNames.set(n,this.functionParamNames.has(n)?null:[...i]),new es(a,r,s,e)}isDottedParamType(){if(this.peek().type!==g.IDENTIFIER||this.peek(1).type!==g.DOT||this.peek(2).type!==g.IDENTIFIER)return!1;let e=3;for(;this.peek(e).type===g.DOT&&this.peek(e+1).type===g.IDENTIFIER;)e+=2;let n=this.peek(e);return n.type===g.LBRACKET?this.peek(e+1).type===g.RBRACKET:n.type===g.OPERATOR&&n.value==="<"?!0:this.isNameSlot(n)}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);let n=this.expectName().value;this.expect(g.LPAREN);let r=[];for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let o=this.peek(),l=null;for(;this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.IDENTIFIER&&this.peek(2).type!==g.LPAREN;)l&&(l+=" "),l=(l||"")+this.advance().value;if(this.isDottedParamType()){let p=this.parseTypeExpression();l=l?l+" "+p:p}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="<"){let p=this.parseTypeExpression();l=l?l+" "+p:p}if(this.peek().type===g.IDENTIFIER&&this.peek(1).type===g.LBRACKET&&this.peek(2).type===g.RBRACKET){let p=this.parseTypeExpression();l=l?l+" "+p:p}let c=this.expectName().value,u=new he(c);if(l&&(u.varType=l),this.match(g.OPERATOR,"=")){this.advance(),this.skipNewlines();let p=this.parseExpression();this.assertParamDefault(p,o),r.push(new as(u,p))}else r.push(u);this.match(g.COMMA)&&this.advance()}this.expect(g.RPAREN),this.skipNewlines(),this.expect(g.OPERATOR,"=>"),this.skipNewlines();let i=new Set;for(let o of r){let l=o.type==="AssignmentPattern"?o.left:o;l&&l.name&&i.add(l.name)}this.paramScopes.push(i);let s;try{s=this.parseFunctionBody()}finally{this.paramScopes.pop()}let a=new he(n);return e&&(a.returnType=e),a.isMethod=!0,new es(a,r,s,e)}parseFunctionBody(){let e=[];if(!this.match(g.INDENT)){let n=this.parseStatementOrSequence(),r=Array.isArray(n)?n:n?[n]:[];return r.length>0&&this._addImplicitReturn(r),new Tt(r)}for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let n=this.parseStatementOrSequence();Array.isArray(n)?e.push(...n):n&&e.push(n)}return this.match(g.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new Tt(e)}_addImplicitReturn(e){let n=e[e.length-1];n.type==="ForStatement"||n.type==="WhileStatement"?this._addImplicitReturnToLoop(e):this._emitLastValue(e,r=>new ns(r))}_addImplicitReturnToLoop(e){let n=e[e.length-1];if(n.body?.type!=="BlockStatement"||n.body.body.length===0)return;let r=`__loopValue_${this.loopValueCounter++}`,i=()=>new he("na"),s=a=>new Qe(new kn("=",new he(r),a));this._emitLastValue(n.body.body,s)&&(n.body.body.unshift(s(i())),e.splice(e.length-1,0,new Mt([new bt(new he(r),i())],Xt.LET)),e.push(new ns(new he(r))))}_emitLastValue(e,n){let r=e[e.length-1];if(r.type==="ExpressionStatement"){let i=r.expression;return i?.type==="Identifier"&&(i.name==="break"||i.name==="continue")?!1:(i?.type==="AssignmentExpression"&&i.left?.type==="Identifier"?e.push(n(new he(i.left.name))):e[e.length-1]=n(i),!0)}if(r.type==="VariableDeclaration"){let i=r.declarations[r.declarations.length-1];return i?.id?.type!=="Identifier"?!1:(e.push(n(new he(i.id.name))),!0)}if(r.type==="IfStatement"){let i=!1;for(let s=r;s;s=s.alternate?.type==="IfStatement"?s.alternate:null){let a=[s.consequent,s.alternate?.type==="BlockStatement"?s.alternate:null];for(let o of a)o?.body?.length>0&&(i=this._emitLastValue(o.body,n)||i)}return i}return!1}continueSequence(e){if(!this.match(g.COMMA))return e;let n=[e];for(;this.match(g.COMMA);){this.advance(),this.skipNewlines(!0);let r=this.parseStatementOrSequence();Array.isArray(r)?n.push(...r):r&&n.push(r)}return n}parseStatementOrSequence(){this.pos;let e=this.peek().line;if(this.match(g.KEYWORD,"if")){let 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.isOnceStatement())return this.parseOnceStatement();if(this.match(g.KEYWORD,"break")||this.match(g.KEYWORD,"continue")){let r=this.advance().value;return new Qe(new he(r))}if(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip"))return this.continueSequence(this.parseVarDeclaration());if(this.isTupleDestructuring())return this.continueSequence(this.parseTupleDestructuring());if(this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration())return this.continueSequence(this.parseTypedVarDeclaration());let n=[];for(;;){if(n.length>0&&(this.match(g.KEYWORD,"var")||this.match(g.KEYWORD,"varip")||this.isTupleDestructuring()||this.peek().type===g.IDENTIFIER&&this.isTypedVarDeclaration())){let s=this.parseStatementOrSequence();Array.isArray(s)?n.push(...s):s&&n.push(s);break}this.rejectReservedAssignmentTarget();let r=this.peek(),i=this.parseExpression();if(this.match(g.OPERATOR)){let s=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(s)){this.advance(),this.skipNewlines(!0);let a=this.parseExpression();if(s==="="&&i.type==="Identifier"?(this.assertDeclarableName(i,r),this.assertNotTupleAssignment(i,a,r),n.push(new Mt([new bt(i,a)],Xt.LET))):n.push(new Qe(new kn(s===":="?"=":s,i,a))),this.match(g.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(n.length>0)n.push(new Qe(i));else return new Qe(i);break}}else if(this.match(g.COMMA)){n.push(new Qe(i)),this.advance(),this.skipNewlines();continue}else{if(n.length>0)n.push(new Qe(i));else return new Qe(i);break}}return n.length>1?n:n.length===1?n[0]:null}parseIfStatement(){this.expect(g.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock(),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 Xr(e,n,r)}parseForStatement(){this.expect(g.KEYWORD,"for");let e=null,n=!1;if(this.match(g.LBRACKET)){this.advance();let r=[];for(;!this.match(g.RBRACKET);)this.skipNewlines(),r.push(new he(this.expect(g.IDENTIFIER).value)),this.match(g.COMMA)&&this.advance();this.expect(g.RBRACKET),e=new ss(r),n=!0}else{let r=this.expectName().value;e=new he(r)}if(this.match(g.KEYWORD,"in")){this.advance();let r=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new Mt([new bt(e,r)],Xt.CONST),a=new ts(s,null,null,i);return a.isForIn=!0,a}else{if(n)throw new Error(`Range-based for loops don\'t support destructuring at ${this.peek().line}:${this.peek().column}`);this.expect(g.OPERATOR,"=");let r=this.parseExpression();this.expect(g.KEYWORD,"to");let i=this.parseExpression(),s=null;this.match(g.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();let a=this.parseBlock(),o=new Mt([new bt(e,r)],Xt.LET),l=new $t("<=",r,i),c=new Jt(l,new $t("<=",e,i),new $t(">=",e,i)),u;return s?u=new Jt(l,new kn("+=",e,s),new kn("-=",e,s)):u=new Jt(l,new rs("++",e),new rs("--",e)),new ts(o,c,u,a)}}parseWhileStatement(){this.expect(g.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock();return new Za(e,n)}parseBlock(){if(!this.match(g.INDENT)){this.rejectDanglingWrappedLine();let r=this.parseStatement();return new Tt(r?[r]:[])}let e=this.peek().indent;this.advance();let n=[];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;let r=this.parseStatement();r&&n.push(r)}return this.match(g.DEDENT)&&this.peek().indent<e&&this.advance(),new Tt(n)}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.IDENTIFIER&&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==="="||this.peek(e).value===":=")}parseTupleDestructuring(){let e=this.expect(g.LBRACKET),n=[],r=new Set;for(;!this.match(g.RBRACKET);){this.skipNewlines();let a=this.expect(g.IDENTIFIER);if(this.match(g.IDENTIFIER))throw new Error(`Mismatched input "${this.peek().value}" expecting set "]" at ${this.startOf(this.peek())}`);let o=a.value;if(o!=="_"){if(r.has(o))throw new Error(`"${o}" is already defined at ${this.startOf(e)}`);r.add(o)}o=this.variableName(o),n.push(new he(o)),this.match(g.COMMA)&&this.advance()}if(this.expect(g.RBRACKET),this.skipNewlines(),this.match(g.OPERATOR,":="))throw new Error(`Mismatched input ":=" expecting set "=" at ${this.startOf(this.peek())}`);this.expect(g.OPERATOR,"="),this.skipNewlines(!0);let i=this.parseExpression();this.assertNotTupleLiteral(i);let s=this.tupleArityOf(i);if(s!==void 0&&s!==n.length)throw new Error(`Syntax error: The quantities of tuple elements on each side of the assignment operator do not match. The right side has ${s} but the left side has ${n.length}. at ${this.startOf(e)}`);return new Mt([new bt(new ss(n),i)],Xt.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.match(g.OPERATOR,"?")){let n=this.advance();this.skipNewlines(!0);let r=this.parseExpression();this.expect(g.COLON),this.skipNewlines(!0);let i=this.parseExpression(),s=[r,i].find(a=>a.type==="ArrayExpression");if(s)throw new Error(`Ternary operations cannot return tuples. Convert the expression into an \\`if\\` or \\`switch\\` conditional structure to return a tuple. at ${this.startOf(this.tupleLiteralStart.get(s)??n)}`);return new Jt(e,r,i)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.match(g.KEYWORD,"or")||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);let n=this.parseLogicalAnd();e=new $t("||",e,n)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.match(g.KEYWORD,"and")||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);let n=this.parseEquality();e=new $t("&&",e,n)}return e}parseEquality(){let e=this.parseComparison();for(;this.peekOperatorEx(["==","!="]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseComparison();e=new $t(n,e,r)}return e}parseComparison(){let e=this.parseAdditive();for(;this.peekOperatorEx(["<",">","<=",">="]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseAdditive();e=new $t(n,e,r)}return e}parseAdditive(){let e=this.parseMultiplicative();for(;this.peekOperatorEx(["+","-"]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseMultiplicative();e=new $t(n,e,r)}return e}parseMultiplicative(){let e=this.parseUnary();for(;this.peekOperatorEx(["*","/","%"]);){let n=this.advance().value;this.skipNewlines(!0);let r=this.parseUnary();e=new $t(n,e,r)}return e}parseUnary(){if(this.match(g.OPERATOR)){let e=this.peek().value;if(["+","-","!"].includes(e)){let n=this.advance();this.skipNewlines();let r=new Zr(e,this.parseUnary());return r._pos=this.startOf(n),r}}return this.match(g.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new Zr("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(g.OPERATOR,"<")){let n=this.pos;this.advance();let r=1,i=!0,s="",a="",o=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),r===1&&(a+=this.peek().value),this.advance();else{i=!1,this.pos=n;break}if(i&&e.type==="MemberExpression"&&e.property.name==="new"&&(e.object.name==="array"||e.object.name==="matrix")&&o.has(s)&&(e.property=new he("new_"+s)),i&&this.match(g.LPAREN)){let l=e.type==="MemberExpression"&&e.property.name==="new"&&e.object.name==="map";e=this.parseCallExpression(e),l&&a.split(",")[1]==="string"&&e.arguments.length===0&&e.arguments.push(new Je("string"));continue}else{if(i)continue;break}}else if(this.match(g.LPAREN))e=this.parseCallExpression(e);else if(this.match(g.DOT)){this.advance(),this.skipNewlines();let n=this.peek();if(n.type!==g.IDENTIFIER&&n.type!==g.KEYWORD)throw new Error(`Expected property name but got ${n.type} at ${n.line}:${n.column}`);this.advance(),e=new is(e,new he(n.value),!1)}else if(this.match(g.LBRACKET)){if(this.startsNewLine())break;this.advance(),this.skipNewlines();let n=this.parseExpression();this.expect(g.RBRACKET),e=new is(e,n,!0)}else break;return e}parseCallExpression(e){let n=this.tokens[this.pos-1];this.expect(g.LPAREN);let r=[],i=[],s=this.dottedName(e),a=s!==null&&(s==="input"||/^(request|input)\\./.test(s)),o=(c,u,p)=>{if(!(c.type!=="ArrayExpression"||a))throw p!==void 0?new Error(`The "${p}" parameter of the "${s}()" function cannot accept a tuple as an argument. Pass a single argument to this parameter. at ${this.startOf(n)}`):new Error(`Cannot call "${s??"function"}" with a tuple argument. Only the expression parameter of request.*() functions and the options parameter of input.*() functions accept tuples. at ${this.startOf(u)}`)},l=s!==null?this.functionParamNames.get(s):void 0;for(;!this.match(g.RPAREN)&&(this.skipNewlines(),!this.match(g.RPAREN));){let c=this.peek();if((this.peek().type===g.IDENTIFIER||this.peek().type===g.KEYWORD)&&this.peek(1).type===g.OPERATOR&&this.peek(1).value==="="){let u=this.advance(),p=u.value;this.advance(),this.skipNewlines();let h=this.peek(),d=this.parseExpression();o(d,h,l?p:void 0);let f=new he(p);f._pos=this.startOf(u),i.push(new Ir(f,d))}else{let u=this.parseExpression();o(u,c,l?.[r.length]),r.push(u)}this.match(g.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(g.RPAREN),i.length>0&&r.push(new ai(i)),new Qa(e,r)}parsePrimary(){let e=this.peek();if(this.match(g.NUMBER)){let n=this.advance(),r=new Je(n.value,n.raw);return typeof n.raw=="string"&&(r._pos=`${n.line}:${n.column-n.raw.length}`),r}if(this.match(g.STRING)){let n=this.advance(),r=new Je(n.value);return n.startColumn!==void 0&&(r._pos=`${n.line}:${n.startColumn}`),r}if(this.match(g.BOOLEAN)){let n=this.advance(),r=new Je(n.value);return r._pos=this.startOf(n),r}if(this.match(g.IDENTIFIER)){let n=this.advance(),r=n.value;(this.functionNames.has(r)&&this.peek().type!==g.LPAREN&&!this.isCurrentFunctionParam(r)&&!(this.peek().type===g.DOT&&Ti.has(r))&&!(this.peek().type===g.DOT&&this.typeNames.has(r))||this.typeVariableNames.has(r)&&!this.isCurrentFunctionParam(r)&&!this.isTypeMemberAccess())&&(r=r+"_var");let i=new he(r);return i._pos=this.startOf(n),i}if(this.match(g.LBRACKET))return this.parseArrayLiteral();if(this.match(g.LPAREN)){this.advance(),this.skipNewlines();let n=this.parseExpression();return this.skipNewlines(),this.expect(g.RPAREN),n}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 this.unexpected(e)}parseArrayLiteral(){let e=this.expect(g.LBRACKET),n=[];for(;!this.match(g.RBRACKET)&&(this.skipNewlines(),!this.match(g.RBRACKET));)n.push(this.parseExpression()),this.match(g.COMMA)&&this.advance(),this.skipNewlines();this.expect(g.RBRACKET);let r=new Ja(n);return this.tupleLiteralStart.set(r,e),r._pos=this.startOf(e),r}parseIfExpression(){this.expect(g.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines(),this.expect(g.INDENT);let n=[];for(;!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let a=this.parseStatement();a&&n.push(a)}this.advance();let r=[];if(this.match(g.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(g.KEYWORD,"if")){let a=this.parseIfExpression();if(this.needsIIFE(n,r)){let o=new Jt(e,new Tt(n),a);return o.needsIIFE=!0,o.consequentStmts=n,o.alternateExpr=a,o}else return new Jt(e,this.getBlockValue(n),a)}else{for(this.expect(g.INDENT);!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let a=this.parseStatement();a&&r.push(a)}this.advance()}if(this.needsIIFE(n,r)){let a=new Jt(e,new Tt(n),new Tt(r));return a.needsIIFE=!0,a.consequentStmts=n,a.alternateStmts=r,a}let i=this.getBlockValue(n),s=r.length>0?this.getBlockValue(r):new Je(null);return new Jt(e,i,s)}needsIIFE(e,n){if(e.length>1||n.length>1)return!0;let r=i=>i.some(s=>s.type==="IfStatement"||s.type==="ForStatement"||s.type==="WhileStatement"||s.type==="BlockStatement");return r(e)||r(n)}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);let n=[];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();let i=[];if(this.match(g.INDENT)){for(this.advance();!this.match(g.DEDENT)&&!this.match(g.EOF)&&(this.skipNewlines(),!this.match(g.DEDENT));){let a=this.parseStatement();a&&i.push(a)}this.advance()}else{let a=this.parseStatement();a&&i.push(a)}let s=this.getBlockValue(i);n.push(new to(r,s,i)),this.skipNewlines()}return this.advance(),new eo(e,n)}parseForExpression(){let e=this.parseForStatement();return e.isExpression=!0,e}parseWhileExpression(){let e=this.parseWhileStatement();return e.isExpression=!0,e}getBlockValue(e){if(e.length===0)return new Je(null);let n=e[e.length-1];return n.type==="ExpressionStatement"?n.expression:n.type==="VariableDeclaration"&&n.declarations.length>0?n.declarations[0].id:new Je(null)}};At(Ah,"STATEMENT_KEYWORDS",new Set(["if","else","for","while","switch"]));var iS=Ah,sS=Object.defineProperty,aS=(t,e,n)=>e in t?sS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ct=(t,e,n)=>aS(t,typeof e!="symbol"?e+"":e,n),oS=new Set(Jo),Qs=t=>typeof t=="string"&&/(^|\\s)string$/.test(t),Js=t=>t?.type==="Identifier"&&t.name==="na",no=class{constructor(e={}){ct(this,"indent"),ct(this,"indentStr"),ct(this,"output"),ct(this,"sourceCode"),ct(this,"sourceLines"),ct(this,"lastCommentedLine"),ct(this,"includeSourceComments"),ct(this,"paramRenameCounter"),ct(this,"functionParams"),ct(this,"userFunctionCollisions"),ct(this,"userFunctionRenames"),ct(this,"renamedTypeNames"),ct(this,"methodNameCounts",new Map),ct(this,"stringVarScopes",[new Map]),this.indent=0,this.indentStr=e.indentStr||" ",this.output=[],this.sourceCode=e.sourceCode||null,this.sourceLines=this.sourceCode?this.sourceCode.split(`\n`):[],this.lastCommentedLine=-1,this.includeSourceComments=e.includeSourceComments||!1,this.paramRenameCounter=0,this.functionParams=new Map,this.userFunctionCollisions=new Set,this.userFunctionRenames=new Map,this.renamedTypeNames=new Set}renameDiscardTargets(e){let n=new Set;for(let r of e)!r||r.type!=="Identifier"||(r.name==="_"?r.name=this.freshDiscardName():n.has(r.name)&&(r.name=`${r.name}${this.paramRenameCounter++}`),n.add(r.name))}freshDiscardName(){return`_$${this.paramRenameCounter++}`}generate(e){if(this.output=[],this.indent=0,this.lastCommentedLine=-1,this.functionParams=new Map,this.userFunctionCollisions=new Set,this.userFunctionRenames=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.renameConflictingVariables(e),this.renameFunctionsSharingTypeNames(e),this.collectFunctionParams(e)}renameFunctionsSharingTypeNames(e){let n=new Set;for(let s of e.body)s.type==="TypeDefinition"&&typeof s.name=="string"&&n.add(s.name);if(n.size===0)return;let r=new Map;for(let s of e.body){let a=s.type==="FunctionDeclaration"&&!s.id?.isMethod?s.id?.name:void 0;a&&n.has(a)&&!r.has(a)&&r.set(a,`${a}_$${this.paramRenameCounter++}`)}if(r.size===0)return;let i=s=>{if(!(!s||typeof s!="object")){s.type==="FunctionDeclaration"&&!s.id?.isMethod&&r.has(s.id?.name)&&(s.id.name=r.get(s.id.name)),s.type==="CallExpression"&&s.callee?.type==="Identifier"&&r.has(s.callee.name)&&(s.callee.name=r.get(s.callee.name));for(let a of Object.keys(s)){if(a==="type")continue;let o=s[a];if(Array.isArray(o))for(let l of o)i(l);else o&&typeof o=="object"&&o.type&&i(o)}}};i(e)}renameConflictingVariables(e){let n=new Map;this.renamedTypeNames=new Set,this.collectConflictingVarNames(e,n),n.size>0&&this.renameVariableRefsInAST(e,n)}renameTypeString(e,n){return typeof e!="string"||this.renamedTypeNames.size===0?e:e.replace(/[A-Za-z_]\\w*/g,r=>this.renamedTypeNames.has(r)&&n.has(r)?n.get(r):r)}isReservedName(e){return!!e&&(Ti.has(e)||Ii.has(e))}collectConflictingVarNames(e,n){if(!(!e||typeof e!="object")){if(e.type==="VariableDeclaration"){for(let r of e.declarations)if(r.id?.type==="Identifier"&&this.isReservedName(r.id.name)&&!n.has(r.id.name)&&n.set(r.id.name,`${r.id.name}_$${this.paramRenameCounter++}`),r.id?.type==="ArrayPattern")for(let i of r.id.elements)i?.type==="Identifier"&&this.isReservedName(i.name)&&!n.has(i.name)&&n.set(i.name,`${i.name}_$${this.paramRenameCounter++}`)}(e.type==="AssignmentExpression"||e.type==="ReassignmentExpression")&&e.left?.type==="Identifier"&&this.isReservedName(e.left.name)&&!n.has(e.left.name)&&n.set(e.left.name,`${e.left.name}_$${this.paramRenameCounter++}`),e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"&&!e.id.isMethod&&this.isReservedName(e.id.name)&&(n.has(e.id.name)||n.set(e.id.name,`${e.id.name}_$${this.paramRenameCounter++}`),this.userFunctionRenames.set(e.id.name,n.get(e.id.name)),Ti.has(e.id.name)&&this.userFunctionCollisions.add(e.id.name)),e.type==="TypeDefinition"&&typeof e.name=="string"&&Ii.has(e.name)&&(n.has(e.name)||n.set(e.name,`${e.name}_$${this.paramRenameCounter++}`),this.renamedTypeNames.add(e.name));for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.collectConflictingVarNames(s,n);else i&&typeof i=="object"&&i.type&&this.collectConflictingVarNames(i,n)}}}renameVariableRefsInAST(e,n){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"){e.id?.type==="Identifier"&&n.has(e.id.name)&&(e.id.name=n.get(e.id.name)),e.id&&(e.id.returnType=this.renameTypeString(e.id.returnType,n)),e.returnType=this.renameTypeString(e.returnType,n);let r=n;for(let i of e.params??[]){let s=i.type==="AssignmentPattern"?i.left:i;s&&(s.varType=this.renameTypeString(s.varType,n),s.type==="Identifier"&&r.has(s.name)&&(r===n&&(r=new Map(n)),r.delete(s.name)))}for(let i of e.params??[])i.type==="AssignmentPattern"&&i.right&&this.renameVariableRefsInAST(i.right,r);r.size>0&&this.renameVariableRefsInAST(e.body,r);return}if(e.type==="TypeDefinition"){typeof e.name=="string"&&n.has(e.name)&&(e.name=n.get(e.name));for(let r of e.fields??[])r.type=this.renameTypeString(r.type,n),r.defaultValue&&this.renameVariableRefsInAST(r.defaultValue,n);return}if(e.type==="VariableDeclarator"&&(e.varType=this.renameTypeString(e.varType,n)),e.type==="Identifier"&&(e.varType=this.renameTypeString(e.varType,n)),e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&n.has(e.callee.name)?(Ii.has(e.callee.name)||this.userFunctionCollisions.has(e.callee.name))&&(e.callee.name=n.get(e.callee.name)):e.callee?.type==="Identifier"&&this.userFunctionRenames.has(e.callee.name)?e.callee.name=this.userFunctionRenames.get(e.callee.name):this.renameVariableRefsInAST(e.callee,n),e.arguments)for(let r of e.arguments)this.renameVariableRefsInAST(r,n);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&n.has(e.object.name)&&Ti.has(e.object.name))return;if(!e.computed&&e.property?.type==="Identifier"&&n.has(e.property.name)){this.renameVariableRefsInAST(e.object,n);return}this.renameVariableRefsInAST(e.object,n),e.computed&&this.renameVariableRefsInAST(e.property,n);return}if(e.type==="Property"){this.renameVariableRefsInAST(e.value,n);return}if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameVariableRefsInAST(s,n);else i&&typeof i=="object"&&i.type&&this.renameVariableRefsInAST(i,n)}}}collectFunctionParams(e){if(!(!e||typeof e!="object")){if(e.type==="FunctionDeclaration"&&e.id?.name){let n=[];for(let r of e.params)r.type==="Identifier"?n.push(r.name):r.type==="AssignmentPattern"&&r.left?.name&&n.push(r.left.name);this.functionParams.set(e.id.name,n)}if(Array.isArray(e.body))for(let n of e.body)this.collectFunctionParams(n);else e.body&&typeof e.body=="object"&&this.collectFunctionParams(e.body)}}writeSourceComment(e,n=null){if(!this.sourceLines.length)return;let r=n||e,i=[];for(let s=e-1;s<r&&s<this.sourceLines.length;s++)if(s>this.lastCommentedLine){let a=this.sourceLines[s].trim();a&&!a.startsWith("//@")&&!a.startsWith("//")&&i.push(this.sourceLines[s])}if(i.length>0){for(let s of i)this.write(this.indentStr.repeat(this.indent)),this.write("/// "),this.write(s.trimEnd()),this.write(`\n`);this.lastCommentedLine=Math.max(this.lastCommentedLine,r-1)}}write(e){this.output.push(e)}writeLine(e=""){e?this.output.push(this.indentStr.repeat(this.indent)+e+`\n`):this.output.push(`\n`)}increaseIndent(){this.indent++}decreaseIndent(){this.indent--}generateProgram(e){for(let n=0;n<e.body.length;n++)if(this.generateStatement(e.body[n]),n<e.body.length-1){let r=e.body[n],i=e.body[n+1];(r.type==="FunctionDeclaration"||r.type==="TypeDefinition")&&(i.type==="FunctionDeclaration"||i.type==="TypeDefinition")&&this.writeLine()}}generateStatement(e){switch(this.includeSourceComments&&e._line&&this.sourceLines.length>0&&this.writeSourceComment(e._line),e.type){case"FunctionDeclaration":return this.generateFunctionDeclaration(e);case"VariableDeclaration":return this.generateVariableDeclaration(e);case"ExpressionStatement":return this.generateExpressionStatement(e);case"IfStatement":return this.generateIfStatement(e);case"ForStatement":return this.generateForStatement(e);case"WhileStatement":return this.generateWhileStatement(e);case"ReturnStatement":return this.generateReturnStatement(e);case"BlockStatement":if(e._sequence){for(let n of e.body)this.generateStatement(n);return}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 n=0;n<e.fields.length;n++){let r=e.fields[n];r.defaultValue?(this.write(`${r.name}: [\'${r.type}\', `),this.generateExpression(r.defaultValue),this.write("]")):this.write(`${r.name}: \'${r.type}\'`),n<e.fields.length-1&&this.write(", ")}this.write(" ")}this.write(`});\n`)}renameIdentifiersInAST(e,n){if(!(!e||typeof e!="object")){if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}if(e.type!=="FunctionDeclaration")for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameIdentifiersInAST(s,n);else i&&typeof i=="object"&&i.type&&this.renameIdentifiersInAST(i,n)}}}renameParamRefsInBody(e,n){if(!(!e||typeof e!="object")&&e.type!=="FunctionDeclaration"){if(e.type==="CallExpression"){if(e.callee?.type==="Identifier"&&n.has(e.callee.name)||this.renameParamRefsInBody(e.callee,n),e.arguments)for(let r of e.arguments)this.renameParamRefsInBody(r,n);return}if(e.type==="MemberExpression"){if(!e.computed&&e.object?.type==="Identifier"&&n.has(e.object.name))return;this.renameParamRefsInBody(e.object,n),e.computed&&this.renameParamRefsInBody(e.property,n);return}if(e.type==="Property"){this.renameParamRefsInBody(e.value,n);return}if(e.type==="Identifier"&&n.has(e.name)){e.name=n.get(e.name);return}for(let r of Object.keys(e)){if(r==="type")continue;let i=e[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&this.renameParamRefsInBody(s,n);else i&&typeof i=="object"&&i.type&&this.renameParamRefsInBody(i,n)}}}generateFunctionDeclaration(e){this.write(this.indentStr.repeat(this.indent));let n=e.id.isMethod,r=new Map;for(let p of e.params){let h=p.type==="AssignmentPattern"?p.left.name:p.name;if(h&&oS.has(h)){let d=`${h}_$${this.paramRenameCounter++}`;r.set(h,d)}}let i=p=>p.type==="Identifier"&&p.name==="this"||p.type==="AssignmentPattern"&&p.left?.name==="this",s=new Map;n&&e.params.length>0&&i(e.params[0])&&s.set("this","self");let a=new Map;if(e.params.forEach((p,h)=>{let d=(p.type==="AssignmentPattern"?p.left:p)?.name;!d||!Ii.has(d)||r.has(d)||n&&h===0&&d==="this"||a.set(d,`${d}_$${this.paramRenameCounter++}`)}),r.size>0||s.size>0||a.size>0){for(let p of e.params){let h=p.type==="AssignmentPattern"?p.left:p;if(h?.type==="Identifier"){let d=r.get(h.name)??s.get(h.name)??a.get(h.name);d&&(h.name=d)}p.type==="AssignmentPattern"&&p.right&&(r.size>0&&this.renameParamRefsInBody(p.right,r),s.size>0&&this.renameIdentifiersInAST(p.right,s),a.size>0&&this.renameVariableRefsInAST(p.right,a))}r.size>0&&this.renameParamRefsInBody(e.body,r),s.size>0&&this.renameIdentifiersInAST(e.body,s),a.size>0&&this.renameVariableRefsInAST(e.body,a)}let o=e.id.name;if(n){let p=(this.methodNameCounts.get(e.id.name)??0)+1;this.methodNameCounts.set(e.id.name,p),o=p===1?`$M_${e.id.name}`:`$M_${e.id.name}$${p}`}this.write("function "),this.write(o),this.write("(");let l=e.params,c=new Map;for(let p=0;p<l.length;p++){let h=l[p];if(h.type==="Identifier")this.write(h.name),c.set(h.name,Qs(h.varType));else if(h.type==="AssignmentPattern"){let d=Qs(h.left.varType);c.set(h.left.name,d),this.write(h.left.name),this.write(" = "),d&&Js(h.right)?this.write(\'""\'):this.generateExpression(h.right)}p<l.length-1&&this.write(", ")}this.write(") "),this.stringVarScopes.push(c);try{this.generateBlockStatement(e.body,!1)}finally{this.stringVarScopes.pop()}if(this.write(`\n`),n){this.write(this.indentStr.repeat(this.indent)),this.write(`${o}.__pineMethod__ = true;\n`);let p=e.params[0],h=p?.type==="AssignmentPattern"?p.left?.varType:p?.varType;typeof h=="string"&&h.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${o}.__pineReceiverType__ = ${JSON.stringify(h)};\n`))}let u=[];for(let p=0;p<e.params.length;p++){let h=e.params[p],d=h.type==="AssignmentPattern"?h.left?.name:h.name;if(n&&p===0&&d==="self")continue;let f=h.type==="AssignmentPattern"?h.left?.varType:h.varType;d&&f&&u.push([d,f])}if(u.length>0){this.write(this.indentStr.repeat(this.indent));let p=u.map(([h,d])=>`${JSON.stringify(h)}: ${JSON.stringify(d)}`).join(", ");this.write(`${o}.__pineParamTypes__ = {${p}};\n`)}}generateVariableDeclaration(e){let n=e.kind==="var"||e.kind==="varip"?"var":"let";for(let r=0;r<e.declarations.length;r++){let i=e.declarations[r];if(i.id?.type==="Identifier"&&i.id.name==="_"?i.id.name=this.freshDiscardName():i.id?.type==="ArrayPattern"&&this.renameDiscardTargets(i.id.elements),i.init&&i.init.type==="ConditionalExpression"&&i.init.needsIIFE){let l=i.id.type==="Identifier"?i.id.name:null;if(l){this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" "),this.write(l),this.write(`;\n`),this.generateIfStatementWithAssignment(i.init,l);continue}}this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" "),i.id.type==="Identifier"?this.write(i.id.name):i.id.type==="ArrayPattern"&&(this.write("["),this.write(i.id.elements.map(l=>l.name).join(", ")),this.write("]"));let s=i.id.type==="Identifier"&&(i.id.varType?Qs(i.id.varType):i.init?.type==="Literal"&&typeof i.init.value=="string");i.id.type==="Identifier"&&this.stringVarScopes[this.stringVarScopes.length-1].set(i.id.name,s),i.init&&(this.write(" = "),s&&Js(i.init)?this.write(\'""\'):this.generateExpression(i.init)),this.write(`;\n`);let a=i.id?.varType,o=i.id?.type==="Identifier"?i.id.name:null;o&&typeof a=="string"&&/^[A-Za-z_$][\\w$]*$/.test(a)&&a[0]===a[0].toUpperCase()?(this.write(this.indentStr.repeat(this.indent)),this.write(`"__pineUdtVar:${o}=${a}";\n`)):o&&typeof a=="string"&&a.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${JSON.stringify(`__pineTypedVar:${o}=${a}`)};\n`))}}generateExpressionStatement(e){if(e.expression.type==="SwitchExpression"&&e.expression.discriminant===null){this.write(this.indentStr.repeat(this.indent)),this.generateSwitchAsIfElse(e.expression),this.write(`\n`);return}this.write(this.indentStr.repeat(this.indent)),this.generateExpression(e.expression),this.write(`;\n`)}generateIfStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.consequent,!1),e.alternate?(this.write(" else "),e.alternate.type==="IfStatement"?this.generateIfStatement(e.alternate):this.generateBlockStatement(e.alternate,!1)):this.write(`\n`)}generateIfStatementWithAssignment(e,n){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let r=0;r<e.consequentStmts.length;r++){let i=e.consequentStmts[r];r===e.consequentStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternateExpr)this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternateStmts.length;r++){let i=e.alternateStmts[r];r===e.alternateStmts.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithAssignments(e,n){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let i=e.consequent.body[r];r===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}if(this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),e.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let r=0;r<e.alternate.consequent.body.length;r++){let i=e.alternate.consequent.body[r];r===e.alternate.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate.alternate,n)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.alternate.body.length;r++){let i=e.alternate.body[r];r===e.alternate.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternatesWithAssignments(e,n){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let r=0;r<e.consequent.body.length;r++){let i=e.consequent.body[r];r===e.consequent.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternatesWithAssignments(e.alternate,n)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let r=0;r<e.body.length;r++){let i=e.body[r];r===e.body.length-1?i.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(" = "),this.generateExpression(i.expression),this.write(`;\n`)):i.type==="IfStatement"?this.generateNestedIfWithAssignments(i,n):this.generateStatement(i):this.generateStatement(i)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(n),this.write(` = false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateForStatement(e){if(this.write(this.indentStr.repeat(this.indent)),e.isForIn){if(this.write("for ("),e.init&&e.init.type==="VariableDeclaration"){let n=e.init.declarations[0];this.write(`${e.init.kind} `),n.id.type==="Identifier"?this.write(n.id.name):n.id.type==="ArrayPattern"&&(this.renameDiscardTargets(n.id.elements),this.write("["),this.write(n.id.elements.map(r=>r.name).join(", ")),this.write("]")),this.write(" of "),this.generateExpression(n.init)}this.write(") "),this.generateBlockStatement(e.body,!1);return}if(this.write("for ("),e.init)if(e.init.type==="VariableDeclaration"){let n=e.init.declarations[0];this.write(`${e.init.kind} ${n.id.name}`),n.init&&(this.write(" = "),this.generateExpression(n.init))}else this.generateExpression(e.init);this.write("; "),e.test&&this.generateExpression(e.test),this.write("; "),e.update&&(e.update.type==="AssignmentExpression"?(this.generateExpression(e.update.left),this.write(` ${e.update.operator} `),this.generateExpression(e.update.right)):this.generateExpression(e.update)),this.write(") "),this.generateBlockStatement(e.body,!1)}generateWhileStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("while ("),this.generateExpression(e.test),this.write(") "),this.generateBlockStatement(e.body,!1)}generateReturnStatement(e){this.write(this.indentStr.repeat(this.indent)),this.write("return"),e.argument&&(this.write(" "),this.generateExpression(e.argument)),this.write(`;\n`)}generateBlockStatement(e,n=!0){this.write(`{\n`),n?this.increaseIndent():this.indent++;for(let r of e.body)this.generateStatement(r);n?this.decreaseIndent():this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n&&this.write(`\n`)}generateExpression(e){switch(e.type){case"Identifier":return this.write(e.name);case"Literal":return this.generateLiteral(e);case"BinaryExpression":case"LogicalExpression":return this.generateBinaryExpression(e);case"UnaryExpression":return this.generateUnaryExpression(e);case"AssignmentExpression":return this.generateAssignmentExpression(e);case"UpdateExpression":return this.generateUpdateExpression(e);case"CallExpression":return this.generateCallExpression(e);case"MemberExpression":return this.generateMemberExpression(e);case"ConditionalExpression":return this.generateConditionalExpression(e);case"ArrayExpression":return this.generateArrayExpression(e);case"ObjectExpression":return this.generateObjectExpression(e);case"SwitchExpression":return this.generateSwitchExpression(e);case"SequenceExpression":return this.generateSequenceExpression(e);case"ForStatement":return this.generateLoopAsExpression(e,"for");case"WhileStatement":return this.generateLoopAsExpression(e,"while");default:throw new Error(`Unknown expression type: ${e.type}`)}}generateLiteral(e){if(typeof e.value=="string"){let n=e.value.replace(/\\\\/g,"\\\\\\\\").replace(/\'/g,"\\\\\'").replace(/\\n/g,"\\\\n").replace(/\\r/g,"\\\\r").replace(/\\t/g,"\\\\t");this.write(`\'${n}\'`)}else if(e.value===null)this.write("null");else{let n=String(e.value);typeof e.raw=="string"&&/[.eE]/.test(e.raw)&&!/[.eE]/.test(n)?this.write(n+".0"):this.write(n)}}generateBinaryExpression(e){let n=this.getPrecedence(e);this.getPrecedence(e.left)<n?(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(" ");let i=this.getPrecedence(e.right),s=i<n;i===n&&(r==="-"||r==="/"||r==="%")&&(s=!0),s?(this.write("("),this.generateExpression(e.right),this.write(")")):this.generateExpression(e.right)}generateUnaryExpression(e){let n=e.operator;n==="not"&&(n="!"),this.write(n),this.getPrecedence(e.argument)<15||e.argument.type==="UnaryExpression"&&(n==="-"||n==="+")&&(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 n=e.operator;n===":="&&(n="="),this.write(n),this.write(" "),n==="="&&e.left.type==="Identifier"&&Js(e.right)&&this.isStringVariable(e.left.name)?this.write(\'""\'):this.generateExpression(e.right)}isStringVariable(e){for(let n=this.stringVarScopes.length-1;n>=0;n--){let r=this.stringVarScopes[n].get(e);if(r!==void 0)return r}return!1}generateUpdateExpression(e){e.prefix?(this.write(e.operator),this.generateExpression(e.argument)):(this.generateExpression(e.argument),this.write(e.operator))}generateCallExpression(e){this.getPrecedence(e.callee)<19?(this.write("("),this.generateExpression(e.callee),this.write(")")):this.generateExpression(e.callee),this.write("(");let n=e.callee?.type==="Identifier"?e.callee.name:null,r=n?this.functionParams.get(n):null,i=e.arguments.length>0?e.arguments[e.arguments.length-1]:null;if(i?.type==="ObjectExpression"&&r){let s=e.arguments.slice(0,-1),a=new Map;for(let u of i.properties){let p=u.key?.name||u.key?.value;p&&a.set(p,u.value)}let o=[],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);let c=o.slice(0,l+1);for(let u=0;u<c.length;u++)c[u]===null?this.write("undefined"):this.generateExpression(c[u]),u<c.length-1&&this.write(", ")}else for(let s=0;s<e.arguments.length;s++){let a=e.arguments[s];a.type==="AssignmentExpression"&&a.operator==="="?this.generateExpression(a.right):this.generateExpression(a),s<e.arguments.length-1&&this.write(", ")}this.write(")")}generateMemberExpression(e){this.getPrecedence(e.object)<19?(this.write("("),this.generateExpression(e.object),this.write(")")):this.generateExpression(e.object),e.computed?(this.write("["),this.generateExpression(e.property),this.write("]")):(this.write("."),this.generateExpression(e.property))}generateConditionalExpression(e){if(e.needsIIFE){this.generateIIFEConditional(e);return}this.write("("),this.generateExpression(e.test),this.write(" ? "),this.generateExpression(e.consequent),this.write(" : "),this.generateExpression(e.alternate),this.write(")")}generateIIFEConditional(e){this.write(`(() => {\n`),this.indent++,this.generateIIFEIfBlock(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateIIFEIfBlock(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequentStmts)for(let n=0;n<e.consequentStmts.length;n++){let r=e.consequentStmts[n];n===e.consequentStmts.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):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 {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(e.alternateExpr),this.write(`;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");else if(e.alternateStmts&&e.alternateStmts.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternateStmts.length;n++){let r=e.alternateStmts[n];n===e.alternateStmts.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}")}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}");this.write(`\n`)}generateNestedIfWithReturns(e){if(this.write(this.indentStr.repeat(this.indent)),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let r=e.consequent.body[n];n===e.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):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.alternate)if(e.alternate.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.alternate.test),this.write(`) {\n`),this.indent++,e.alternate.consequent.type==="BlockStatement"&&e.alternate.consequent.body.length>0)for(let n=0;n<e.alternate.consequent.body.length;n++){let r=e.alternate.consequent.body[n];n===e.alternate.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate.alternate)}else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.alternate.body.length;n++){let r=e.alternate.body[n];n===e.alternate.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`);else this.write(`\n`)}generateNestedIfAlternates(e){if(e)if(e.type==="IfStatement"){if(this.write(" else "),this.write("if ("),this.generateExpression(e.test),this.write(`) {\n`),this.indent++,e.consequent.type==="BlockStatement"&&e.consequent.body.length>0)for(let n=0;n<e.consequent.body.length;n++){let r=e.consequent.body[n];n===e.consequent.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),this.generateNestedIfAlternates(e.alternate)}else if(e.type==="BlockStatement"&&e.body.length>0){this.write(` else {\n`),this.indent++;for(let n=0;n<e.body.length;n++){let r=e.body[n];n===e.body.length-1?r.type==="ExpressionStatement"?(this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.expression),this.write(`;\n`)):r.type==="IfStatement"?this.generateNestedIfWithReturns(r):this.generateStatement(r):this.generateStatement(r)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}else this.write(` else {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`return false;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}generateNestedIfAsExpression(e){if(e.type==="IfStatement"){if(this.write("("),this.generateExpression(e.test),this.write(" ? "),e.consequent.type==="BlockStatement"&&e.consequent.body.length>0){let n=e.consequent.body[e.consequent.body.length-1];n.type==="ExpressionStatement"?this.generateExpression(n.expression):n.type==="IfStatement"&&this.generateNestedIfAsExpression(n)}if(this.write(" : "),e.alternate)if(e.alternate.type==="IfStatement")this.generateNestedIfAsExpression(e.alternate);else if(e.alternate.type==="BlockStatement"&&e.alternate.body.length>0){let n=e.alternate.body[e.alternate.body.length-1];n.type==="ExpressionStatement"&&this.generateExpression(n.expression)}else this.write("false");else this.write("false");this.write(")")}}generateArrayExpression(e){this.write("[");for(let n=0;n<e.elements.length;n++)this.generateExpression(e.elements[n]),n<e.elements.length-1&&this.write(", ");this.write("]")}generateObjectExpression(e){this.write("{");for(let n=0;n<e.properties.length;n++){let r=e.properties[n];r.key.type==="Identifier"?this.write(r.key.name):this.generateExpression(r.key),this.write(": "),this.generateExpression(r.value),n<e.properties.length-1&&this.write(", ")}this.write("}")}generateSwitchExpression(e){if(e.discriminant===null){this.generateSwitchAsIfElseIIFE(e);return}this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write("switch ("),this.generateExpression(e.discriminant),this.write(`) {\n`),this.indent++;for(let n of e.cases){if(this.write(this.indentStr.repeat(this.indent)),n.test?(this.write("case "),this.generateExpression(n.test),this.write(`: {\n`)):this.write(`default: {\n`),this.indent++,n.statements&&n.statements.length>0){let r=n.statements[n.statements.length-1];if(r.type==="ExpressionStatement"||r.type==="VariableDeclaration"){for(let i=0;i<n.statements.length-1;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write("return "),r.type==="ExpressionStatement"?this.generateExpression(r.expression):this.generateExpression(n.consequent),this.write(`;\n`)}else{for(let i=0;i<n.statements.length;i++)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(n.statements[i]);this.write(this.indentStr.repeat(this.indent)),this.write(`return null;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(n.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`)}this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write(`}\n`),this.writeNaForMissingDefault(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSwitchAsIfElseIIFE(e){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent));for(let n=0;n<e.cases.length;n++){let r=e.cases[n];if(r.test?(n===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {\n`)):n>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,r.statements&&r.statements.length>0){let i=r.statements[r.statements.length-1];if(i.type==="ExpressionStatement"||i.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 "),i.type==="ExpressionStatement"?this.generateExpression(i.expression):this.generateExpression(r.consequent),this.write(`;\n`)}else{for(let 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;\n`)}}else this.write(this.indentStr.repeat(this.indent)),this.write("return "),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n>=e.cases.length-1&&this.write(`\n`)}this.writeNaForMissingDefault(e),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}writeNaForMissingDefault(e){if(e.cases.some(i=>!i.test))return;let n=i=>{let s=i.statements?.length?i.statements[i.statements.length-1]:null;return s?s.type==="ExpressionStatement"?s.expression:null:i.consequent},r=e.cases.length>0&&e.cases.every(i=>{let s=n(i);return s?.type==="Literal"&&typeof s.value=="string"});this.write(this.indentStr.repeat(this.indent)),this.write(r?`return "";\n`:`return na;\n`)}generateSwitchAsIfElse(e){for(let n=0;n<e.cases.length;n++){let r=e.cases[n];if(r.test?(n===0?this.write("if ("):this.write(" else if ("),this.generateExpression(r.test),this.write(`) {\n`)):n>0?this.write(` else {\n`):this.write(`{\n`),this.indent++,r.statements&&r.statements.length>0)for(let i of r.statements)this.write(this.indentStr.repeat(this.indent)),this.generateStatement(i);else this.write(this.indentStr.repeat(this.indent)),this.generateExpression(r.consequent),this.write(`;\n`);this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("}"),n<e.cases.length-1||this.write(`\n`)}}generateLoopAsExpression(e,n){this.write(`(() => {\n`),this.indent++,this.write(this.indentStr.repeat(this.indent)),this.write(`let __result;\n`);let r=e.body;if(r&&r.body&&r.body.length>0){let i=r.body.length-1,s=r.body[i];s.type==="ExpressionStatement"&&(r.body[i]={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:{type:"Identifier",name:"__result"},right:s.expression},_line:s._line})}n==="for"?this.generateForStatement(e):this.generateWhileStatement(e),this.write(this.indentStr.repeat(this.indent)),this.write(`return __result;\n`),this.indent--,this.write(this.indentStr.repeat(this.indent)),this.write("})()")}generateSequenceExpression(e){this.write("(");for(let n=0;n<e.expressions.length;n++)this.generateExpression(e.expressions[n]),n<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}}},Dc={pi:Math.PI,e:Math.E,phi:1.618033988749895,rphi:.618033988749895},Th=/^#[0-9a-f]{6}([0-9a-f]{2})?$/i,et=(t,e,n=!0)=>Number.isFinite(t)?{value:t,type:e,exact:n}:void 0,rn=t=>!!t&&(t.type==="int"||t.type==="float")&&typeof t.value=="number",pr=(...t)=>t.every(e=>e.type==="int")?"int":"float",Qr=(...t)=>t.every(e=>e.exact);function os(t){return t.type==="int"&&typeof t.value=="number"?Math.trunc(t.value):t.value}function xn(t){if(t?.type==="Identifier")return t.name;if(t?.type==="MemberExpression"&&!t.computed&&t.property?.type==="Identifier"){let e=xn(t.object);return e===null?null:`${e}.${t.property.name}`}return null}function zt(t,e){if(t!=null)switch(t.type){case"Literal":return lS(t);case"Identifier":return t.name==="na"?void 0:ps.has(t.name)?{value:t.name,type:"source",exact:!1}:e.lookup(t.name);case"MemberExpression":return cS(t,e);case"UnaryExpression":return uS(t,e);case"BinaryExpression":case"LogicalExpression":return hS(t,e);case"ConditionalExpression":{let n=zt(t.test,e);return n?.type!=="bool"?void 0:zt(n.value?t.consequent:t.alternate,e)}case"CallExpression":return dS(t,e);default:return}}function lS(t){let e=t.value;if(typeof e=="boolean")return{value:e,type:"bool",exact:!0};if(typeof e=="string")return Th.test(e)?{value:e,type:"color",exact:!1}:{value:e,type:"string",exact:!0};if(typeof e=="number"){let n=typeof t.raw=="string"?/[.eE]/.test(t.raw):!Number.isInteger(e);return et(e,n?"float":"int")}}function cS(t,e){let n=xn(t);if(n===null)return;if(e.enums.has(n))return{value:e.enums.get(n),type:"enum",exact:!1};let[r,i]=n.split(".");if(r==="math"&&i in Dc)return et(Dc[i],"float");if(r==="color"&&kr(n))return{value:n,type:"color",exact:!1};let s=Dd[r];if(r!=="display"&&s&&typeof s=="object"&&i in s){let a=s[i];if(typeof a=="string")return{value:a,type:"string",exact:!1};if(typeof a=="number")return{value:a,type:Number.isInteger(a)?"int":"float",exact:!1}}return{value:n,type:"other",exact:!1}}function uS(t,e){let n=zt(t.argument,e);if(n){if(t.operator==="!"||t.operator==="not")return n.type==="bool"?{value:!n.value,type:"bool",exact:n.exact}:void 0;if(rn(n)){if(t.operator==="-")return et(-n.value,n.type,n.exact);if(t.operator==="+")return n}}}function hS(t,e){let n=t.operator;if(n==="&&"||n==="||"||n==="and"||n==="or"){let l=zt(t.left,e);if(l?.type!=="bool")return;if(n==="&&"||n==="and"?!l.value:l.value)return l;let c=zt(t.right,e);return c?.type==="bool"?{value:c.value,type:"bool",exact:l.exact&&c.exact}:void 0}let r=zt(t.left,e),i=zt(t.right,e);if(!r||!i)return;if(n==="+"&&r.type==="string"&&i.type==="string")return{value:String(r.value)+String(i.value),type:"string",exact:Qr(r,i)};if(n==="=="||n==="==="||n==="!="||n==="!=="){if(!(rn(r)&&rn(i)||r.type===i.type&&["string","bool"].includes(r.type)))return;let l=rn(r)?Math.abs(r.value-i.value)<1e-10:r.value===i.value;return{value:n.startsWith("=")?l:!l,type:"bool",exact:Qr(r,i)}}if(!rn(r)||!rn(i))return;let s=r.value,a=i.value,o=Qr(r,i);switch(n){case"+":return et(s+a,pr(r,i),o);case"-":return et(s-a,pr(r,i),o);case"*":return et(s*a,pr(r,i),o);case"/":{if(a===0)return;let l=pr(r,i),c=s/a;return et(l==="int"&&e.truncatingIntDivision?Math.trunc(c):c,l,o)}case"%":return a===0?void 0:et(s%a,pr(r,i),o);case">":return{value:s>a,type:"bool",exact:o};case"<":return{value:s<a,type:"bool",exact:o};case">=":return{value:s>=a,type:"bool",exact:o};case"<=":return{value:s<=a,type:"bool",exact:o};default:return}}var pS={abs:{arity:[1,1],type:"same",fn:Math.abs},max:{arity:[2,1/0],type:"same",fn:Math.max},min:{arity:[2,1/0],type:"same",fn:Math.min},avg:{arity:[2,1/0],type:"float",fn:(...t)=>t.reduce((e,n)=>e+n,0)/t.length},floor:{arity:[1,1],type:"int",fn:Math.floor},ceil:{arity:[1,1],type:"int",fn:Math.ceil},sqrt:{arity:[1,1],type:"float",fn:Math.sqrt},pow:{arity:[2,2],type:"float",fn:Math.pow},exp:{arity:[1,1],type:"float",fn:Math.exp},log:{arity:[1,1],type:"float",fn:Math.log},log10:{arity:[1,1],type:"float",fn:Math.log10},sign:{arity:[1,1],type:"float",fn:Math.sign},sin:{arity:[1,1],type:"float",fn:Math.sin},cos:{arity:[1,1],type:"float",fn:Math.cos},tan:{arity:[1,1],type:"float",fn:Math.tan},asin:{arity:[1,1],type:"float",fn:Math.asin},acos:{arity:[1,1],type:"float",fn:Math.acos},atan:{arity:[1,1],type:"float",fn:Math.atan},todegrees:{arity:[1,1],type:"float",fn:t=>t*180/Math.PI},toradians:{arity:[1,1],type:"float",fn:t=>t*Math.PI/180}};function dS(t,e){let n=xn(t.callee);if(n===null)return;let r=t.arguments??[];if(r.some(a=>a?.type==="ObjectExpression"))return;let i=r.map(a=>zt(a,e));if(i.some(a=>!a))return;let s=i;if(n==="int"&&s.length===1&&rn(s[0]))return et(Math.trunc(s[0].value),"int",s[0].exact);if(n==="float"&&s.length===1&&rn(s[0]))return et(os(s[0]),"float",s[0].exact);if(n.startsWith("math.")){let a=n.slice(5);if(a==="round"){if(!s.every(rn)||s.length<1||s.length>2)return;let c=s[0].value;if(s.length===1)return et(Math.round(c),"int",s[0].exact);let u=Math.pow(10,s[1].value);return et(Math.round(c*u)/u,"float",Qr(...s))}let o=pS[a];if(!o||s.length<o.arity[0]||s.length>o.arity[1]||!s.every(rn))return;let l=o.type==="same"?pr(...s):o.type;return et(o.fn(...s.map(c=>c.value)),l,Qr(...s))}if(n==="str.upper"||n==="str.lower"||n==="str.length"){if(s.length!==1||s[0].type!=="string")return;let a=String(s[0].value);return n==="str.length"?et(a.length,"int",s[0].exact):{value:n==="str.upper"?a.toUpperCase():a.toLowerCase(),type:"string",exact:s[0].exact}}if(n==="color.new"||n==="color.rgb")return fS(n,s);if(n==="timestamp"&&s.length===1&&s[0].type==="string")return mS(String(s[0].value))}function fS(t,e){let n=s=>Math.max(0,Math.min(1,s));if(t==="color.rgb"){let[s,a,o,l]=e.map(u=>u.value);if(typeof s!="number"||typeof a!="number"||typeof o!="number")return;let c=n((100-(typeof l=="number"?l:0))/100);return{value:Di(s,a,o,c),type:"color",exact:!1}}let r=kr(e[0]?.value),i=e[1]?.value;if(!(!r||typeof i!="number"))return{value:Di(r[0],r[1],r[2],n((100-i)/100)),type:"color",exact:!1}}function mS(t){let e=t.trim(),n=/[Zz]$/.test(e)||/[+-]\\d{2}:?\\d{2}$/.test(e),r=n?new Date(e).getTime():new Date(e.includes("T")?e+"Z":e.replace(/\\s+/,"T")+"Z").getTime();return!n&&Number.isNaN(r)&&(r=new Date(`${e} UTC`).getTime()),et(r,"int",n)}var Oc={const:0,input:1,simple:2,series:3},Jr=(...t)=>t.reduce((e,n)=>Oc[n]>Oc[e]?n:e,"const"),ro={},Yn=(t,e,n)=>n.forEach(r=>ro[r]={qual:t,type:e});Yn("series","float",["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","ask","bid"]);Yn("series","int",["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]);Yn("series","bool",["barstate.isfirst","barstate.islast","barstate.ishistory","barstate.isrealtime","barstate.isnew","barstate.isconfirmed","barstate.islastconfirmedhistory"]);Yn("simple","int",["timeframe.multiplier"]);Yn("simple","float",["syminfo.mintick","syminfo.pointvalue"]);Yn("simple","string",["timeframe.period","syminfo.ticker","syminfo.tickerid","syminfo.timezone","syminfo.currency","syminfo.type","syminfo.prefix","syminfo.root","syminfo.description"]);Yn("simple","bool",["timeframe.isintraday","timeframe.isdaily","timeframe.isweekly","timeframe.ismonthly","timeframe.isdwm","timeframe.isminutes","timeframe.isseconds"]);var yS=new Set(["cross","crossover","crossunder","rising","falling"]),gS=new Set(["barssince","highestbars","lowestbars"]),_S=new Set(["floor","ceil"]),xS=new Set(["abs","max","min"]),Ph=(...t)=>t.every(e=>e==="int")?"int":"float",Mn=t=>t==="int"||t==="float";function tn(t,e){if(t)switch(t.type){case"Literal":return typeof t.value=="boolean"?{qual:"const",type:"bool"}:typeof t.value=="string"?{qual:"const",type:Th.test(t.value)?"color":"string"}:typeof t.value=="number"?{qual:"const",type:typeof t.raw=="string"&&/[.eE]/.test(t.raw)?"float":"int"}:void 0;case"Identifier":{let n=e.lookup(t.name);return n===null?void 0:n??ro[t.name]}case"MemberExpression":{let n=xn(t);return n?.startsWith("color.")&&kr(n)?{qual:"const",type:"color"}:n?ro[n]:void 0}case"UnaryExpression":{let n=tn(t.argument,e);return n?t.operator==="!"?n.type==="bool"?n:void 0:Mn(n.type)?n:void 0:void 0}case"BinaryExpression":case"LogicalExpression":{let n=tn(t.left,e),r=tn(t.right,e);if(!n||!r)return;let i=Jr(n.qual,r.qual),s=t.operator;return["&&","||",">","<",">=","<=","==","!=","===","!=="].includes(s)?{qual:i,type:"bool"}:s==="+"&&n.type==="string"&&r.type==="string"?{qual:i,type:"string"}:["+","-","*","/","%"].includes(s)&&Mn(n.type)&&Mn(r.type)?{qual:i,type:Ph(n.type,r.type)}:void 0}case"ConditionalExpression":{let n=tn(t.test,e),r=tn(t.consequent,e),i=tn(t.alternate,e);if(!n||!r||!i)return;let s=Jr(n.qual,r.qual,i.qual);return r.type===i.type?{qual:s,type:r.type}:Mn(r.type)&&Mn(i.type)?{qual:s,type:"float"}:void 0}case"CallExpression":return bS(t,e);default:return}}function bS(t,e){let n=xn(t.callee);if(!n)return;let r=(t.arguments??[]).filter(o=>o?.type!=="ObjectExpression");if(n.startsWith("ta.")){let o=n.slice(3);return{qual:"series",type:yS.has(o)?"bool":gS.has(o)?"int":"float"}}let i=r.map(o=>tn(o,e));if(i.some(o=>!o))return;let s=i,a=Jr(...s.map(o=>o.qual));if(n==="timestamp")return s.length===1&&s[0].type==="string"?{qual:a,type:"int"}:s.length>=3?{qual:Jr("simple",a),type:"int"}:void 0;if(n==="color.new"||n==="color.rgb")return{qual:a,type:"color"};if(n==="int"&&s.length===1&&Mn(s[0].type))return{qual:a,type:"int"};if(n==="float"&&s.length===1&&Mn(s[0].type))return{qual:a,type:"float"};if(n==="str.tostring"||n==="str.format")return{qual:Jr("simple",a),type:"string"};if(n.startsWith("math.")&&s.length&&s.every(o=>Mn(o.type))){let o=n.slice(5);return o==="round"?{qual:a,type:s.length===1?"int":"float"}:_S.has(o)?{qual:a,type:"int"}:xS.has(o)?{qual:a,type:Ph(...s.map(l=>l.type))}:{qual:a,type:"float"}}}var vS={"&&":"and","||":"or","!":"not","===":"==","!==":"!="};function Rc(t,e){let n=`(${e.qual} ${e.type})`;switch(t?.type){case"Identifier":case"MemberExpression":return xn(t)??"";case"CallExpression":return`call "${xn(t.callee)}" ${n}`;case"ConditionalExpression":return`call "operator ?:" ${n}`;case"BinaryExpression":case"LogicalExpression":case"UnaryExpression":return`call "operator ${vS[t.operator]??t.operator}" ${n}`;default:return""}}function Ut(t){switch(t?.type){case"Identifier":case"Literal":case"UnaryExpression":case"ArrayExpression":return t._pos;case"MemberExpression":return Ut(t.object);case"CallExpression":return Ut(t.callee);case"BinaryExpression":case"LogicalExpression":return Ut(t.left);case"ConditionalExpression":return Ut(t.test);default:return}}var wS=Object.defineProperty,SS=(t,e,n)=>e in t?wS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,In=(t,e,n)=>SS(t,typeof e!="symbol"?e+"":e,n),ES="untitled",NS=new Set(["bool","color","enum","float","int","price","session","source","string","symbol","text_area","time","timeframe"]),Lc={"":["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"]},CS=["defval","title","inline","group","tooltip","display","active"],Fc=["defval","title","options","tooltip","inline","group","confirm","display","active"],Vc=["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display","active"],IS={"":"bool",int:"int",float:"float",bool:"bool",string:"string",text_area:"string",session:"string",symbol:"string",timeframe:"string",time:"int",price:"float",color:"color"};function kS(t,e){if(e==="defval")return IS[t];if(e==="title"||e==="tooltip"||e==="group"||e==="inline")return"string";if(e==="minval"||e==="maxval"||e==="step")return t==="int"?"int":"float";if(e==="confirm")return"bool"}var An=class{constructor(e){this.parent=e,In(this,"vars",new Map)}resolve(e){for(let n=this;n;n=n.parent){let r=n.vars.get(e);if(r)return r}}};function AS(t,e={}){return new io(t,e).run()}function Dh(t){if(t?.type!=="CallExpression")return null;let e=xn(t.callee);return e==="input"?"":e?.startsWith("input.")&&NS.has(e.slice(6))?e.slice(6):null}var io=class{constructor(e,n){this.ast=e,In(this,"sites",[]),In(this,"enums",new Map),In(this,"reassigned",new Set),In(this,"visited",new WeakSet),In(this,"inputDefaults",new WeakMap),In(this,"functionNames",new Set),In(this,"truncatingIntDivision"),this.truncatingIntDivision=n.version!=null&&n.version<6}run(){this.collectEnumsAndReassignments(this.ast);let e=new An(null);return this.visitStatements(this.ast.body??[],{scope:e,target:null,fnName:null}),this.sites}collectEnumsAndReassignments(e){Pi(e,n=>{if(n.type==="FunctionDeclaration"&&n.id?.name&&this.functionNames.add(n.id.name),n.type==="AssignmentExpression"&&n.left?.type==="Identifier"&&this.reassigned.add(n.left.name),n.type==="VariableDeclaration")for(let r of n.declarations??[]){let i=r?.init;if(!(r?.id?.type!=="Identifier"||i?.type!=="ObjectExpression"||!i.properties?.length||!i.properties.every(s=>s.value?.type==="Literal"&&typeof s.value.value=="string")))for(let s of i.properties)this.enums.set(`${r.id.name}.${s.key.name}`,s.value.value)}})}pineName(e){return e.endsWith("_var")&&this.functionNames.has(e.slice(0,-4))?e.slice(0,-4):e}env(e,n=!1){return{enums:this.enums,truncatingIntDivision:this.truncatingIntDivision,lookup:r=>{let i=e.resolve(r);if(n&&i?.kind==="value"&&!i.nonConst&&i.inputDefault)return i.inputDefault;if(!(!i||i.kind!=="value"||i.nonConst||i.busy))return i.cache===void 0&&(i.busy=!0,i.cache=zt(i.init,this.env(i.scope))??null,i.busy=!1),i.cache??void 0}}}fold(e,n){return zt(e,this.env(n))}foldCondition(e,n){let r=this.fold(e,n);return r?.type==="bool"?r.value:void 0}declareValue(e,n,r,i){let s=this.reassigned.has(n)||/\\b(series|simple)\\b/.test(i??"");e.vars.set(n,{kind:"value",name:n,init:r,scope:e,nonConst:s,inputDerived:jc(r)})}declarePattern(e,n,r){if(n?.type==="Identifier")e.vars.set(n.name,{kind:r,name:n.name});else if(n?.type==="ArrayPattern")for(let i of n.elements??[])this.declarePattern(e,i,r);else n?.type==="AssignmentPattern"&&this.declarePattern(e,n.left,r)}visitStatements(e,n){for(let r of e)this.visit(r,n)}visit(e,n){if(!(!e||typeof e!="object")){if(Array.isArray(e)){for(let r of e)this.visit(r,n);return}if(!(typeof e.type!="string"||this.visited.has(e)))switch(this.visited.add(e),e.type){case"VariableDeclaration":for(let r of e.declarations??[]){let i=r.id?.type==="Identifier"?r.id.name:null;if(this.visit(r.init,{...n,target:i?this.pineName(i):n.target}),i){this.declareValue(n.scope,i,r.init,r.varType??r.id?.varType??null);let s=n.scope.vars.get(i),a=this.inputDefaults.get(r.init);s?.kind==="value"&&a&&(s.inputDefault=a)}}return;case"AssignmentExpression":{let r=e.left?.type==="Identifier"?e.left.name:null;if(this.visit(e.right,{...n,target:r?this.pineName(r):n.target}),r&&jc(e.right)){let i=n.scope.resolve(r);i?.kind==="value"&&(i.inputDerived=!0)}return}case"BlockStatement":this.visitStatements(e.body??[],e._sequence?n:{...n,scope:new An(n.scope)});return;case"IfStatement":{this.visit(e.test,n);let r=this.foldCondition(e.test,n.scope);r!==!1&&this.visitBranch(e.consequent,n),r!==!0&&e.alternate&&this.visitBranch(e.alternate,n);return}case"ConditionalExpression":{this.visit(e.test,n);let r=this.foldCondition(e.test,n.scope);r!==!1&&this.visit(e.consequent,n),r!==!0&&this.visit(e.alternate,n);return}case"BinaryExpression":case"LogicalExpression":{this.visit(e.left,n);let r=e.operator;if((r==="&&"||r==="||")&&this.foldCondition(e.left,n.scope)===(r==="||"))return;this.visit(e.right,n);return}case"SwitchExpression":this.visitSwitch(e,n);return;case"ForStatement":{let r=new An(n.scope),i=e.init;if(i?.type==="VariableDeclaration")for(let a of i.declarations??[])this.visit(a.init,n),this.declarePattern(r,a.id,"loop");else this.visit(i,n);let s={...n,scope:r};this.visit(e.test,s),this.visit(e.update,s),this.visitBranch(e.body,s);return}case"FunctionDeclaration":{let r=new An(n.scope);for(let s of e.params??[])this.declarePattern(r,s,"param");let i={scope:r,target:null,fnName:e.id?.name??null};this.visit(e.params,i),this.visitBranch(e.body,i);return}case"CallExpression":{let r=Dh(e);if(r!==null){this.recordInput(e,r,n);return}this.visit(e.callee,n),this.visit(e.arguments,n);return}default:this.visitChildren(e,n)}}}visitBranch(e,n){e?.type==="BlockStatement"?this.visit(e,n):this.visit(e,{...n,scope:new An(n.scope)})}visitSwitch(e,n){this.visit(e.discriminant,n);let r=e.discriminant?this.fold(e.discriminant,n.scope):void 0,i=!1;for(let s of e.cases??[]){let a=!i;if(a&&s.test)if(this.visit(s.test,n),e.discriminant){let l=r?this.fold(s.test,n.scope):void 0;r&&l&&l.type===r.type&&(l.value===r.value?i=!0:a=!1)}else{let l=this.foldCondition(s.test,n.scope);l===!0?i=!0:l===!1&&(a=!1)}else a&&!s.test&&(i=!0);if(!a)continue;let o={...n,scope:new An(n.scope)};s.statements?.length?this.visitStatements(s.statements,o):this.visit(s.consequent,o)}}visitChildren(e,n){for(let r of Object.keys(e)){if(r==="args"||r==="type"||r.startsWith("_"))continue;let i=e[r];i&&typeof i=="object"&&this.visit(i,n)}}recordInput(e,n,r){let i=e.arguments??[],s=i[i.length-1],a=s?.type==="ObjectExpression",o=a?s.properties??[]:[],l=a?i.slice(0,-1):i.slice(),c=n===""?"input":`input.${n}`,u={},p=l[0]??o.find(E=>E.key?.name==="defval")?.value,h=n==="int"||n==="float"?o.some(E=>E.key?.name==="options")||l[2]?.type==="ArrayExpression"?Fc:Vc:n===""&&ea(p,r.scope)?CS:Lc[n];l.forEach((E,C)=>{C<h.length&&(u[h[C]]={node:E,holder:i,key:String(C)})});let d=n==="int"||n==="float"?new Set([...Fc,...Vc]):new Set(Lc[n]);for(let E of o)if(!(E.type!=="Property"||!E.key?.name)){if(!d.has(E.key.name))throw new Error(`The "${c}" function does not have an argument with the name "${E.key.name}"${E.key._pos?` at ${E.key._pos}`:""}`);u[E.key.name]={node:E.value,holder:E,key:"value"}}this.validateArguments(e,r.scope,u.active?.node),this.checkArgumentTypes(e,n,u,r.scope);let f={},m;for(let[E,{node:C}]of Object.entries(u)){let I=C?.type==="ArrayExpression"?void 0:E==="active"?zt(C,this.env(r.scope,!0)):this.fold(C,r.scope);E==="defval"&&(m=I?.type,I&&this.inputDefaults.set(e,I)),f[E]=I?os(I):MS(C,F=>this.fold(F,r.scope))}if(this.checkDefvalConstraints(e,n,u,f,r.scope),n==="enum"&&f.options===void 0){let E=this.enumField(u.defval?.node,r.scope),C=E?.slice(0,E.lastIndexOf(".")+1);C&&(f.options=[...this.enums].filter(([I])=>I.startsWith(C)&&!I.slice(C.length).includes(".")).map(([,I])=>I))}this.inlineDefval(u.defval,r.scope);let _=`in_${this.sites.length}`,x=typeof f.title=="string"?f.title:void 0,w=r.target??void 0,S={id:_,fn:n,name:x??r.target??r.fnName??ES,args:f};w!==void 0&&(S.varId=w),m!==void 0&&(S.defvalType=m),this.sites.push(S);let v=[new Ir(new he("__inputId"),new Je(_))];w!==void 0&&v.push(new Ir(new he("__varId"),new Je(w))),i.push(new ai(v))}inlineDefval(e,n){if(!e||!e.node||e.node.type==="Literal")return;let r=this.fold(e.node,n);if(!r||!r.exact||!["int","float","bool","string"].includes(r.type))return;let i=os(r),s=r.type==="float"&&typeof i=="number"&&Number.isInteger(i)?`${i}.0`:typeof i=="number"?String(i):null;e.holder[e.key]=new Je(i,s)}qualifierEnv(e,n=new Set){return{lookup:r=>{let i=e.resolve(r);if(!i)return;if(i.kind!=="value"||i.nonConst||i.inputDerived||n.has(i))return null;let s=this.fold({type:"Identifier",name:r},e);if(s&&["int","float","bool","string"].includes(s.type))return{qual:"const",type:s.type};n.add(i);let a=tn(i.init,this.qualifierEnv(i.scope,n));return n.delete(i),a??null}}}checkArgumentTypes(e,n,r,i){let s=this.qualifierEnv(i),a=n===""?"input":`input.${n}`,o=ta(e.callee),l=c=>c?` at ${c}`:"";for(let[c,{node:u}]of Object.entries(r)){if(!u)continue;if(n==="source"&&c==="defval"){if(ea(u,i))continue;throw new Error(`Invalid value for the "defval" parameter of the "input.source" function. Possible values: [open, high, low, close, hl2, hlc3, ohlc4, hlcc4].${l(o)}`)}if(n==="enum")continue;if(c==="defval"&&u.type==="Identifier"&&u.name==="na"&&!i.resolve("na"))throw n===""?new Error(`Arguments of input function must be of constant type, or "source" builtin variables.${l(o)}`):n==="bool"?new Error(`Cannot call "input.bool" with argument "defval"="na". An argument of "simple na" type was used but a "const bool" is expected.${l(Ut(u))}`):new Error(`The "defval" parameter of the "${a}()" function cannot accept a "na" argument.${l(Ut(u))}`);if(c==="options"&&u.type==="ArrayExpression"){this.checkOptionTypes(a,n,u,s);continue}let p=kS(n,c);if(!p)continue;let h=tn(u,s);if(!h)continue;let d=h.qual==="simple"||h.qual==="series";if(n===""&&c==="defval"){if(!d)continue;if(h.type!=="bool"&&h.type!=="string"){if(ea(u,i)||u.type==="ConditionalExpression")continue;throw new Error(`Arguments of input function must be of constant type, or "source" builtin variables.${l(o)}`)}}else if(!d&&Bc(h.type,p))continue;let f=u.type==="Literal",m=f?$c(u):Rc(u,h);throw new Error(`Cannot call "${a}" with argument "${c}"="${m}". An argument of "${f?"literal":h.qual} ${h.type}" type was used but a "const ${p}" is expected.${l(Ut(u))}`)}}checkOptionTypes(e,n,r,i){let s=n==="int"?"int":n==="float"?"float":["string","session","timeframe"].includes(n)?"string":void 0;if(!s)return;let a=r.elements??[],o=a.map(p=>tn(p,i));if(o.some(p=>!p)||o.every(p=>p.qual!=="simple"&&p.qual!=="series"&&Bc(p.type,s)))return;let l=a.map((p,h)=>p.type==="Literal"?$c(p):Rc(p,o[h])).join(","),c=a.map((p,h)=>`${p.type==="Literal"?"literal":o[h].qual} ${o[h].type}`).join(", "),u=Ut(r);throw new Error(`Cannot call "${e}" with argument "options"="${l}". An argument of "[${c}]" type was used but a "[const ${s}...]" is expected.${u?` at ${u}`:""}`)}enumField(e,n){if(e?.type==="ConditionalExpression"){let r=this.foldCondition(e.test,n);return r===void 0?null:this.enumField(r?e.consequent:e.alternate,n)}return xn(e)}checkDefvalConstraints(e,n,r,i,s){let a=r.defval?.node,o=u=>u?` at ${u}`:"";if(n==="enum"){let u=[a,...r.options?.node?.type==="ArrayExpression"?r.options.node.elements:[]].map(p=>this.enumField(p,s));if(u.some(p=>!p||!this.enums.has(p)))return;if(new Set(u.map(p=>p.slice(0,p.lastIndexOf(".")))).size>1)throw new Error(`All values passed to "input.enum()" as its "defval" or "options" must be fields of the same enum.${o(ta(e.callee))}`);if(r.options){let[p,...h]=u;if(!h.includes(p))throw new Error(`input\'s defval should be in options, but \'${p}\' is not in [${h.join(", ")}]${o(Ut(a))}`)}return}let l=i.defval;if(typeof l=="number"&&(n==="int"||n==="float")){let{minval:u,maxval:p}=i;if(typeof u=="number"&&l<u||typeof p=="number"&&l>p)throw new Error(`Input\'s "defval" value must be between "minval" and "maxval"${o(Ut(a))}`)}let c=i.options;if(Array.isArray(c)&&r.options?.node?.type==="ArrayExpression"&&(typeof l=="number"||typeof l=="string")&&!c.some(u=>typeof u=="number"&&typeof l=="number"?Math.abs(u-l)<1e-10:u===l)&&c.every(u=>typeof u==typeof l)){let u=typeof l=="string"?`\'${l}\'`:String(l);throw new Error(`input\'s defval should be in options, but ${u} is not in [${c.map(String).join(", ")}]${o(Ut(a))}`)}}validateArguments(e,n,r){let i=new Set;r&&Pi(r,s=>i.add(s)),Pi({type:"Args",list:e.arguments??[]},(s,a,o)=>{if(s.type!=="Identifier"||a?.type==="Property"&&o==="key"||a?.type==="MemberExpression"&&o==="property"&&!a.computed)return;let l=n.resolve(s.name);if(l){if(l.kind==="loop"||l.kind==="param")throw new Error(`Undeclared identifier "${s.name}"${s._pos?` at ${s._pos}`:""}`);if(l.kind==="value"&&l.inputDerived&&!i.has(s)){let c=ta(e.callee);throw new Error(`Arguments of input function must be of constant type, or "source" builtin variables.${c?` at ${c}`:""}`)}}})}};function ea(t,e){return t?.type==="Identifier"&&ps.has(t.name)&&!e.resolve(t.name)}function Bc(t,e){return t===e||e==="float"&&t==="int"}function $c(t){return String(t.value)}function MS(t,e){if(t?.type==="ArrayExpression")return(t.elements??[]).map(n=>{let r=e(n);return r?os(r):void 0})}function jc(t){let e=!1;return Pi(t,n=>{!e&&Dh(n)!==null&&(e=!0)}),e}function ta(t){let e=t;for(;e?.type==="MemberExpression";)e=e.object;return e?._pos}function Pi(t,e){let n=new WeakSet,r=(i,s,a)=>{if(!(!i||typeof i!="object")){if(Array.isArray(i)){for(let o of i)r(o,s,a);return}if(!n.has(i)){n.add(i),typeof i.type=="string"&&e(i,s,a);for(let o of Object.keys(i)){if(o==="args"||o.startsWith("_"))continue;let l=i[o];l&&typeof l=="object"&&r(l,i,o)}}}};r(t,null,"")}function Oh(t){let e=/^\\s*\\/\\/\\s*@version\\s*=\\s*(\\d+)\\s*$/im,n=t.match(e);return n&&n[1]?parseInt(n[1],10):null}function sl(t,e={}){let n=Oh(t);if(n===null)return{success:!1,version:null,error:"Pine Script version not found. Please add //@version=X comment to your script."};if(n<5)return{success:!1,version:n,error:`Pine Script version ${n} is not supported. Only version 5 and above are supported.`};try{let r=new Jw(t).tokenize(),i=new iS(r).parse(),s=AS(i,{version:n}),a={...e,sourceCode:t},o=new no(a).generate(i);return{success:!0,version:n,code:o,ast:i,tokens:r,inputs:s}}catch(r){return{success:!1,version:n,error:r.message,stack:r.stack}}}var TS=new Set(["security_lower_tf","security"]),Rh=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function PS(t){if(!t||t.type!=="CallExpression")return!1;let e=t.callee;return!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="request"||e.property?.type!=="Identifier"?!1:TS.has(e.property.name)}function DS(t){let e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function OS(t){let e=[],n=new WeakSet;function r(i,s){if(!i||typeof i!="object"||n.has(i))return;n.add(i);let a=s.concat([i]);PS(i)&&e.push({call:i,path:a});for(let o of Object.keys(i)){if(Rh.has(o))continue;let l=i[o];if(Array.isArray(l))for(let c of l)r(c,a);else l&&typeof l=="object"&&r(l,a)}}return r(t,[]),e}function so(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function en(t,e,n){if(n>=e.length-1)return t;let r=e[n+1];switch(t.type){case"BlockStatement":{let i=t.body.indexOf(r);if(i<0)return t;let s=t.body.slice(0,i);return s.push(en(r,e,n+1)),{...t,body:s}}case"IfStatement":return r===t.test?{...t,test:en(r,e,n+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:en(r,e,n+1),alternate:null}:r===t.alternate?{...t,alternate:en(r,e,n+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:en(r,e,n+1)}:t;case"SwitchStatement":{let i=t.cases.indexOf(r);if(i>=0){let s=t.cases.slice(0,i);return s.push(en(r,e,n+1)),{...t,cases:s}}return t}case"SwitchCase":{let i=t.consequent.indexOf(r);if(i>=0){let s=t.consequent.slice(0,i);return s.push(en(r,e,n+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:en(r,e,n+1)}:t;default:return t}}function RS(t){if(!t||t.type!=="CallExpression")return null;let e=t.callee;if(!e||e.type!=="MemberExpression"||e.computed||e.object?.type!=="Identifier"||e.object.name!=="$"||e.property?.type!=="Identifier"||e.property.name!=="call")return null;let n=t.arguments?.[0];return n?.type==="Identifier"&&typeof n.name=="string"?n.name:null}function LS(t,e,n){let r=t.body||[];for(let i=0;i<r.length;i++){let s=r[i];if(s!==n&&FS(s,e))return i}return-1}function FS(t,e){let n=!1,r=new WeakSet;function i(s){if(!(n||!s||typeof s!="object")&&!r.has(s)){if(r.add(s),RS(s)===e){n=!0;return}for(let a of Object.keys(s)){if(Rh.has(a))continue;let o=s[a];if(Array.isArray(o))for(let l of o)i(l);else o&&typeof o=="object"&&i(o)}}}return i(t),n}function VS(t,e){let n=-1;for(let h=1;h<e.length;h++)if(so(e[h])){n=h;break}if(n<0)return null;let r=e[n];for(let h=n+1;h<e.length;h++)if(so(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;let i=r.id.name,s=e.slice(n),a=en(r,s,0),o=LS(t,i,r);if(o<0)return null;let l=t.body||[],c=l.indexOf(r);if(c<0)return null;let u=[],p=Math.max(o,c);for(let h=0;h<=p;h++){let d=l[h];u.push(d===r?a:d)}return u}function BS(t,e){let n={type:"Program",sourceType:"module",body:[{type:"ExpressionStatement",expression:{type:"ArrowFunctionExpression",async:!!t.async,params:t.params,body:{type:"BlockStatement",body:e}}}]},r=`var _r = ${Xo(n)}\n; return _r;`;return new Function("",r)()}function $S(t){let e={};if(!t||t.type!=="Program"||!Array.isArray(t.body)||t.body.length===0)return e;let n=t.body[0],r=null;if(n.type==="ExpressionStatement"){let s=n.expression;s&&(s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression")&&(r=s)}else n.type==="FunctionDeclaration"&&(r=n);if(!r||r.body?.type!=="BlockStatement")return e;let i=OS(r.body);for(let{call:s,path:a}of i){let o=DS(s);if(!o||o in e)continue;let l=a.some(p=>so(p)),c=null;if(l)c=VS(r.body,a);else{let p=en(r.body,a,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;let u=BS(r,c);e[o]=u}return e}function jS(t){if(typeof t=="function")return{code:t.toString(),version:null};{let e=Oh(t);if(e===null)return{code:t,version:null};if(e>=5){let n=sl(t);if(n.success)return{code:n.code,version:e};throw new Error(`Failed to transpile Pine Script version ${e}: ${n.error}`)}else throw new Error(`Unsupported Pine Script version ${e}. Only version 5 and above are supported.`)}}function WS(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:n}=e,{code:r,version:i}=jS(t),s=r;s=nw(s);let a=n?s.split(`\n`):[],o=Go(s,{ecmaVersion:"latest",sourceType:"module",locations:n});rw(o),iw(o),Jv(o),Qv(o);let l=new Ba;cw(o,l),sw(o,l);let c=hw(o,l)||"";if(i!==null&&bw(o,l,{intDivision:i<6}),Ew(o,{lazyLogical:i===null||i>=6}),zw(o,l,c,e,a),$w(o),Ww(o),qw(o),Lw(o),o.type==="Program"&&o.body.length>0){let m=o.body[0],_=m?.expression||m;_.body?.type==="BlockStatement"&&_.body.body.unshift({type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"__maxLoops"},init:{type:"LogicalExpression",operator:"||",left:{type:"MemberExpression",object:{type:"Identifier",name:"$"},property:{type:"Identifier",name:"__maxLoops"},computed:!1},right:{type:"Literal",value:5e5}}}]})}let u=jv||Yo||void 0,p=Object.assign({},u,{LineComment(m,_){_.write("//"+m.value)}}),h=Xo(o,{generator:p,comments:n}),d=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:$S(o),f=new Function("",`var _r = ${h}\n; return _r;`)(this);if(f._pineVersion=i,d&&Object.keys(d).length>0){for(let m of Object.values(d))m._pineVersion=i;f._ltfSlices=d}return f}var US={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"},qS=new Set(["bool","color","time","text_area"]),zS=["open","high","low","close","hl2","hlc3","hlcc4","ohlc4"];function HS(t){if(typeof t!="string")return[];let e=sl(t);if(!e.success||!e.inputs)return[];let n=[];for(let r of e.inputs){let i=KS(r);i&&n.push(i)}return n}function KS(t){let e=t.args,n=t.fn===""?GS(e.defval,t.defvalType):US[t.fn];if(!n)return null;let r={id:t.id,name:t.name,type:n,defval:e.defval};t.varId!==void 0&&(r.varId=t.varId),e.title!==void 0&&(r.title=String(e.title)),e.tooltip!==void 0&&e.tooltip!==""&&(r.tooltip=String(e.tooltip)),e.group!==void 0&&(r.group=String(e.group)),e.inline!==void 0&&(r.inline=String(e.inline)),e.confirm!==void 0&&(r.confirm=!!e.confirm),e.active!==void 0&&(r.active=!!e.active);let i="display"in e?YS(e.display):qS.has(n)?"none":"all";return i!==void 0&&(r.display=i),Array.isArray(e.options)?r.options=e.options:n==="source"&&(r.options=[...zS]),typeof e.minval=="number"&&(r.minval=e.minval),typeof e.maxval=="number"&&(r.maxval=e.maxval),typeof e.step=="number"&&(r.step=e.step),r}function GS(t,e){switch(e){case"int":case"float":case"bool":case"string":case"color":case"source":return e}return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?ps.has(t)?"source":t.startsWith("#")?"color":"string":null}function YS(t){if(typeof t!="string")return;let e=t.startsWith("display.")?t.slice(8):t;if(e==="none"||e==="data_window"||e==="status_line"||e==="all")return e}function Lh(t,e,n,r,i="key"){let s={},a=new Map;for(let o of t)a.set(o.key,o),s[o.key]=r&&o.key in r?r[o.key]:o.defval;for(let o of t)for(let l of o.aliases??[])!l||a.has(l)||a.set(l,o);return{proxy:new Proxy(s,{get(o,l){if(typeof l=="symbol")return o[l];let c=a.get(l);return c?o[c.key]:o[l]},set(o,l,c){if(typeof l!="string")return!1;let u=a.get(l);if(!u)throw new Error(`[${e}] unknown ${i} "${l}". Known: ${[...a.keys()].join(", ")||"(none)"}`);return XS(u,c,e),o[u.key]=c,n?.(u.key),!0},deleteProperty(o,l){throw new Error(`[${e}] cannot delete "${String(l)}" \\u2014 keys are fixed by the script\'s source.`)},defineProperty(){throw new Error(`[${e}] cannot define new properties \\u2014 keys are fixed by the script\'s source.`)},ownKeys(o){return Reflect.ownKeys(o)},getOwnPropertyDescriptor(o,l){return Reflect.getOwnPropertyDescriptor(o,l)},has(o,l){return typeof l=="string"&&a.has(l)}}),values:s,entryByKey:a}}function XS(t,e,n){let r=t.key;switch(t.type){case"int":if(typeof e!="number"||!Number.isInteger(e))throw new TypeError(`[${n}] "${r}" expects an int; got ${hr(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${n}] "${r}" expects a number; got ${hr(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${n}] "${r}" expects a boolean; got ${hr(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(`[${n}] "${r}" expects a string; got ${hr(e)}`);break}if(t.options&&!t.options.some(i=>ZS(i,e)))throw new RangeError(`[${n}] "${r}" value ${hr(e)} is not one of: ${t.options.map(hr).join(", ")}`);if(typeof e=="number"){if(typeof t.minval=="number"&&e<t.minval)throw new RangeError(`[${n}] "${r}" value ${e} is below minval ${t.minval}`);if(typeof t.maxval=="number"&&e>t.maxval)throw new RangeError(`[${n}] "${r}" value ${e} is above maxval ${t.maxval}`)}}function ZS(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function hr(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function QS(t,e){let n=new Map,r=[],i=new Set(t.map(o=>o.id));for(let o of t){let l=[o.varId,o.title].find(u=>u&&!n.has(u)&&!i.has(u))??o.id,c=[o.title,o.id].filter(u=>!!u&&u!==l);n.set(l,o),r.push({key:l,type:o.type,defval:o.defval,options:o.type==="source"?void 0:o.options,minval:o.minval,maxval:o.maxval,aliases:c.length?c:void 0})}let{proxy:s,values:a}=Lh(r,"Indicator.input",e,void 0,"input key");return{proxy:s,values:a,metaByKey:n}}var Fh=[{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}],Vh=[...Fh.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"}],Bh=[...Fh.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 JS(t){return t==="strategy"?Bh:Vh}function eE(t){return typeof t=="string"?tE(t):typeof t=="function"?nE(t):{type:null,args:{}}}function tE(t){let e=sl(t);if(!e.success||!e.ast)return{type:null,args:{}};let n=null;return ls(e.ast,r=>{if(n||r.type!=="ExpressionStatement"&&r.type!=="VariableDeclaration")return;let i=r.type==="ExpressionStatement"?r.expression:r.declarations?.[0]?.init;if(!i||i.type!=="CallExpression")return;let s=i.callee;s?.type==="Identifier"&&(s.name!=="indicator"&&s.name!=="strategy"||(n={type:s.name,args:jh(i.arguments??[],$h(s.name))}))}),n??{type:null,args:{}}}function nE(t){let e;try{e=Go(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let n=null;return ls(e,r=>{if(n||r.type!=="CallExpression")return;let i=r.callee;i?.type==="Identifier"&&(i.name!=="indicator"&&i.name!=="strategy"||(n={type:i.name,args:jh(r.arguments??[],$h(i.name))}))}),n??{type:null,args:{}}}function $h(t){return t==="strategy"?Bh:Vh}function jh(t,e){let n={},r=t[t.length-1],i=r?.type==="ObjectExpression",s=i?t.slice(0,-1):t.slice();for(let a=0;a<s.length&&a<e.length;a++){let o=e[a].name;n[o]=ao(s[a])}if(i)for(let a of r.properties??[])a.type!=="Property"||!a.key?.name||(n[a.key.name]=ao(a.value));return n}function ao(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(ao);default:return}}function ls(t,e){if(!(!t||typeof t!="object")){e(t);for(let n of Object.keys(t)){let r=t[n];if(!(n==="loc"||n==="range"||n==="start"||n==="end"))if(Array.isArray(r))for(let i of r)ls(i,e);else r&&typeof r=="object"&&typeof r.type=="string"&&ls(r,e)}}}function rE(t,e,n){let r=new Map,i=[];for(let o of t)r.set(o.name,o),o.mutable&&i.push({key:o.name,type:o.type,defval:o.defval,options:o.options,minval:o.minval,maxval:o.maxval});let{proxy:s,values:a}=Lh(i,"Indicator.prop",n,e);return{proxy:s,values:a,propByName:r}}var iE=Object.defineProperty,sE=(t,e,n)=>e in t?iE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ut=(t,e,n)=>sE(t,typeof e!="symbol"?e+"":e,n),zn=class t{constructor(e,n={}){ut(this,"source"),ut(this,"inputs"),ut(this,"_prepared",null),ut(this,"_inputMeta",null),ut(this,"_inputValues",{}),ut(this,"_explicitOverrides",new Set),ut(this,"_inputProxy",null),ut(this,"_inputMetaByKey",new Map),ut(this,"_propMeta",null),ut(this,"_propValues",{}),ut(this,"_propProxy",null),ut(this,"_declarationType",null),ut(this,"_sourcePropArgs",{}),ut(this,"_explicitPropOverrides",new Set),this.source=e,this.inputs=n,Object.defineProperty(this,"input",{get:()=>this._getInputProxy(),set:()=>{throw new Error(\'[Indicator] .input cannot be replaced \\u2014 mutate individual keys (e.g. ind.input["My Title"] = 20).\')},enumerable:!0,configurable:!1}),Object.defineProperty(this,"prop",{get:()=>this._getPropProxy(),set:()=>{throw new Error(\'[Indicator] .prop cannot be replaced \\u2014 mutate individual keys (e.g. ind.prop["initial_capital"] = 50000).\')},enumerable:!0,configurable:!1})}static from(e){return e instanceof t?e:new t(e)}prepare(e={}){if(this._prepared)return this._prepared;let n=WS(this.source,{debug:!!e.debug,ln:e.ln}),r=aE(n),i=n._ltfSlices,s=this;return this._prepared={fn:n,get inputs(){return s.getRuntimeInputs()},usesVisibleRange:r,ltfSlices:i},this._prepared}usesVisibleRange(){return this.prepare().usesVisibleRange}getRuntimeInputs(){let e={...this.inputs??{}};if(this._inputMeta)for(let n of this._explicitOverrides){let r=this._inputValues[n],i=this._inputMetaByKey.get(n);i&&(e[i.id]=r),this._inputMeta.some(s=>s!==i&&(s.varId===n||s.title===n))||(e[n]=r)}return e}getInputsMeta(){return this._ensureInputsScanned(),this._inputMeta}getPropsMeta(){return this._ensurePropsScanned(),this._propMeta}getRuntimePropOverrides(){let e={};if(this._propMeta)for(let n of this._explicitPropOverrides)e[n]=this._propValues[n];return e}getDeclarationType(){return this._ensurePropsScanned(),this._declarationType}_ensureInputsScanned(){if(this._inputMeta)return;this._inputMeta=HS(this.source);for(let n of this._inputMeta)n.type==="color"&&n.defval!==void 0&&(n.defval=Td(n.defval));let e=QS(this._inputMeta,n=>this._explicitOverrides.add(n));this._inputValues=e.values,this._inputProxy=e.proxy,this._inputMetaByKey=e.metaByKey}_getInputProxy(){return this._ensureInputsScanned(),this._inputProxy}_ensurePropsScanned(){if(this._propMeta)return;let e=eE(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=JS(e.type);let n=rE(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=n.values,this._propProxy=n.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function aE(t){let e=t.toString();return Gv.some(n=>{let r=n.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${r}\\\\b`).test(e)})}var oE=Object.defineProperty,lE=(t,e,n)=>e in t?oE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fe=(t,e,n)=>lE(t,typeof e!="symbol"?e+"":e,n);function cE(t){let e=ze(t);return e?pt(e)*1e3:864e5}var Rn=class{constructor(e,n,r,i,s,a){this.source=e,this.tickerId=n,this.timeframe=r,this.limit=i,this.sDate=s,this.eDate=a,fe(this,"data",[]),fe(this,"open",[]),fe(this,"high",[]),fe(this,"low",[]),fe(this,"close",[]),fe(this,"volume",[]),fe(this,"hl2",[]),fe(this,"hlc3",[]),fe(this,"ohlc4",[]),fe(this,"hlcc4",[]),fe(this,"openTime",[]),fe(this,"closeTime",[]),fe(this,"_readyPromise",null),fe(this,"_ready",!1),fe(this,"_debugSettings",{ln:!1,debug:!1}),fe(this,"_transpiledCode",null),fe(this,"_currentIndicator",null),fe(this,"_isSecondaryContext",!1),fe(this,"_syminfo"),fe(this,"_chartTimezone",null),fe(this,"_maxLoops",5e5),fe(this,"_alertMode","realtime"),fe(this,"_viewportLeft"),fe(this,"_viewportRight"),fe(this,"_usesVisibleRange",!1),fe(this,"_lastRunViewport",{}),fe(this,"_lastResult",null),fe(this,"_lastPineTSCode",null),this._readyPromise=new Promise(o=>{this.loadMarketData(e,n,r,i,s,a).then(l=>{let c=l;this.data=c;let u=c.map(C=>C.open),p=c.map(C=>C.close),h=c.map(C=>C.high),d=c.map(C=>C.low),f=c.map(C=>C.volume),m=c.map(C=>(C.high+C.low+C.close)/3),_=c.map(C=>(C.high+C.low)/2),x=c.map(C=>(C.high+C.low+C.open+C.close)/4),w=c.map(C=>(C.high+C.low+C.close+C.close)/4),S=c.map(C=>C.openTime),v=cE(this.timeframe),E=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+v);this.open=u,this.close=p,this.high=h,this.low=d,this.volume=f,this.hl2=_,this.hlc3=m,this.ohlc4=x,this.hlcc4=w,this.openTime=S,this.closeTime=E,e&&e.getSymbolInfo?e.getSymbolInfo(n).then(C=>{this._syminfo=C,this._ready=!0,o(!0)}).catch(C=>{console.warn("Failed to get symbol info, using default values:",C),this._ready=!0,o(!0)}):(this._ready=!0,o(!0))})})}get transpiledCode(){return this._transpiledCode}markAsSecondary(){this._isSecondaryContext=!0}setTimezone(e){this._chartTimezone=e}setMaxLoops(e){this._maxLoops=e}setAlertMode(e){this._alertMode=e}setVisibleRange(e,n){this._viewportLeft=e,this._viewportRight=n}usesVisibleRange(){return this._usesVisibleRange}get visibleRangeLeft(){return this._viewportLeft}get visibleRangeRight(){return this._viewportRight}async update(e){let n=e??this._lastPineTSCode;if(!n)throw new Error("pine.update(): pineTSCode is required on the first call.");let r=this._lastResult===null,i=this._viewportLeft!==this._lastRunViewport.left||this._viewportRight!==this._lastRunViewport.right;return r||this._usesVisibleRange&&i?(this._lastPineTSCode=n,this._lastRunViewport={left:this._viewportLeft,right:this._viewportRight},this._lastResult=await this.run(n),this._lastResult):this._lastResult}setDebugSettings({ln:e,debug:n}){this._debugSettings.ln=e,this._debugSettings.debug=n}async loadMarketData(e,n,r,i,s,a){return Array.isArray(e)?e:e.getMarketData(n,r,i,s,a)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}run(e,n,r){let i=zn.from(e);if(this._currentIndicator=i,r&&r>0){let s=typeof this.eDate>"u"&&!Array.isArray(this.source);return this._runPaginated(i,n,r,s)}else return this._runComplete(i,n)}stream(e,n={}){let{live:r=!0,interval:i=1e3}=n,s=n.pageSize||this.data.length,a=zn.from(e);this._currentIndicator=a;let o={data:[],error:[],warning:[],alert:[]},l=!1,c=(h,...d)=>{o[h]&&o[h].forEach(f=>f(...d))},u=(h,d)=>{o[h]||(o[h]=[]),o[h].push(d)},p=()=>{l=!0};return(async()=>{try{r&&typeof this.eDate<"u"&&(this.eDate=Math.max(this.eDate,Date.now()));let h=!Array.isArray(this.source)&&r,d=this._runPaginated(a,void 0,s,h);for await(let f of d){if(l)break;if(f===null){await new Promise(m=>setTimeout(m,i));continue}if(c("data",f),f.warnings&&f.warnings.length>0){for(let m of f.warnings)c("warning",m);f.warnings.length=0}if(f.alerts&&f.alerts.length>0){for(let m of f.alerts)c("alert",m);f.alerts.length=0}if(h&&!l){let m=f.marketData[f.idx],_=m&&m.closeTime<Date.now(),x=f.idx>=f.marketData.length-1;(!_||x)&&await new Promise(w=>setTimeout(w,i))}}}catch(h){c("error",h)}})(),{on:u,stop:p}}async runPretranspiled(e,n={},r){await this.ready(),r||(r=this.data.length);let i=this._initializeContext(null,n,this._isSecondaryContext);i.pineVersion=e._pineVersion??null,this._transpiledCode=e;let s=e._ltfSlices;return s&&(i._ltfTruncatedBodies=s),await this._executeIterations(i,e,this.data.length-r,this.data.length),i}async _runComplete(e,n){await this.ready(),n||(n=this.data.length);let r=e.prepare(this._debugSettings);this._usesVisibleRange=r.usesVisibleRange;let i=this._initializeContext(e.source??null,r.inputs,this._isSecondaryContext);i.pineVersion=r.fn._pineVersion??null,this._transpiledCode=r.fn,r.ltfSlices&&(i._ltfTruncatedBodies=r.ltfSlices);let s=this.data.length-n,a=this.data.length;return a-s>1?(await this._executeIterations(i,r.fn,s,a-1),i._varSnapshot=this._snapshotVarState(i),await this._executeIterations(i,r.fn,a-1,a)):await this._executeIterations(i,r.fn,s,a),i}async*_runPaginated(e,n,r,i=!1){await this.ready(),n||(n=this.data.length);let s=e.prepare(this._debugSettings);this._usesVisibleRange=s.usesVisibleRange;let a=this._initializeContext(e.source??null,s.inputs,this._isSecondaryContext);a.pineVersion=s.fn._pineVersion??null,this._transpiledCode=s.fn,s.ltfSlices&&(a._ltfTruncatedBodies=s.ltfSlices);let o=this.data.length-n,l=null;for(;;){let c=this.data.length,u=c-o;if(u>0){let m=Math.min(u,r),_=this._getResultLength(a.result),x=o+m;i&&x>=c&&m>1?(await this._executeIterations(a,this._transpiledCode,o,x-1),l=this._snapshotVarState(a),await this._executeIterations(a,this._transpiledCode,x-1,x)):i&&x>=c&&m===1?await this._executeIterations(a,this._transpiledCode,o,x):await this._executeIterations(a,this._transpiledCode,o,x),o+=m,yield this._createPageContext(a,_);continue}if(!i||Array.isArray(this.source))break;let p=Date.now(),{newCandles:h,updatedLastCandle:d}=await this._updateMarketData(),f=Date.now()-p;if(h===0&&!d){yield null;continue}if(h===0&&d&&f<1e3&&await new Promise(m=>setTimeout(m,1e3-f)),a.dataVersion++,a.length=this.data.length,this._restoreVarState(a,l),Array.isArray(a.result))a.result.pop();else if(typeof a.result=="object"&&a.result!==null)for(let m in a.result)Array.isArray(a.result[m])&&a.result[m].pop();a.data.close.data.pop(),a.data.open.data.pop(),a.data.high.data.pop(),a.data.low.data.pop(),a.data.volume.data.pop(),a.data.hl2.data.pop(),a.data.hlc3.data.pop(),a.data.ohlc4.data.pop(),a.data.hlcc4.data.pop(),a.data.openTime.data.pop(),a.data.closeTime&&a.data.closeTime.data.pop(),a.data.bar_index.data.pop(),o=this.data.length-(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){let n=Object.keys(e);if(n.length>0&&Array.isArray(e[n[0]]))return e[n[0]].length}return 0}_createPageContext(e,n){let r=new Cr({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(n);else if(typeof e.result=="object"&&e.result!==null){r.result={};for(let i in e.result)Array.isArray(e.result[i])?r.result[i]=e.result[i].slice(n):r.result[i]=e.result[i]}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};let n=this.source,r=this.data.length-1,i=this.data[r].openTime;try{let s=await n.getMarketData(this.tickerId,this.timeframe,void 0,i,e);if(!s||s.length===0)return{newCandles:0,updatedLastCandle:!1};let a=!1,o=0;for(let l=0;l<s.length;l++){let c=s[l];c.openTime===i?(this._replaceCandle(r,c),a=!0):c.openTime>i&&(this._appendCandle(c),o++)}return{newCandles:o,updatedLastCandle:a}}catch(s){return console.error("Error updating market data:",s),{newCandles:0,updatedLastCandle:!1}}}_replaceCandle(e,n){this.data[e]=n,this.open[e]=n.open,this.close[e]=n.close,this.high[e]=n.high,this.low[e]=n.low,this.volume[e]=n.volume,this.hl2[e]=(n.high+n.low)/2,this.hlc3[e]=(n.high+n.low+n.close)/3,this.ohlc4[e]=(n.high+n.low+n.open+n.close)/4,this.hlcc4[e]=(n.high+n.low+n.close+n.close)/4,this.openTime[e]=n.openTime,this.closeTime[e]=n.closeTime}_appendCandle(e){this.data.push(e),this.open.push(e.open),this.close.push(e.close),this.high.push(e.high),this.low.push(e.low),this.volume.push(e.volume),this.hl2.push((e.high+e.low)/2),this.hlc3.push((e.high+e.low+e.close)/3),this.ohlc4.push((e.high+e.low+e.open+e.close)/4),this.hlcc4.push((e.high+e.low+e.close+e.close)/4),this.openTime.push(e.openTime),this.closeTime.push(e.closeTime)}async updateTail(e){if(this.data.length===0||Array.isArray(this.source))return!1;let{newCandles:n,updatedLastCandle:r}=await this._updateMarketData();if(n===0&&!r)return!1;let i=e._varSnapshot;if(i?this._restoreVarState(e,i):this._removeLastResult(e),Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let o in e.result)Array.isArray(e.result[o])&&e.result[o].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop(),e.dataVersion=(e.dataVersion||0)+1,e.length=this.data.length;let s=this.data.length-(n+1);e.rollbackDrawings(s);let a=this.data.length;return s<a-1?(await this._executeIterations(e,this._transpiledCode,s,a-1),e._varSnapshot=this._snapshotVarState(e),await this._executeIterations(e,this._transpiledCode,a-1,a)):await this._executeIterations(e,this._transpiledCode,s,a),!0}_removeLastResult(e){if(Array.isArray(e.result))e.result.pop();else if(typeof e.result=="object"&&e.result!==null)for(let i in e.result)Array.isArray(e.result[i])&&e.result[i].pop();e.data.close.data.pop(),e.data.open.data.pop(),e.data.high.data.pop(),e.data.low.data.pop(),e.data.volume.data.pop(),e.data.hl2.data.pop(),e.data.hlc3.data.pop(),e.data.ohlc4.data.pop(),e.data.hlcc4.data.pop(),e.data.openTime.data.pop(),e.data.closeTime&&e.data.closeTime.data.pop(),e.data.bar_index.data.pop();let n=["const","var","let","params"],r=i=>{for(let s of n)if(i[s])for(let a in i[s]){let o=i[s][a];o instanceof y?o.data.pop():Array.isArray(o)&&o.pop()}};r(e),e.lctx&&e.lctx.forEach(i=>r(i))}_snapshotVarState(e){let n=["const","var","let","params"],r={main:{},lctx:[]},i=s=>{let a={};for(let o of n)if(s[o]){a[o]={};for(let l in s[o]){let c=s[o][l];if(c instanceof y){let u=c.data.length,p=u>0?c.data[u-1]:void 0;a[o][l]={len:u,lastVal:p}}}}return a};if(r.main=i(e),e.lctx){let s=[];e.lctx.forEach(a=>s.push(i(a))),r.lctx=s}return r.strategy=hx(e.strategy),r.resultLength=this._getResultLength(e.result),r.dataLength=e.data.close?.data?.length??0,r}_restoreVarState(e,n){if(!n)return;let r=["const","var","let","params"],i=(s,a)=>{for(let o of r)if(!(!a[o]||!s[o]))for(let l in a[o]){let c=s[o][l],u=a[o][l];c instanceof y&&u&&typeof u.len=="number"&&(c.data.length>u.len&&(c.data.length=u.len),u.len>0&&u.lastVal!==void 0&&(c.data[u.len-1]=u.lastVal))}};if(i(e,n.main),e.lctx&&n.lctx){let s=0;e.lctx.forEach(a=>{n.lctx[s]&&i(a,n.lctx[s]),s++})}px(e.strategy,n.strategy)}_initializeContext(e,n={},r=!1){let i=new Cr({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate,inputs:n});i.pine.syminfo=dc(this._syminfo);let s=Wn(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo=dc({...this._syminfo,tickerid:gu(String(this._syminfo.tickerid??this.tickerId),"heikinashi")})),this._chartTimezone&&(i.chartTimezone=this._chartTimezone),i.viewportLeft=this._viewportLeft,i.viewportRight=this._viewportRight,i.__maxLoops=this._maxLoops,i._alertMode=this._alertMode,i._propOverrides=this._currentIndicator?.getRuntimePropOverrides()??{},i.pineTSCode=e,i.isSecondaryContext=r,i.data.close=new y([]),i.data.open=new y([]),i.data.high=new y([]),i.data.low=new y([]),i.data.volume=new y([]),i.data.hl2=new y([]),i.data.hlc3=new y([]),i.data.ohlc4=new y([]),i.data.hlcc4=new y([]),i.data.openTime=new y([]),i.data.closeTime=new y([]),i.length=this.data.length,i}async _executeIterations(e,n,r,i){let s=["const","var","let","params"];for(let a=r;a<i;a++){if(e.idx=a,e._execTick=(e._execTick||0)+1,e.data.close.data.push(this.close[a]),e.data.open.data.push(this.open[a]),e.data.high.data.push(this.high[a]),e.data.low.data.push(this.low[a]),e.data.volume.data.push(this.volume[a]),e.data.hl2.data.push(this.hl2[a]),e.data.hlc3.data.push(this.hlc3[a]),e.data.ohlc4.data.push(this.ohlc4[a]),e.data.hlcc4.data.push(this.hlcc4[a]),e.data.openTime.data.push(this.openTime[a]),e.data.closeTime.data.push(this.closeTime[a]),e.data.bar_index.data.push(a),e.strategy){rx(e),G_(e),qs(e,"open");let c=ix(e);c&&qs(e,"extreme"),nx(e,"intrabar"),c||qs(e,"extreme"),sx(e)}let o=await n(e);if(e.strategy&&Y_(e),typeof o=="object"){typeof e.result!="object"&&(e.result={});for(let c in o){e.result[c]===void 0&&(e.result[c]=[]);let u;o[c]instanceof y?u=o[c].get(0):Array.isArray(o[c])?u=o[c][o[c].length-1]:u=o[c],e.result[c].push(u)}}else Array.isArray(e.result)||(e.result=[]),e.result.push(o);for(let c of e._drawingHelpers)c.syncToPlot&&c.syncToPlot();let l=c=>{for(let u of s)if(c[u])for(let p in c[u]){let h=c[u][p];if(h instanceof y){let d=h.get(0);h.data.push(d)}else if(Array.isArray(h)){let d=h[h.length-1];h.push(d)}}};l(e),e.lctx&&e.lctx.forEach(c=>l(c))}e.strategy&&ax(e)}},uE={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6};function ei(t,e,n=1){if(e==="month"){let i=new Date(t);return Date.UTC(i.getUTCFullYear(),i.getUTCMonth()+n,1,i.getUTCHours(),i.getUTCMinutes(),i.getUTCSeconds(),i.getUTCMilliseconds())}let r={second:1e3,minute:6e4,hour:36e5,day:864e5,week:7*864e5};return t+n*r[e]}function nn(t,e,n){let[r,i,s]=t.split("-").map(Number),[a,o]=e.split(":").map(Number),l=Date.UTC(r,i-1,s,a,o,0,0),c=new Intl.DateTimeFormat("en-US",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(l)),u=x=>parseInt(c.find(w=>w.type===x).value,10),p=u("year"),h=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),_=Date.UTC(p,h-1,d,f,m,0,0)-l;return l-_}function Wc(t,e,n,r,i=1){if(e==="24x7")return ei(t,r,i);let s=e.split("-")[1];if(!s||s.length!==4)return ei(t,r,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=Uc(t,n);if(r==="second"||r==="minute"||r==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[r],p=nn(c,l,n);return Math.min(u,p)}if(r==="day")return nn(c,l,n);if(r==="week"){let u=new Date(t).getUTCDay(),p=u<=5?5-u:5-u+7,h=t+p*864e5,d=Uc(h,n);return nn(d,l,n)}if(r==="month"){let u=new Date(t),p=u.getUTCFullYear(),h=u.getUTCMonth()+i,d=new Date(Date.UTC(p,h,1)),f=new Date(d.getTime()-864e5);for(;f.getUTCDay()===0||f.getUTCDay()===6;)f.setUTCDate(f.getUTCDate()-1);let m=f.toISOString().split("T")[0];return nn(m,l,n)}return ei(t,r,i)}function Uc(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function hE(t){for(let e=0;e<t.length-1;e++)t[e].closeTime=t[e+1].openTime;t.length>0&&(t[t.length-1].closeTime=t[t.length-1].closeTime+1)}var Wh=t=>t.unit==="D"||t.unit==="W"||t.unit==="M",al=t=>Wh(t)&&!(t.unit==="D"&&t.multiplier===1);function pE(t,e){let n=ze(t);if(!n)return null;if(al(n))return e.has("D")?"D":null;let r=pt(n),i=null,s=0;for(let a of e){let o=ze(a);if(!o||Wh(o))continue;let l=pt(o);l<r&&r%l===0&&l>s&&(i=a,s=l)}return i}function Uh(t,e){let n=ze(t),r=ze(e);return!n||!r||al(n)?1/0:pt(n)/pt(r)}function dE(t,e){let n=ze(t),r=ze(e);return!n||!r?1:pt(n)/pt(r)}function fE(t,e,n,r={}){if(t.length===0)return[];let i=ze(e);if(!i)return[];if(r.calendarGrid||al(i))return mE(t,i,!!r.calendarGrid);let s=Uh(e,n);return yE(t,s)}function mE(t,e,n){let r=[],i=[],s=NaN,a=()=>{let o=oo(i);n&&(o.openTime=s,o.closeTime=wy(s,e)),r.push(o)};for(let o of t){let l=ni(o.openTime,e);i.length>0&&l!==s&&(a(),i=[]),s=l,i.push(o)}return i.length>0&&a(),r}function yE(t,e){if(t.length===0)return[];let n=[],r=[t[0]],i=gE(t),s=i>0?i*1.5:0;for(let a=1;a<t.length;a++){let o=t[a].openTime-t[a-1].openTime;(s>0&&o>s||r.length>=e)&&(n.push(oo(r)),r=[]),r.push(t[a])}return r.length>0&&n.push(oo(r)),n}function oo(t){let e=t[0],n=t[t.length-1],r=e.high,i=e.low,s=0,a=0,o=0,l=0,c=0;for(let u=0;u<t.length;u++){let p=t[u];p.high>r&&(r=p.high),p.low<i&&(i=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:i,close:n.close,volume:s,closeTime:n.closeTime,quoteAssetVolume:a,numberOfTrades:o,takerBuyBaseAssetVolume:l,takerBuyQuoteAssetVolume:c,ignore:0}}function gE(t){if(t.length<2)return 0;let e=Math.min(t.length-1,20),n=1/0;for(let r=0;r<e;r++){let i=t[r+1].openTime-t[r].openTime;i>0&&i<n&&(n=i)}return n===1/0?0:n}var _E=Object.defineProperty,xE=(t,e,n)=>e in t?_E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ki=(t,e,n)=>xE(t,typeof e!="symbol"?e+"":e,n);function bE(t){return ha(t)??t}var oi=class{constructor(e){ki(this,"_configured"),ki(this,"_requiresApiKey"),ki(this,"_providerName"),ki(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){hE(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"])}aggregatesOnCalendarGrid(){return!1}async getMarketData(e,n,r,i,s){e=Pn(e);let a=bE(n),o=this.getSupportedTimeframes();if(o.has(a))return this._getMarketDataNative(e,a,r,i,s);let l=this._aggregationSubTimeframe,c=l&&o.has(l)?l:pE(a,o);if(!c)return console.error(`${this._providerName}: Timeframe \'${n}\' is not supported and no valid sub-timeframe found for aggregation.`),[];let u=this._computeSubLimit(a,c,r),p=this.aggregatesOnCalendarGrid(),h=ze(a),d=p&&i!==void 0&&h?ni(i,h):i,f=await this._getMarketDataNative(e,c,u,d,s);if(f.length===0)return[];let m=fE(f,a,c,{calendarGrid:p});return r&&r>0&&m.length>r?m.slice(m.length-r):m}_computeSubLimit(e,n,r){if(!r)return;let i=Uh(e,n);if(i===1/0){let s=dE(e,n);return Math.ceil(r*s)+2*Math.ceil(s)}return Math.ceil(r*i)+Math.ceil(i)}},vE=Object.defineProperty,wE=(t,e,n)=>e in t?vE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,cs=(t,e,n)=>wE(t,typeof e!="symbol"?e+"":e,n),na="https://api.binance.com/api/v3",qc="https://api.binance.us/api/v3",ra={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"},lo=class{constructor(e=300*1e3){cs(this,"cache"),cs(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([n,r])=>r!==void 0).map(([n,r])=>`${n}:${r}`).join("|")}get(e){let n=this.generateKey(e),r=this.cache.get(n);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(n),null):r.data:null}set(e,n){let r=this.generateKey(e);this.cache.set(r,{data:n,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){let e=Date.now();for(let[n,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(n)}},co=class extends oi{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),cs(this,"cacheManager"),cs(this,"activeApiUrl",null),this.cacheManager=new lo(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${na}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=na,this.activeApiUrl}catch{}try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${qc}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=qc,this.activeApiUrl}catch{}return na}async _fetchRawChunk(e,n,r,i,s){let a=ra[n.toUpperCase()];if(!a)return console.error(`Unsupported timeframe: ${n}`),[];let o=`${await this.getBaseUrl()}/klines?symbol=${e}&interval=${a}`;r&&(o+=`&limit=${Math.min(r,1e3)}`),i&&(o+=`&startTime=${i}`),s&&(o+=`&endTime=${s}`);let l=await fetch(o);if(!l.ok)throw new Error(`HTTP error! status: ${l.status}`);return(await l.json()).map(c=>({openTime:parseInt(c[0]),open:parseFloat(c[1]),high:parseFloat(c[2]),low:parseFloat(c[3]),close:parseFloat(c[4]),volume:parseFloat(c[5]),closeTime:parseInt(c[6]),quoteAssetVolume:parseFloat(c[7]),numberOfTrades:parseInt(c[8]),takerBuyBaseAssetVolume:parseFloat(c[9]),takerBuyQuoteAssetVolume:parseFloat(c[10]),ignore:c[11]}))}async getMarketDataInterval(e,n,r,i){try{let s=ra[n.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${n}`),[];let a=[],o=r,l=i,c=uE[s];if(!c)return console.error(`Duration not defined for interval: ${s}`),[];for(;o<l;){let u=Math.min(o+1e3*c,l),p=await this._fetchRawChunk(e,n,1e3,o,u);if(p.length===0){let[h]=await this._fetchRawChunk(e,n,1,o);if(!h||h.openTime>=l||h.openTime<=o)break;o=h.openTime;continue}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,n,r,i){let s=r,a=[],o=i,l=0,c=Math.ceil(r/1e3)+5;for(;s>0&&l<c;){l++;let u=Math.min(s,1e3),p=await this._fetchRawChunk(e,n,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"])}aggregatesOnCalendarGrid(){return!0}async _getMarketDataNative(e,n,r,i,s){try{let a=s!==void 0,o={tickerId:e,timeframe:n,limit:r,sDate:i,eDate:s};if(a){let c=this.cacheManager.get(o);if(c)return c}if(!ra[n.toUpperCase()])return console.error(`Unsupported timeframe: ${n}`),[];if(this.shouldPaginate(r,i,s)){if(i&&s){let c=await this.getMarketDataInterval(e,n,i,s),u=r?c.slice(0,r):c;return this.cacheManager.set(o,u),u}else if(r&&r>1e3){let c=await this.getMarketDataBackwards(e,n,r,s);return this.cacheManager.set(o,c),c}}let l=await this._fetchRawChunk(e,n,r,i,s);return this.normalizeCloseTime(l),a&&this.cacheManager.set(o,l),l}catch(a){return console.error("Error in binance.klines:",a),[]}}shouldPaginate(e,n,r){return e&&e>1e3?!0:!!(n&&r)}async getSymbolInfo(e){e=Pn(e);try{let n="crypto",r=await this.getBaseUrl(),i=e,s="";e.endsWith(".P")?(n="futures",i=e.replace(".P",""),r="https://fapi.binance.com/fapi/v1",s="Perpetual"):e.includes("_")&&(n="futures",i=e,r="https://dapi.binance.com/dapi/v1",s="Delivery");let a=n==="crypto"?`${r}/exchangeInfo?symbol=${i}`:`${r}/exchangeInfo`,o=await fetch(a);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);let l=(await o.json()).symbols;if(!l||l.length===0)return console.error(`Symbol ${e} not found`),null;let c=n==="futures"?l.find(S=>S.symbol===i):l[0];if(!c)return console.error(`Symbol ${i} not found in exchange info`),null;let u=c.filters?.find(S=>S.filterType==="PRICE_FILTER"),p=c.filters?.find(S=>S.filterType==="LOT_SIZE"),h=u?parseFloat(u.tickSize):.01,d=p?parseFloat(p.minQty):0,f=Math.round(1/h),m=c.baseAsset,_=c.quoteAsset,x=s?` ${s}`:"",w=`${m} / ${_}${x}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:e,description:w,type:n,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:_,timezone:"Etc/UTC",country:"",mintick:h,pricescale:f,minmove:1,pointvalue:c.contractSize||1,mincontract:d,session:"regular",volumetype:"base",expiration_date:c.deliveryDate||NaN,employees:NaN,industry:"",sector:"",shareholders:NaN,shares_outstanding_float:NaN,shares_outstanding_total:NaN,recommendations_buy:NaN,recommendations_buy_strong:NaN,recommendations_date:NaN,recommendations_hold:NaN,recommendations_sell:NaN,recommendations_sell_strong:NaN,recommendations_total:NaN,target_price_average:NaN,target_price_date:NaN,target_price_estimates:NaN,target_price_high:NaN,target_price_low:NaN,target_price_median:NaN}}catch(n){return console.error("Error in binance.exchangeInfo:",n),null}}},SE=Object.defineProperty,EE=(t,e,n)=>e in t?SE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Wr=(t,e,n)=>EE(t,typeof e!="symbol"?e+"":e,n),NE="https://financialmodelingprep.com",zc=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"]),Hc={"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"}},Kc={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"},Gc={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"},CE={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}},uo=class extends oi{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),Wr(this,"_apiKey",null),Wr(this,"_baseUrl",NE),Wr(this,"_profileCache",new Map),Wr(this,"_symbolInfoCache",new Map),Wr(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,n,r,i,s){this.ensureConfigured();try{let a=n.toUpperCase(),o=Hc[a]||Hc[n];if(!o)return console.error(`FMP: Unsupported timeframe: ${n}`),[];let l;if(o.type==="intraday"?l=await this._fetchIntradayData(e,o.endpoint,o.interval,i,s,r):l=await this._fetchDailyData(e,i,s,r),l.length>0&&!this._mintickCache.has(e)){let c=this._estimateMintick(l);c!==void 0&&this._mintickCache.set(e,c)}return l}catch(a){return console.error("Error in FMPProvider.getMarketData:",a),[]}}async _fetchDailyData(e,n,r,i){let s=`${this._baseUrl}/stable/historical-price-eod/full?symbol=${e}&apikey=${this._apiKey}`;n&&(s+=`&from=${this._msToDateStr(n)}`),r&&(s+=`&to=${this._msToDateStr(r)}`);let a=await fetch(s);if(!a.ok){let p=await a.text();throw new Error(`FMP HTTP ${a.status}: ${p}`)}let o=await a.json();if(!Array.isArray(o)||o.length===0)return[];o.reverse();let l=i&&i>0&&i<o.length?o.slice(o.length-i):o,{session:c,timezone:u}=await this._resolveSessionInfo(e);return l.map(p=>{let h=this._dateStrToMs(p.date),d=Wc(h,c,u,"day");return{openTime:h,open:p.open,high:p.high,low:p.low,close:p.close,volume:p.volume,closeTime:d,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async _fetchIntradayData(e,n,r,i,s,a){let o=`${this._baseUrl}${n}?symbol=${e}&apikey=${this._apiKey}`;i&&(o+=`&from=${this._msToDateStr(i)}`),s&&(o+=`&to=${this._msToDateStr(s)}`);let l=await fetch(o);if(!l.ok){let m=await l.text();if(l.status===403||m.includes("Restricted Endpoint"))return console.error(`FMP: Intraday data (${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}`)}let c=await l.json();if(!Array.isArray(c)||c.length===0)return[];c.reverse();let u=a&&a>0&&a<c.length?c.slice(c.length-a):c,{periodType:p,multiplier:h}=CE[r]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let _=this._dateTimeStrToMs(m.date),x=Wc(_,d,f,p,h);return{openTime:_,open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume,closeTime:x,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),e=Pn(e),this._symbolInfoCache.has(e))return this._symbolInfoCache.get(e);try{let n=await this._fetchProfile(e),r="stock";n?.isEtf?r="etf":n?.isFund?r="fund":this._isForex(e)?r="forex":this._isCrypto(e)&&(r="crypto");let i=n?.exchange||(r==="crypto"?"CRYPTO":r==="forex"?"FX":""),s=r==="crypto"||r==="forex"?"Etc/UTC":Kc[i]||"America/New_York",a=r==="crypto"?"24x7":r==="forex"?"0000-0000":Gc[i]||"0930-1600",o=n?.currency||(this._isForex(e)?e.slice(3,6):"USD"),l=this._isForex(e)?e.slice(0,3):n?.currency||"USD",c=this._mintickCache.get(e)??.01,u=Math.round(1/c),p=Math.round(c*u),h={ticker:n?.symbol||e,tickerid:`${i}:${n?.symbol||e}`,prefix:i,root:n?.symbol||e,description:n?.companyName||e,type:r,main_tickerid:`${i}:${n?.symbol||e}`,current_contract:"",isin:n?.isin||"",basecurrency:l,currency:o,timezone:s,country:n?.country||"",mintick:c,pricescale:u,minmove:p,pointvalue:1,mincontract:0,session:a,volumetype:"base",expiration_date:0,employees:n&&parseInt(n.fullTimeEmployees)||0,industry:n?.industry||"",sector:n?.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(n){return console.error("Error in FMPProvider.getSymbolInfo:",n),null}}_estimateMintick(e){let n=[];for(let o=0;o<e.length;o++){let l=e[o],c=Math.abs(l.close-l.open),u=Math.abs(l.high-l.low);if(c>0&&n.push(c),u>0&&n.push(u),o>0){let p=Math.abs(l.close-e[o-1].close);p>0&&n.push(p)}}if(n.length===0)return;let r=Math.min(...n),i=Math.floor(Math.log10(r)),s=r/10**i,a=(Math.floor(s+1e-12)<5?1:10)*10**i;return a>=1?.01:a}async _fetchProfile(e){if(this._profileCache.has(e))return this._profileCache.get(e);let n=`${this._baseUrl}/stable/profile?symbol=${e}&apikey=${this._apiKey}`,r=await fetch(n);if(!r.ok)return null;let i=await r.json();if(!Array.isArray(i)||i.length===0)return null;let s=i[0];return this._profileCache.set(e,s),s}async _resolveSessionInfo(e){try{let n=await this._fetchProfile(e);if(n){let r=n.exchange||"",i=this._isCrypto(e),s=i?"Etc/UTC":Kc[r]||"America/New_York";return{session:i?"24x7":Gc[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)&&zc.has(e.slice(0,3))&&zc.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},IE=Object.defineProperty,kE=(t,e,n)=>e in t?IE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Vn=(t,e,n)=>kE(t,typeof e!="symbol"?e+"":e,n),AE="https://data.alpaca.markets",ME="https://paper-api.alpaca.markets/v2",TE="https://api.alpaca.markets/v2",ia=1e4,Yc={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"},PE={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"},DE={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},OE={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},ho=class extends oi{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),Vn(this,"_apiKey",null),Vn(this,"_apiSecret",null),Vn(this,"_dataUrl",AE),Vn(this,"_tradingUrl",ME),Vn(this,"_feed",null),Vn(this,"_assetCache",new Map),Vn(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=TE)}_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,n,r,i,s){this.ensureConfigured();try{let a=this._resolveTimeframe(n);if(!a)return console.error(`Alpaca: Unsupported timeframe: ${n}`),[];let o=this._isCrypto(e),l=await this._fetchAllBars(e,a,o,i,s,r);if(l.length===0)return[];let{periodType:c,multiplier:u}=this._parseAlpacaTimeframe(a);if(o)return this._convertBarsCrypto(l,c,u);let p=l[0].t.slice(0,10),h=l[l.length-1].t.slice(0,10),d=this._addDaysToDate(h,40);return await this._ensureCalendar(p,d),this._convertBarsStock(l,c,u)}catch(a){return console.error("Error in AlpacaProvider.getMarketData:",a),[]}}async _fetchAllBars(e,n,r,i,s,a){let o=[],l=null,c=a||1/0,u=Math.min(a||ia,ia);do{let p=this._buildBarsUrl(e,n,r,i,s,u,l),h=await fetch(p,{headers:this._headers()});if(!h.ok){let m=await h.text();throw new Error(`Alpaca HTTP ${h.status}: ${m}`)}let d=await h.json(),f=Object.keys(d.bars||{})[0];if(!f||!d.bars[f]||(o.push(...d.bars[f]),l=d.next_page_token,o.length>=c))break}while(l);return a&&a>0&&o.length>a?o.slice(0,a):o}_buildBarsUrl(e,n,r,i,s,a,o){let l=r?`${this._dataUrl}/v1beta3/crypto/us/bars`:`${this._dataUrl}/v2/stocks/bars`,c=new URLSearchParams;return c.set("symbols",e),c.set("timeframe",n),c.set("sort","asc"),i&&c.set("start",new Date(i).toISOString()),s&&c.set("end",new Date(s).toISOString()),a&&c.set("limit",String(Math.min(a,ia))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=Pn(e);try{let n=await this._fetchAsset(e);if(!n)return console.error(`Alpaca: Symbol ${e} not found`),null;let r=n.exchange||"",i=n.class==="crypto",s=i?"Etc/UTC":PE[r]||"America/New_York",a=i?"24x7":DE[r]||"0930-1600",o="stock";i&&(o="crypto");let l=i&&e.split("/")[1]||"USD",c=i?e.split("/")[0]||e:l,u=n.price_increment?parseFloat(n.price_increment):.01,p=Math.round(1/u);return{ticker:n.symbol,tickerid:`${r}:${n.symbol}`,prefix:r,root:i?e.split("/")[0]:n.symbol,description:n.name||n.symbol,type:o,main_tickerid:`${r}:${n.symbol}`,current_contract:"",isin:"",basecurrency:c,currency:l,timezone:s,country:i?"":"US",mintick:u,pricescale:p,minmove:1,pointvalue:1,mincontract:n.min_order_size?parseFloat(n.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(n){return console.error("Error in AlpacaProvider.getSymbolInfo:",n),null}}_convertBarsCrypto(e,n,r){return e.map((i,s,a)=>{let o=new Date(i.t).getTime(),l=s<a.length-1?new Date(a[s+1].t).getTime():ei(o,n,r);return this._toKline(i,o,l)})}_convertBarsStock(e,n,r){let i="America/New_York";return e.map(s=>{let a=new Date(s.t).getTime(),o=s.t.slice(0,10),l;if(n==="day"){let c=this._calendarCache.get(o),u=c?c.close:"16:00";l=nn(o,u,i)}else if(n==="minute"||n==="hour"){let c=a+r*{minute:6e4,hour:36e5}[n],u=this._calendarCache.get(o),p=u?u.close:"16:00",h=nn(o,p,i);l=Math.min(c,h)}else n==="week"?l=this._weeklyCloseFromCalendar(o,i):n==="month"?l=this._monthlyCloseFromCalendar(o,i):l=ei(a,n,r);return this._toKline(s,a,l)})}_toKline(e,n,r){return{openTime:n,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,n){let r=new Date(e+"T00:00:00Z"),i=r.getUTCDay(),s=i<=5?5-i:5-i+7;for(let l=s;l>=0;l--){let c=r.getTime()+l*864e5,u=new Date(c).toISOString().split("T")[0],p=this._calendarCache.get(u);if(p)return nn(u,p.close,n)}let a=r.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return nn(o,"16:00",n)}_monthlyCloseFromCalendar(e,n){let[r,i]=e.split("-").map(Number),s=new Date(Date.UTC(r,i,0)).getUTCDate();for(let o=s;o>=1;o--){let l=`${r}-${String(i).padStart(2,"0")}-${String(o).padStart(2,"0")}`,c=this._calendarCache.get(l);if(c)return nn(l,c.close,n)}let a=new Date(Date.UTC(r,i,0));for(;a.getUTCDay()===0||a.getUTCDay()===6;)a.setUTCDate(a.getUTCDate()-1);return nn(a.toISOString().split("T")[0],"16:00",n)}async _ensureCalendar(e,n){if(this._calendarCache.has(e)&&this._calendarCache.has(n))return;let r=`${this._tradingUrl}/calendar?start=${e}&end=${n}`,i=await fetch(r,{headers:this._headers()});if(!i.ok){console.warn(`Alpaca calendar API returned ${i.status}, falling back to defaults`);return}let s=await i.json();for(let a of s)this._calendarCache.set(a.date,a)}async _fetchAsset(e){if(this._assetCache.has(e))return this._assetCache.get(e);let n=encodeURIComponent(e),r=`${this._tradingUrl}/assets/${n}`,i=await fetch(r,{headers:this._headers()});if(!i.ok)return null;let s=await i.json();return this._assetCache.set(e,s),s}_parseAlpacaTimeframe(e){let n=e.match(/^(\\d+)(Min|Hour|Day|Week|Month)$/);if(n){let r=parseInt(n[1],10),i=OE[n[2]];if(i)return{periodType:i,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Yc[e.toUpperCase()]||Yc[e]||null}_isCrypto(e){return e.includes("/")}_addDaysToDate(e,n){let r=new Date(e+"T00:00:00Z");return r.setUTCDate(r.getUTCDate()+n),r.toISOString().split("T")[0]}},po=class{async getMarketData(){return[]}},RE=typeof process<"u"&&process.versions&&process.versions.node,us=null;if(RE)try{us=new po}catch{us=null}var Mk={Binance:new co,FMP:new uo,Alpaca:new ho,...us?{Mock:us}:{}};function G(t){return typeof t=="string"?t:void 0}function pe(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function qh(t){if(typeof t=="boolean")return t;if(typeof t=="object"&&t!==null&&Array.isArray(t.data)){let e=t;return qh(e.data[e.offset??0])}}function LE(t){let e=new Map,n=!1;for(let i=0;i<t.length;i+=1){let s=t[i].time;e.has(s)&&(n=!0),e.set(s,i)}if(!n)return t;let r=new Set(e.values());return t.filter((i,s)=>r.has(s))}function ol(t){let e=t??{},n=e.fullContext??e;return Object.keys({...n.indicator,...n.strategy?.config}).length>0}function vs(t){let e=t??{},n=e.fullContext??e,r={...n.indicator,...n.strategy?.config},i={title:G(r.title)??"Indicator",overlay:qh(r.overlay)??!1,precision:pe(r.precision),shorttitle:G(r.shorttitle),format:G(r.format)},s=n.plots??{},a=Object.entries(s).map(([l,c])=>{let u=c??{},p=u.options??{};return{key:l,title:G(u.title),style:G(p.style),options:p,data:Array.isArray(u.data)?LE(u.data):[],plot1:G(u.plot1)??G(p.plot1),plot2:G(u.plot2)??G(p.plot2)}}),o=n.strategy?FE(n.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function FE(t){let e=[],n=Array.isArray(t.closedtrades)?t.closedtrades:[],r=Array.isArray(t.opentrades)?t.opentrades:[];for(let i of[...n,...r]){let s=i??{},a=pe(s.entry_price),o=pe(s.entry_time),l=pe(s.size);a===void 0||o===void 0||l===void 0||l===0||e.push({id:G(s.id)??`trade_${e.length}`,entry_id:G(s.entry_id)??"",entry_price:a,entry_time:o,entry_comment:G(s.entry_comment),exit_id:G(s.exit_id),exit_price:pe(s.exit_price),exit_time:pe(s.exit_time),exit_comment:G(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var VE={line:"line",style_line:"line",style_linebr:"line",style_area:"area",style_areabr:"area",style_stepline:"step",style_steplinebr:"step",style_stepline_diamond:"step",style_histogram:"histogram",style_columns:"columns",style_circles:"circles",style_cross:"cross",shape:"markers",char:"markers",bar:"bar",candle:"candle",background:"background",barcolor:"barcolor",hline:"hline",fill:"fill",drawing_line:"drawing_line",drawing_box:"drawing_box",label:"label",drawing_polyline:"drawing_polyline",linefill:"linefill",table:"table"};function zh(t){return t==null||t===""?"line":VE[t]??"line"}function ws(t){if(typeof t!="string")return!1;let e=t.trim();if(!e)return!1;let n=e.toLowerCase();if(n==="na"||n==="nan")return!1;let r=/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})$/.exec(e);return!(r&&parseInt(r[1]??"ff",16)===0||/^rgba\\([^)]*,\\s*0(?:\\.0+)?\\s*\\)$/i.test(e))}function ce(t,e){return ws(t)?t.trim():e}var Hh="#00000000";var Xn="#2962ff",ll="#38c0fd",Kt="#089981",cn="#f23645",Zn="#787b86";var cl="#ff9800",Qn="#5b9cf6",ul="#ff5d00",hl="#0ecb81",pl="#f6465d";var BE=new Map;function R(t,e){BE.set(t,e)}function $E(t,e=""){return`<svg viewBox="0 0 16 16" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`}function P(t,e=""){return`<svg viewBox="0 0 24 24" width="1em" height="1em" ${e?e+" ":""}fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${t}</svg>`}var K=$E;R("style-candles",K(\'<path d="M4.5 2v2M4.5 12v2M11.5 2v1.5M11.5 11v3"/><rect x="2.8" y="4" width="3.4" height="8" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="3.5" width="3.4" height="7.5" rx="0.6" fill="currentColor"/>\'));R("style-bars",K(\'<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>\'));R("style-line",K(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>\'));R("style-area",K(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/><path d="M1.5 11.5 5.5 7l3 2.5 5-6V13.5h-12z" fill="currentColor" fill-opacity="0.25" stroke="none"/>\'));R("style-baseline",K(\'<path d="M1.5 8h13" stroke-dasharray="2 2"/><path d="M2.5 8 5.25 4.5 8 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M2.5 8 5.25 4.5 8 8"/><path d="M8 8l2.75 3.5L13.5 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M8 8l2.75 3.5L13.5 8"/>\'));R("style-heikinashi",K(\'<path d="M4.5 12v2M11.5 2v2"/><rect x="2.8" y="5" width="3.4" height="7" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="4" width="3.4" height="7" rx="0.6" fill="currentColor"/>\'));R("indicators",K(\'<path d="M1.5 12.5 5 7l2.5 3.5L11 4l3.5 5"/><circle cx="11" cy="4" r="1.4" fill="currentColor" stroke="none"/>\'));R("undo",K(\'<path d="M6.2 9.5 2.7 6l3.5-3.5"/><path d="M2.7 6h6.8a3.65 3.65 0 0 1 0 7.3H7.5"/>\'));R("redo",K(\'<path d="M9.8 9.5 13.3 6 9.8 2.5"/><path d="M13.3 6H6.5a3.65 3.65 0 0 0 0 7.3h2"/>\'));R("objects",K(\'<path d="M8 1.8 14 5 8 8.2 2 5z"/><path d="M2 8l6 3.2L14 8" opacity="0.7"/><path d="M2 11l6 3.2 6-3.2" opacity="0.4"/>\'));R("clock",K(\'<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>\'));R("calendar",K(\'<rect x="2.2" y="3.2" width="11.6" height="10.6" rx="1.4"/><path d="M5.2 1.8v2.8M10.8 1.8v2.8M2.2 6.8h11.6"/>\'));R("datawindow",K(\'<rect x="1.8" y="2.5" width="12.4" height="11" rx="1.5"/><path d="M4.5 5.5h4M4.5 8h7M4.5 10.5h5.5"/>\'));R("camera",K(\'<path d="M5.5 4 6.5 2.5h3L10.5 4h3A1 1 0 0 1 14.5 5v7.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"/><circle cx="8" cy="8.5" r="2.6"/>\'));R("gear",K(\'<path d="M6.55 1.4h2.9l.32 1.72c.48.14.92.38 1.3.7l1.66-.55 1.45 2.5-1.35 1.1c.08.34.12.7.12 1.07s-.04.73-.12 1.07l1.35 1.1-1.45 2.5-1.66-.55a4.3 4.3 0 0 1-1.3.7L9.45 14.6h-2.9l-.32-1.72a4.3 4.3 0 0 1-1.3-.7l-1.66.55-1.45-2.5 1.35-1.1A4.4 4.4 0 0 1 3.05 7.94c0-.37.04-.73.12-1.07l-1.35-1.1 1.45-2.5 1.66.55c.38-.32.82-.56 1.3-.7L6.55 1.4z"/><circle cx="8" cy="8" r="2.2"/>\'));R("search",K(\'<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>\'));R("bell",K(\'<path d="M8 2a4 4 0 0 0-4 4v2.5L2.5 11v1h11v-1L12 8.5V6a4 4 0 0 0-4-4z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/>\'));R("market-open",P(\'<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>\'));R("market-pre",P(\'<path d="M12 2v8"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m8 6 4-4 4 4"/><path d="M16 18a4 4 0 0 0-8 0"/>\'));R("market-post",P(\'<path d="M12 10V2"/><path d="m4.93 10.93 1.41 1.41"/><path d="M2 18h2"/><path d="M20 18h2"/><path d="m19.07 10.93-1.41 1.41"/><path d="M22 22H2"/><path d="m16 14-4 4-4-4"/><path d="M16 6a4 4 0 0 0-8 0"/>\'));R("market-extended",P(\'<path d="M22 22H2"/><path d="M12 3a5 5 0 0 0 7.5 7.5A7.5 7.5 0 1 1 12 3Z"/>\'));R("market-closed",P(\'<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>\'));R("market-holiday",P(\'<path d="m10 20-1.25-2.5L6 16"/><path d="M10 4 8.75 6.5 6 8"/><path d="m14 20 1.25-2.5L18 16"/><path d="m14 4 1.25 2.5L18 8"/><path d="m17 10-5 5-5-5"/><path d="M4 12h16"/>\'));R("chevron-right",K(\'<path d="m6 3.5 4.5 4.5L6 12.5"/>\'));R("chevron-left",K(\'<path d="M10 3.5 5.5 8l4.5 4.5"/>\'));R("chevron-down",K(\'<path d="M3.5 6 8 10.5 12.5 6"/>\'));R("chevron-up",K(\'<path d="M3.5 10 8 5.5 12.5 10"/>\'));R("chevrons-right",K(\'<path d="m4 3.5 4.5 4.5L4 12.5"/><path d="m8.5 3.5 4.5 4.5-4.5 4.5"/>\'));R("chevrons-left",K(\'<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>\'));R("replay",K(\'<path d="M14 4.2v7.6L8.6 8z"/><path d="M7.4 4.2v7.6L2 8z"/>\'));R("check",K(\'<path d="m2.8 8.4 3.4 3.4 7-7.6"/>\'));R("close",K(\'<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>\'));R("pin",K(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/>\'));R("pin-filled",K(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/><path d="M6.4 2.5h3.2v3.6l2 2.3v.9H4.4v-.9l2-2.3z" fill="currentColor" stroke="none"/>\'));R("eye",K(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>\'));R("eye-off",K(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>\'));R("lock",K(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7"/>\'));R("unlock",K(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.7-.7"/>\'));R("trash",K(\'<path d="M2.5 4.3h11M6.2 4.3V3.1a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.2M4.2 4.3l.5 9.1a1.15 1.15 0 0 0 1.15 1.1h4.3a1.15 1.15 0 0 0 1.15-1.1l.5-9.1M6.5 7v4.5M9.5 7v4.5"/>\'));R("group",K(\'<path d="M1.8 4.5V2.4a.6.6 0 0 1 .6-.6h2.1M11.5 1.8h2.1a.6.6 0 0 1 .6.6v2.1M14.2 11.5v2.1a.6.6 0 0 1-.6.6h-2.1M4.5 14.2H2.4a.6.6 0 0 1-.6-.6v-2.1"/><rect x="4" y="4" width="4.2" height="4.2" rx="0.7"/><rect x="7.8" y="7.8" width="4.2" height="4.2" rx="0.7"/>\'));R("ungroup",K(\'<rect x="1.6" y="1.6" width="6.2" height="6.2" rx="0.9"/><rect x="8.2" y="8.2" width="6.2" height="6.2" rx="0.9" stroke-dasharray="2 1.5"/>\'));R("clone",K(\'<rect x="5.5" y="5.5" width="9" height="9" rx="1.2"/><path d="M11 5.5v-3a1 1 0 0 0-1-1H2.5a1 1 0 0 0-1 1V10a1 1 0 0 0 1 1h3"/>\'));R("arrow-up",K(\'<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>\'));R("arrow-down",K(\'<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>\'));R("move-vertical",K(\'<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>\'));R("move",K(\'<path d="M8 1.8v12.4M1.8 8h12.4M5.6 4.2 8 1.8l2.4 2.4M5.6 11.8 8 14.2l2.4-2.4M4.2 5.6 1.8 8l2.4 2.4M11.8 5.6 14.2 8l-2.4 2.4"/>\'));R("pen",K(\'<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>\'));R("wave",K(\'<path d="M1.5 10.4c1.6 0 1.9-4.8 3.4-4.8s1.8 4.8 3.4 4.8 1.8-4.8 3.4-4.8 1.6 4.8 2.8 4.8"/>\'));R("folder-plus",K(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M8 7.6v3.6M6.2 9.4h3.6"/>\'));R("folder-minus",K(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M6.2 9.4h3.6"/>\'));R("collapse",K(\'<path d="M3 8h10"/>\'));R("expand",K(\'<rect x="2.2" y="2.2" width="11.6" height="11.6" rx="1.4"/><path d="M8 5.4v5.2M5.4 8h5.2"/>\'));R("plus",K(\'<path d="M8 2.8v10.4M2.8 8h10.4"/>\'));R("minus",K(\'<path d="M2.8 8h10.4"/>\'));R("maximize",K(\'<path d="M2.5 6V3a.5.5 0 0 1 .5-.5h3M10 2.5h3a.5.5 0 0 1 .5.5v3M13.5 10v3a.5.5 0 0 1-.5.5h-3M6 13.5H3a.5.5 0 0 1-.5-.5v-3"/>\'));R("restore",K(\'<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>\'));R("star",K(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\'));R("star-filled",K(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\',\'fill="currentColor"\'));R("grip",K(\'<circle cx="6" cy="3.5" r="1"/><circle cx="10" cy="3.5" r="1"/><circle cx="6" cy="8" r="1"/><circle cx="10" cy="8" r="1"/><circle cx="6" cy="12.5" r="1"/><circle cx="10" cy="12.5" r="1"/>\',\'fill="currentColor" stroke="none"\'));R("kebab",K(\'<circle cx="8" cy="3.2" r="1.2"/><circle cx="8" cy="8" r="1.2"/><circle cx="8" cy="12.8" r="1.2"/>\',\'fill="currentColor" stroke="none"\'));R("burger",K(\'<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>\'));R("info",K(\'<path d="M8 7.4v4.4"/><circle cx="8" cy="4.6" r="0.9" fill="currentColor" stroke="none"/>\'));R("reset",K(\'<path d="M2 8a6 6 0 1 0 6-6 6.5 6.5 0 0 0-4.5 1.83L2 5.33"/><path d="M2 2v3.33h3.33"/>\'));R("pane-collapse",K(\'<path d="M2.6 9.4h4v4M13.4 6.6h-4v-4"/><path d="m9.4 6.6 4.2-4.2M2.4 13.6l4.2-4.2"/>\'));R("pane-expand",K(\'<path d="M9.8 2.4h3.8v3.8M6.2 13.6H2.4V9.8"/><path d="m13.6 2.4-4.4 4.4M2.4 13.6l4.4-4.4"/>\'));R("cursor",P(\'<path d="M5 3l6 16 2-6 6-2z"/>\',\'fill="currentColor" stroke="none"\'));R("ruler",P(\'<path d="M21.3 15.3 8.7 2.7a1 1 0 0 0-1.4 0L2.7 7.3a1 1 0 0 0 0 1.4l12.6 12.6a1 1 0 0 0 1.4 0l4.6-4.6a1 1 0 0 0 0-1.4Z"/><path d="m7.5 10.5 2 2"/><path d="m10.5 7.5 2 2"/><path d="m13.5 4.5 2 2"/><path d="m4.5 13.5 2 2"/>\'));R("magnet",P(\'<path d="m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15"/><path d="m5 8 4 4"/><path d="m12 15 4 4"/>\'));R("eraser",P(\'<path d="m7 21-4.3-4.3a1 1 0 0 1 0-1.4L13 5a2 2 0 0 1 2.8 0l4.2 4.2a2 2 0 0 1 0 2.8L12 20"/><path d="M22 21H7"/><path d="m5 11 9 9"/>\'));R("pen-lock",P(\'<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="13" y="14.5" width="8" height="6" rx="1.2"/><path d="M15 14.5v-1.6a2 2 0 0 1 4 0v1.6"/>\'));R("pen-sync",P(\'<path d="M13.8 4.2a2.1 2.1 0 0 1 3 3L8.5 15.5l-3.5 1 1-3.5Z"/><rect x="12.5" y="13.5" width="6" height="4.8" rx="1"/><path d="M15.5 18.3v1a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1v-2.8a1 1 0 0 0-1-1h-1"/>\'));R("brush",P(\'<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>\'));R("bucket",P(\'<path d="m18.5 11.5-7-7L4 12a1.8 1.8 0 0 0 0 2.5l5 5a1.8 1.8 0 0 0 2.5 0Z"/><path d="m5 5 4 4"/><path d="M3.5 13.5h13"/><path d="M21 17.5c0 1.1-.9 2-2 2s-2-.9-2-2c0-1 1.2-1.7 2-3 .8 1.3 2 2 2 3Z"/>\'));R("type",P(\'<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>\'));R("bold",P(\'<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7Z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7Z"/>\',\'stroke-width="2.4"\'));R("italic",P(\'<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>\',\'stroke-width="2.2"\'));R("price-delta",P(\'<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>\'));R("date-delta",P(\'<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>\'));R("bring-front",P(\'<rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/>\'));R("send-back",P(\'<rect x="8.5" y="8.5" width="7" height="7" rx="1.5" fill="currentColor" stroke="none" opacity="0.35"/><path d="M4.5 10.5V6a1.5 1.5 0 0 1 1.5-1.5h4.5"/><path d="M19.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5h-4.5"/><rect x="8.5" y="8.5" width="7" height="7" rx="1.5"/>\'));R("r-squared",\'<svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" stroke="none"><text x="2.5" y="17.5" font-size="14" font-family="serif">R\\xB2</text></svg>\');R("bands",P(\'<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>\'));R("dedekind",P(\'<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0"/><path d="M8 20a4 4 0 0 1 8 0"/><path d="M12 4v16"/>\'));R("sonic",P(\'<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>\'));R("supersonic",P(\'<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>\'));var L=ll;function jE(){return{lineColor:L,lineWidth:2,lineStyle:"solid"}}function Es(t=""){return{value:t,size:"normal",hAlign:"left",vAlign:"top"}}var op=class lp{constructor(e){this.locked=!1,this.visible=!0,this.zIndex=0,this.id=e.id??`dw-${lp.seq+=1}`,this.paneId=e.paneId,this.anchors=(e.anchors??[]).map(n=>({time:n.time,price:n.price})),this.style=e.style?{...e.style}:jE(),this.text=e.text?{...e.text}:void 0,this.locked=e.locked??!1,this.visible=e.visible??!0,this.zIndex=e.zIndex??0,this.createdAt=e.createdAt??Date.now(),e.props&&this.readProps(e.props)}isComplete(){return this.anchors.length>=this.anchorSchema().min}placementMode(){return"click"}onPlaced(e){}constrainHandleDrag(e){}translateBody(e,n,r){return r.map(i=>({time:i.time+e,price:i.price+n}))}timeExtent(){if(this.anchors.length===0)return null;let e=1/0,n=-1/0;for(let r of this.anchors)r.time<e&&(e=r.time),r.time>n&&(n=r.time);return{min:e,max:n}}editableLevels(){return null}applySettings(e){for(let[n,r]of Object.entries(e))n.startsWith("text.")&&!this.text&&(this.text=Es()),WE(this,n,r)}applyProps(e){this.readProps(e)}serialize(){return{id:this.id,type:this.type,paneId:this.paneId,anchors:this.anchors.map(e=>({time:e.time,price:e.price})),style:{...this.style},text:this.text?{...this.text}:void 0,locked:this.locked,visible:this.visible,zIndex:this.zIndex,createdAt:this.createdAt,props:this.writeProps()}}writeProps(){}readProps(e){}};op.seq=0;var xe=op;function WE(t,e,n){let r=e.split("."),i=t;for(let s=0;s<r.length-1;s+=1){let a=r[s],o=i[a];(o==null||typeof o!="object")&&(o={},i[a]=o),i=o}i[r[r.length-1]]=n}var Pr=[{value:"solid",label:"Solid"},{value:"dashed",label:"Dashed"},{value:"dotted",label:"Dotted"}],re=[{path:"style.lineColor",label:"Line color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Line width",kind:"number",min:1,max:10,step:1,group:"line"},{path:"style.lineStyle",label:"Line style",kind:"lineStyle",options:Pr,group:"line"}],gt=[{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"}],fl=[{value:"small",label:"Small"},{value:"normal",label:"Normal"},{value:"large",label:"Large"},{value:"huge",label:"Huge"}],se=[{path:"text.value",label:"Text",kind:"text",group:"text"},{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:fl,group:"text"},{path:"text.bold",label:"Bold",kind:"boolean",group:"text"},{path:"text.italic",label:"Italic",kind:"boolean",group:"text"}];function We(t,e,n,r,i,s){let a=i-n,o=s-r,l=a*a+o*o;if(l<=1e-9)return Math.hypot(t-n,e-r);let c=((t-n)*a+(e-r)*o)/l;return c=c<0?0:c>1?1:c,Math.hypot(t-(n+c*a),e-(r+c*o))}function ml(t,e,n){let r=1/0;for(let i=1;i<n.length;i+=1){let s=n[i-1],a=n[i],o=We(t,e,s[0],s[1],a[0],a[1]);o<r&&(r=o)}return r}function Sn(t,e,n,r,i,s,a=0){let o=Math.min(n,i)-a,l=Math.max(n,i)+a,c=Math.min(r,s)-a,u=Math.max(r,s)+a;return t>=o&&t<=l&&e>=c&&e<=u}function mi(t,e,n){let r=!1;for(let i=0,s=n.length-1;i<n.length;s=i,i+=1){let a=n[i],o=n[s];a[1]>e!=o[1]>e&&t<(o[0]-a[0])*(e-a[1])/(o[1]-a[1])+a[0]&&(r=!r)}return r}function be(t,e,n,r=6){for(let i=0;i<n.length;i+=1){let s=n[i];if(Math.hypot(t-s[0],e-s[1])<=r)return i}return-1}function it(t,e,n,r,i,s,a){if(i==="none")return[t,e,n,r];let o=n-t,l=i==="left"||i==="both",c=i==="right"||i==="both";if(Math.abs(o)<1e-6){if(l&&c)return[t,0,n,a];let f=r>=e;return c?f?[t,e,n,a]:[t,e,n,0]:f?[t,0,n,r]:[t,a,n,r]}let u=(r-e)/o,p=f=>e+u*(f-t),h=l?-2:Math.min(t,n),d=c?s+2:Math.max(t,n);return[h,p(h),d,p(d)]}var UE=class extends xe{constructor(){super(...arguments),this.type="trendline"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&We(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);if(!e)return null;let n=Math.min(e[0],e[2]),r=Math.min(e[1],e[3]);return{x:n,y:r,w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,{path:"style.arrowRight",label:"Arrow",kind:"boolean",group:"line"},...se]}}},qE=class extends xe{constructor(){super(...arguments),this.type="hline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"y"}]}}y(t){let e=this.anchors[0];return e?t.yOf(e.price,this.paneId):null}hitTest(t,e,n,r){let i=this.y(n);return i!=null&&Math.abs(e-i)<=r}handlePoints(t){let e=this.anchors[0],n=this.y(t);return!e||n==null?[]:[[t.xOf(e.time),n]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.y(t);return e==null?null:{x:0,y:e-1,w:t.width,h:2}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return{fields:[...re,...se]}}},zE=class extends xe{constructor(){super(...arguments),this.type="ray"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);if(!i)return!1;let[s,a,o,l]=it(i[0],i[1],i[2],i[3],"right",n.width,n.height);return We(t,e,s,a,o,l)<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...se]}}},yl=class extends xe{anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&We(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...se]}}},HE=class extends yl{constructor(){super(...arguments),this.type="extendedline"}hitTest(t,e,n,r){let i=this.pixels(n);if(!i)return!1;let[s,a,o,l]=it(i[0],i[1],i[2],i[3],"both",n.width,n.height);return We(t,e,s,a,o,l)<=r}timeExtent(){return null}},KE=class extends xe{constructor(){super(...arguments),this.type="vline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"x"}]}}x(t){let e=this.anchors[0];return e?t.xOf(e.time):null}hitTest(t,e,n,r){let i=this.x(n);return i!=null&&Math.abs(t-i)<=r}handlePoints(t){let e=this.anchors[0],n=this.x(t);if(!e||n==null)return[];let r=t.yOf(e.price,this.paneId);return r==null?[]:[[n,r]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.x(t);return e==null?null:{x:e-1,y:0,w:2,h:t.height}}priceRange(){return null}schema(){return{fields:[...re,...se]}}},GE=class extends xe{constructor(){super(...arguments),this.type="hray"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.pt(n);return i!=null&&We(t,e,i[0],i[1],n.width,i[1])<=r}handlePoints(t){let e=this.pt(t);return e?[e]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pt(t);return e?{x:e[0],y:e[1]-1,w:Math.max(0,t.width-e[0]),h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){let t=this.anchors[0];return t?{min:t.time,max:Number.POSITIVE_INFINITY}:null}schema(){return{fields:[...re,...se]}}},YE=class extends xe{constructor(){super(...arguments),this.type="crossline"}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}pt(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.pt(n);return i!=null&&(Math.abs(e-i[1])<=r||Math.abs(t-i[0])<=r)}handlePoints(t){let e=this.pt(t);return e?[e]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pt(t);return e?{x:e[0]-1,y:e[1]-1,w:2,h:2}:null}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}timeExtent(){return null}schema(){return{fields:[...re,...se]}}},XE=class extends yl{constructor(){super(...arguments),this.type="infoline"}},ZE=class extends yl{constructor(){super(...arguments),this.type="trendangle"}},QE=class extends xe{constructor(){super(...arguments),this.type="box"}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i?this.style.fillColor&&Sn(t,e,i.x1,i.y1,i.x2,i.y2)?!0:[[i.x1,i.y1,i.x2,i.y1],[i.x2,i.y1,i.x2,i.y2],[i.x2,i.y2,i.x1,i.y2],[i.x1,i.y2,i.x1,i.y1]].some(a=>We(t,e,a[0],a[1],a[2],a[3])<=r):!1}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re.map(t=>({...t,label:t.label.replace("Line","Border")})),{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"},...se]}}},JE={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},gl=class extends xe{defaultLabel(){return"Text"}labelText(){return this.text?.value??this.defaultLabel()}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}box(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=JE[this.text?.size??"normal"]??14,i=this.labelText().split(`\n`),s=Math.max(1,...i.map(a=>a.length));return{x:t.xOf(e.time),y:n,w:Math.max(12,s*r*.6)+8,h:i.length*r*1.4+4}}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Sn(t,e,i.x,i.y,i.x+i.w,i.y+i.h)}handlePoints(t){let e=this.anchors[0],n=e?t.yOf(e.price,this.paneId):null;return e&&n!=null?[[t.xOf(e.time),n]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){return this.box(t)}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}},eN=class extends gl{constructor(t){super(t),this.type="text",this.text||(this.text={...Es(),size:"large"})}schema(){return{fields:[...se],textIsContent:!0}}},tN=class extends gl{constructor(t){super(t),this.type="note",this.text||(this.text=Es("Note"))}defaultLabel(){return"Note"}schema(){return{fields:[...re,...gt,...se],textIsContent:!0}}},nN=class extends gl{constructor(){super(...arguments),this.type="pricelabel"}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return{fields:[...re,...gt,...se.filter(t=>t.path!=="text.value")]}}},rN={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Ns=class extends xe{constructor(t){super(t),this.text||(this.text=Es(this.defaultLabel()))}defaultLabel(){return"Callout"}labelText(){return this.text?.value??this.defaultLabel()}anchorSchema(){return{min:2,max:2,slots:[{role:"target",free:"both"},{role:"box",free:"both"}]}}box(t){let e=this.anchors[1];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=rN[this.text?.size??"normal"]??14,i=this.labelText().split(`\n`),s=Math.max(1,...i.map(l=>l.length)),a=Math.max(20,s*r*.6)+16,o=i.length*r*1.4+12;return{x:t.xOf(e.time)-a/2,y:n-o/2,w:a,h:o}}points(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitTest(t,e,n,r){let i=this.box(n);if(i&&Sn(t,e,i.x,i.y,i.x+i.w,i.y+i.h,r))return!0;let s=this.points(n);return s!=null&&We(t,e,s[0][0],s[0][1],s[1][0],s[1][1])<=r}handlePoints(t){let e=this.points(t);return e?[e[0]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}translateBody(t,e,n){let r=n[0],i=n[1];return!r||!i?n.map(s=>({time:s.time+t,price:s.price+e})):[{time:r.time,price:r.price},{time:i.time+t,price:i.price+e}]}bounds(t){return this.box(t)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...gt,...se],textIsContent:!0}}},iN=class extends Ns{constructor(){super(...arguments),this.type="callout"}},sN=class extends Ns{constructor(){super(...arguments),this.type="pricenote"}defaultLabel(){return""}labelText(){let t=this.anchors[0]?.price;return t==null?"0.00":t.toFixed(2)}schema(){return{fields:[...re,...gt,...se.filter(t=>t.path!=="text.value")]}}},aN=class extends Ns{constructor(){super(...arguments),this.type="comment"}defaultLabel(){return"Comment"}},oN=class extends Ns{constructor(){super(...arguments),this.type="signpost"}defaultLabel(){return"Signpost"}},Gt=class extends xe{hitTest(t,e,n,r){let i=this.geometry(n);return i?this.style.fillColor&&i.fill&&mi(t,e,i.fill)?!0:i.segments.some(s=>We(t,e,s[0],s[1],s[2],s[3])<=r):!1}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}},lN=class extends Gt{constructor(){super(...arguments),this.type="parallelchannel"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"y"}]}}offset(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];return!t||!e||!n?0:n.price-(t.price+e.price)/2}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return[];let s=[[t.xOf(e.time),r],[t.xOf(n.time),i]],a=this.anchors[2];if(a){let o=t.yOf(a.price,this.paneId);o!=null&&s.push([t.xOf((e.time+n.time)/2),o])}return s}timeExtent(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.time,e.time),max:Math.max(t.time,e.time)}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=this.offset(),i=t.xOf(e.time),s=t.xOf(n.time),a=t.yOf(e.price,this.paneId),o=t.yOf(n.price,this.paneId),l=t.yOf(e.price+r,this.paneId),c=t.yOf(n.price+r,this.paneId);return a==null||o==null||l==null||c==null?null:{segments:[[i,a,s,o],[i,l,s,c]],fill:[[i,a],[s,o],[s,c],[i,l]]}}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=this.offset(),r=[t.price,e.price,t.price+n,e.price+n],i=this.anchors[2];return i&&r.push(i.price),{min:Math.min(...r),max:Math.max(...r)}}schema(){return{fields:[...re,...gt,...se]}}},cN=class extends Gt{constructor(){super(...arguments),this.type="disjointchannel"}anchorSchema(){return{min:4,max:4,slots:[{role:"top1",free:"both"},{role:"top2",free:"both"},{role:"bot1",free:"both"},{role:"bot2",free:"both"}]}}seg(t,e,n){let r=this.anchors[t],i=this.anchors[e];if(!r||!i)return null;let s=n.yOf(r.price,this.paneId),a=n.yOf(i.price,this.paneId);return s==null||a==null?null:[n.xOf(r.time),s,n.xOf(i.time),a]}geometry(t){let e=this.seg(0,1,t),n=this.seg(2,3,t),r=[e,n].filter(s=>s!=null);if(r.length===0)return null;let i=e&&n?[[e[0],e[1]],[e[2],e[3]],[n[2],n[3]],[n[0],n[1]]]:null;return{segments:r,fill:i}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...gt,...se]}}},uN=class extends Gt{constructor(){super(...arguments),this.type="flattopbottom"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"flat",free:"y"}]}}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return[];let s=[[t.xOf(e.time),r],[t.xOf(n.time),i]],a=this.anchors[2];if(a){let o=t.yOf(a.price,this.paneId);o!=null&&s.push([t.xOf((e.time+n.time)/2),o])}return s}timeExtent(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.time,e.time),max:Math.max(t.time,e.time)}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=t.yOf(e.price,this.paneId),a=t.yOf(n.price,this.paneId);if(s==null||a==null)return null;let o=this.anchors[2];if(!o)return{segments:[[r,s,i,a]],fill:null};let l=t.yOf(o.price,this.paneId);return l==null?null:{segments:[[r,s,i,a],[r,l,i,l]],fill:[[r,s],[i,a],[i,l],[r,l]]}}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=[t.price,e.price],r=this.anchors[2];return r&&n.push(r.price),{min:Math.min(...n),max:Math.max(...n)}}schema(){return{fields:[...re,...gt,...se]}}},hN=2;function Kh(){return{midColor:Zn,midStyle:"solid",upperColor:Kt,upperStyle:"solid",lowerColor:cn,lowerStyle:"solid",upperFill:`${Kt}26`,lowerFill:`${cn}26`,showR2:!0}}function pN(t){let e=t.length;if(e<2)return null;let n=0,r=0,i=0,s=0,a=0;for(let f=0;f<e;f+=1){let m=t[f].close;n+=f,r+=m,i+=f*m,s+=f*f,a+=m*m}let o=e*s-n*n,l=o===0?0:(e*i-n*r)/o,c=(r-l*n)/e,u=0;for(let f=0;f<e;f+=1){let m=t[f].close-(c+l*f);u+=m*m}let p=Math.sqrt(u/e),h=Math.sqrt(o*(e*a-r*r)),d=h===0?0:(e*i-n*r)/h;return{t0:t[0].time,t1:t[e-1].time,mid0:c,mid1:c+l*(e-1),dev:hN*p,r2:Math.max(0,Math.min(1,d*d)),n:e}}var dN=class extends xe{constructor(t){super(t),this.type="regressionchannel",this.cachedRange=null,this.reg||(this.reg=Kh())}anchorSchema(){return{min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}fit(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=Math.min(e.time,n.time),i=Math.max(e.time,n.time),s=t.barsInRange?.(r,i)??null,a=s?pN(s):null;return a&&(this.cachedRange={min:Math.min(a.mid0,a.mid1)-a.dev,max:Math.max(a.mid0,a.mid1)+a.dev}),a}layout(t){let e=this.fit(t);if(!e)return null;let n=t.yOf(e.mid0,this.paneId),r=t.yOf(e.mid1,this.paneId),i=t.yOf(e.mid0+e.dev,this.paneId),s=t.yOf(e.mid1+e.dev,this.paneId),a=t.yOf(e.mid0-e.dev,this.paneId),o=t.yOf(e.mid1-e.dev,this.paneId);return n==null||r==null||i==null||s==null||a==null||o==null?null:{x0:t.xOf(e.t0),x1:t.xOf(e.t1),midY0:n,midY1:r,upperY0:i,upperY1:s,lowerY0:a,lowerY1:o,r2:e.r2,showR2:this.reg.showR2}}band(t){let e=this.layout(t);return e?[[e.x0,e.upperY0],[e.x1,e.upperY1],[e.x1,e.lowerY1],[e.x0,e.lowerY0]]:null}hitTest(t,e,n,r){let i=this.layout(n);if(!i)return!1;let s=[[i.x0,i.upperY0],[i.x1,i.upperY1],[i.x1,i.lowerY1],[i.x0,i.lowerY0]];return mi(t,e,s)?!0:[[i.x0,i.midY0,i.x1,i.midY1],[i.x0,i.upperY0,i.x1,i.upperY1],[i.x0,i.lowerY0,i.x1,i.lowerY1]].some(o=>We(t,e,o[0],o[1],o[2],o[3])<=r)}handlePoints(t){let e=this.layout(t);if(e)return[[e.x0,e.midY0],[e.x1,e.midY1]];let n=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return[];n.push([t.xOf(r.time),i])}return n}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.band(t);if(!e)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"reg.midColor",label:"Midline color",kind:"color",group:"line"},{path:"reg.midStyle",label:"Midline style",kind:"lineStyle",group:"line"},{path:"reg.upperColor",label:"Upper line color",kind:"color",group:"line"},{path:"reg.upperStyle",label:"Upper line style",kind:"lineStyle",group:"line"},{path:"reg.lowerColor",label:"Lower line color",kind:"color",group:"line"},{path:"reg.lowerStyle",label:"Lower line style",kind:"lineStyle",group:"line"},{path:"reg.upperFill",label:"Upper fill",kind:"color",group:"fill"},{path:"reg.lowerFill",label:"Lower fill",kind:"color",group:"fill"},{path:"reg.showR2",label:"Show R\\xB2",kind:"boolean",group:"behavior"}]}}writeProps(){return{...this.reg}}readProps(t){this.reg={...Kh(),...t}}},Gh=`${Qn}00`;function Yh(){return{midColor:Qn,midStyle:"solid",multiplier:1,upperColor:Gh,upperStyle:"solid",lowerColor:Gh,lowerStyle:"solid",bandFill:`${Qn}33`}}function fN(t,e){let n=t.length;if(n<1)return null;let r=0;for(let c of t)r+=c.volume>0?c.volume:0;let i=r>0,s=0,a=0,o=0,l=[];for(let c=0;c<n;c+=1){let u=t[c],p=(u.high+u.low+u.close)/3,h=i?Math.max(0,u.volume):1;s+=h,a+=p*h,o+=p*p*h;let d=s>0?a/s:p,f=s>0?Math.max(0,o/s-d*d):0,m=Math.sqrt(f)*e;l.push({time:u.time,mid:d,upper:d+m,lower:d-m})}return l}var mN=class extends xe{constructor(t){super(t),this.type="anchoredvwap",this.cachedRange=null,this.cachedExtent=null,this.vwap||(this.vwap=Yh())}anchorSchema(){return{min:1,max:1,slots:[{role:"anchor",free:"x"}]}}series(t){let e=this.anchors[0];if(!e)return null;let n=t.barsInRange?.(e.time,Number.POSITIVE_INFINITY)??null;if(!n||n.length<1)return null;let r=fN(n.map(i=>({time:i.time,high:i.high,low:i.low,close:i.close,volume:i.volume??0})),this.vwap.multiplier);if(r&&r.length>0){let i=1/0,s=-1/0;for(let a of r)a.lower<i&&(i=a.lower),a.upper>s&&(s=a.upper);this.cachedRange={min:i,max:s},this.cachedExtent={min:r[0].time,max:r[r.length-1].time}}return r}layout(t){let e=this.series(t);if(!e)return null;let n=[],r=[],i=[];for(let s of e){let a=t.xOf(s.time),o=t.yOf(s.mid,this.paneId),l=t.yOf(s.upper,this.paneId),c=t.yOf(s.lower,this.paneId);o==null||l==null||c==null||(n.push([a,o]),r.push([a,l]),i.push([a,c]))}return n.length>0?{mid:n,upper:r,lower:i}:null}bandPolygon(t){return[...t.upper,...[...t.lower].reverse()]}hitTest(t,e,n,r){let i=this.layout(n);return i?mi(t,e,this.bandPolygon(i))?!0:dl(t,e,i.mid,r)||dl(t,e,i.upper,r)||dl(t,e,i.lower,r):!1}handlePoints(t){let e=this.layout(t);if(e&&e.mid.length>0)return[e.mid[0]];let n=this.anchors[0];if(!n)return[];let r=t.yOf(n.price,this.paneId);return r==null?[]:[[t.xOf(n.time),r]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.layout(t);if(!e)return null;let n=[...e.upper,...e.lower],r=n.map(o=>o[0]),i=n.map(o=>o[1]),s=Math.min(...r),a=Math.min(...i);return{x:s,y:a,w:Math.max(...r)-s,h:Math.max(...i)-a}}priceRange(){return this.cachedRange}timeExtent(){return this.cachedExtent}schema(){return{fields:[{path:"vwap.midColor",label:"VWAP color",kind:"color",group:"line"},{path:"vwap.midStyle",label:"VWAP style",kind:"lineStyle",group:"line"},{path:"vwap.multiplier",label:"Band multiplier",kind:"number",min:.5,max:5,step:.5,group:"behavior"},{path:"vwap.upperColor",label:"Upper band color",kind:"color",group:"line"},{path:"vwap.lowerColor",label:"Lower band color",kind:"color",group:"line"},{path:"vwap.bandFill",label:"Band fill",kind:"color",group:"fill"}]}}writeProps(){return{...this.vwap}}readProps(t){this.vwap={...Yh(),...t}}};function dl(t,e,n,r){for(let i=1;i<n.length;i+=1)if(We(t,e,n[i-1][0],n[i-1][1],n[i][0],n[i][1])<=r)return!0;return!1}var yN=`${Kt}66`,gN=`${cn}66`,_N=`${Kt}BF`,xN=`${cn}BF`;function Xh(){return{rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:yN,downColor:gN,vaUpColor:_N,vaDownColor:xN,showVah:!0,vahColor:Zn,vahStyle:"solid",showVal:!0,valColor:Zn,valStyle:"solid",showPoc:!0,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:!1,developingPocColor:Xn,developingPocStyle:"dotted",showDevelopingVa:!1,developingVaColor:Xn,developingVaStyle:"dotted"}}function bN(t,e){return t<0?0:t>=e?e-1:t}function cp(t,e,n){let r=t.length,i=0,s=0;for(let u=0;u<r;u+=1){let p=t[u].up+t[u].down;i+=p,p>s&&(s=p)}let a=i*Math.min(1,Math.max(0,n)),o=e,l=e,c=s;for(;c<a&&(o>0||l<r-1);){let u=o>0?t[o-1].up+t[o-1].down:-1,p=l<r-1?t[l+1].up+t[l+1].down:-1;p>u?(l+=1,c+=p):(o-=1,c+=u)}return{vaFrom:o,vaTo:l}}function up(t,e,n,r){let i=r.volume;if(!(i>0))return;let s=t.length,a=r.close>=r.open?"up":"down",o=new Set;for(let l of[r.open,r.high,r.low,r.close])o.add(bN(Math.floor((l-e)/n),s));for(let l of o)t[l][a]+=i}function hp(t){let e=0,n=0;for(let r=0;r<t.length;r+=1){let i=t[r].up+t[r].down;i>e&&(e=i,n=r)}return e>0?{poc:n,maxTotal:e}:null}function vN(t,e,n){let r=1/0,i=-1/0;for(let d of t)d.volume>0&&(d.low<r&&(r=d.low),d.high>i&&(i=d.high));if(!Number.isFinite(r))return null;let s=i>r?Math.max(1,Math.round(e)):1,a=i>r?(i-r)/s:1,o=Array.from({length:s},(d,f)=>({price:r+f*a,up:0,down:0}));for(let d of t)up(o,r,a,d);let l=hp(o);if(!l)return null;let{poc:c,maxTotal:u}=l,{vaFrom:p,vaTo:h}=cp(o,c,n);return{rows:o,rowH:a,min:r,maxTotal:u,poc:c,vaFrom:p,vaTo:h}}function wN(t,e,n,r){let i=vN(t,e,n);if(!i)return null;if(!r||t.length<1)return{profile:i,developingPoc:[],developingVaHigh:[],developingVaLow:[]};let{min:s,rowH:a}=i,o=i.rows.length,l=Array.from({length:o},(h,d)=>({price:s+d*a,up:0,down:0})),c=[],u=[],p=[];for(let h of t){up(l,s,a,h);let d=hp(l);if(!d)continue;let{poc:f}=d,{vaFrom:m,vaTo:_}=cp(l,f,n);c.push({time:h.time,price:l[f].price+a/2}),u.push({time:h.time,price:l[_].price+a}),p.push({time:h.time,price:l[m].price})}return{profile:i,developingPoc:c,developingVaHigh:u,developingVaLow:p}}var SN=class extends xe{constructor(t){super(t),this.type="fixedrangevp",this.cachedRange=null,this.frvp||(this.frvp=Xh())}anchorSchema(){return{min:2,max:2,slots:[{role:"start",free:"x"},{role:"end",free:"x"}]}}barsInSpan(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=Math.min(e.time,n.time),i=Math.max(e.time,n.time),s=t.barsInRange?.(r,i)??null;return!s||s.length<1?null:s.map(a=>({time:a.time,open:a.open,high:a.high,low:a.low,close:a.close,volume:a.volume??0}))}compute(t){let e=this.barsInSpan(t);if(!e)return null;let n=this.frvp,r=n.showDevelopingPoc||n.showDevelopingVa,i=wN(e,n.rows,n.valueAreaPct/100,r);if(i){let{profile:s}=i;this.cachedRange={min:s.min,max:s.min+s.rowH*s.rows.length}}return i}layout(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=this.compute(t);if(!r)return null;let{profile:i}=r,s=Math.min(e.time,n.time),a=Math.max(e.time,n.time),o=t.xOf(s),l=t.xOf(a),c=Math.abs(l-o),u=Math.max(1,Math.min(100,Math.max(0,this.frvp.widthPct))/100*c),p=this.frvp.anchor==="left",h=p?Math.min(o,l):Math.max(o,l),d=p?1:-1,f=[];for(let v=0;v<=i.rows.length;v+=1){let E=t.yOf(i.min+v*i.rowH,this.paneId);if(E==null)return null;f.push(E)}let m=v=>t.yOf(v,this.paneId),_=i.rows[i.vaTo].price+i.rowH,x=i.rows[i.vaFrom].price,w=i.rows[i.poc].price+i.rowH/2,S=v=>{let E=[];for(let C of v){let I=m(C.price);I!=null&&E.push([t.xOf(C.time),I])}return E};return{x0:Math.min(o,l),x1:Math.max(o,l),anchorX:h,maxW:u,grow:d,profile:i,yEdges:f,vahY:m(_),valY:m(x),pocY:m(w),developingPoc:S(r.developingPoc),developingVaHigh:S(r.developingVaHigh),developingVaLow:S(r.developingVaLow)}}hitTest(t,e,n,r){let i=this.layout(n);if(!i)return!1;let s=i.grow===1?i.anchorX:i.anchorX-i.maxW,a=i.grow===1?i.anchorX+i.maxW:i.anchorX,o=Math.min(i.yEdges[0],i.yEdges[i.yEdges.length-1]),l=Math.max(i.yEdges[0],i.yEdges[i.yEdges.length-1]);if(mi(t,e,[[s,o],[a,o],[a,l],[s,l]]))return!0;let c=[[i.x0,i.vahY],[i.x0,i.valY],[i.x0,i.pocY]];for(let[,u]of c)if(u!=null&&We(t,e,i.x0,u,i.x1,u)<=r)return!0;for(let u of[i.developingPoc,i.developingVaHigh,i.developingVaLow])for(let p=1;p<u.length;p+=1)if(We(t,e,u[p-1][0],u[p-1][1],u[p][0],u[p][1])<=r)return!0;return!1}handlePoints(t){let e=this.layout(t);if(e&&e.pocY!=null)return[[e.x0,e.pocY],[e.x1,e.pocY]];let n=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return[];n.push([t.xOf(r.time),i])}return n}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.layout(t);if(!e)return null;let n=Math.min(e.x0,e.grow===1?e.anchorX:e.anchorX-e.maxW),r=Math.max(e.x1,e.grow===1?e.anchorX+e.maxW:e.anchorX),i=Math.min(e.yEdges[0],e.yEdges[e.yEdges.length-1]),s=Math.max(e.yEdges[0],e.yEdges[e.yEdges.length-1]);return{x:n,y:i,w:r-n,h:s-i}}priceRange(){if(this.cachedRange)return this.cachedRange;let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"frvp.rows",label:"Rows",kind:"number",min:1,max:500,step:1,group:"behavior"},{path:"frvp.valueAreaPct",label:"Value Area",kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.widthPct",label:"Width %",kind:"number",min:0,max:100,step:1,group:"behavior"},{path:"frvp.anchor",label:"Anchor",kind:"select",options:[{value:"right",label:"Right"},{value:"left",label:"Left"}],group:"behavior"},{path:"frvp.upColor",label:"Up Volume",kind:"color",group:"fill"},{path:"frvp.downColor",label:"Down Volume",kind:"color",group:"fill"},{path:"frvp.vaUpColor",label:"Value Area Up",kind:"color",group:"fill"},{path:"frvp.vaDownColor",label:"Value Area Down",kind:"color",group:"fill"},{path:"frvp.showVah",label:"VAH",kind:"boolean",group:"line"},{path:"frvp.vahColor",label:"VAH color",kind:"color",group:"line"},{path:"frvp.vahStyle",label:"VAH style",kind:"lineStyle",options:Pr,group:"line"},{path:"frvp.showVal",label:"VAL",kind:"boolean",group:"line"},{path:"frvp.valColor",label:"VAL color",kind:"color",group:"line"},{path:"frvp.valStyle",label:"VAL style",kind:"lineStyle",options:Pr,group:"line"},{path:"frvp.showPoc",label:"POC",kind:"boolean",group:"line"},{path:"frvp.pocColor",label:"POC color",kind:"color",group:"line"},{path:"frvp.pocStyle",label:"POC style",kind:"lineStyle",options:Pr,group:"line"},{path:"frvp.showDevelopingPoc",label:"Developing POC",kind:"boolean",group:"line"},{path:"frvp.developingPocColor",label:"Developing POC color",kind:"color",group:"line"},{path:"frvp.developingPocStyle",label:"Developing POC style",kind:"lineStyle",options:Pr,group:"line"},{path:"frvp.showDevelopingVa",label:"Developing VA",kind:"boolean",group:"line"},{path:"frvp.developingVaColor",label:"Developing VA color",kind:"color",group:"line"},{path:"frvp.developingVaStyle",label:"Developing VA style",kind:"lineStyle",options:Pr,group:"line"}]}}writeProps(){return{...this.frvp}}readProps(t){this.frvp={...Xh(),...t}}},EN=class extends Gt{constructor(){super(...arguments),this.type="pitchfork"}anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=f=>{let m=t.yOf(f.price,this.paneId);return m==null?null:[t.xOf(f.time),m]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(a);if(!o)return null;let l=(s[0]+o[0])/2,c=(s[1]+o[1])/2,u=l-i[0],p=c-i[1],h=t.width,d=t.height;return{segments:[it(i[0],i[1],l,c,"right",h,d),it(s[0],s[1],s[0]+u,s[1]+p,"right",h,d),it(o[0],o[1],o[0]+u,o[1]+p,"right",h,d),[s[0],s[1],o[0],o[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...se]}}},pp=class extends Gt{anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=m=>{let _=t.yOf(m.price,this.paneId);return _==null?null:[t.xOf(m.time),_]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(this.medianStart(e,n,a)),l=r(a);if(!o||!l)return null;let c=(s[0]+l[0])/2,u=(s[1]+l[1])/2,p=c-o[0],h=u-o[1],d=t.width,f=t.height;return{segments:[it(o[0],o[1],c,u,"right",d,f),it(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),it(l[0],l[1],l[0]+p,l[1]+h,"right",d,f),[s[0],s[1],l[0],l[1]],[i[0],i[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...se]}}},NN=class extends pp{constructor(){super(...arguments),this.type="schiffpitchfork"}medianStart(t,e){return{time:t.time,price:(t.price+e.price)/2}}},CN=class extends pp{constructor(){super(...arguments),this.type="modifiedschiffpitchfork"}medianStart(t,e){return{time:(t.time+e.time)/2,price:(t.price+e.price)/2}}},IN=class extends Gt{constructor(){super(...arguments),this.type="insidepitchfork"}anchorSchema(){return{min:3,max:3,slots:[{role:"pivot",free:"both"},{role:"upper",free:"both"},{role:"lower",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=m=>{let _=t.yOf(m.price,this.paneId);return _==null?null:[t.xOf(m.time),_]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r({time:(e.time+n.time)/2,price:(e.price+n.price)/2}),l=r(a);if(!o||!l)return null;let c=(s[0]+l[0])/2,u=(s[1]+l[1])/2,p=l[0]-o[0],h=l[1]-o[1],d=t.width,f=t.height;return{segments:[it(c,u,c+p,u+h,"right",d,f),it(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),it(l[0],l[1],l[0]+p,l[1]+h,"right",d,f),[s[0],s[1],l[0],l[1]],[o[0],o[1],l[0],l[1]],[i[0],i[1],s[0],s[1]]],fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...se]}}},kN=class extends xe{constructor(){super(...arguments),this.type="arrow"}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}pixels(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:[t.xOf(e.time),r,t.xOf(n.time),i]}hitTest(t,e,n,r){let i=this.pixels(n);return i!=null&&We(t,e,i[0],i[1],i[2],i[3])<=r}handlePoints(t){let e=this.pixels(t);return e?[[e[0],e[1]],[e[2],e[3]]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.pixels(t);return e?{x:Math.min(e[0],e[2]),y:Math.min(e[1],e[3]),w:Math.abs(e[2]-e[0]),h:Math.abs(e[3]-e[1])}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,{path:"style.arrowRight",label:"Head (end)",kind:"boolean",group:"line"},{path:"style.arrowLeft",label:"Head (start)",kind:"boolean",group:"line"},...se]}}},Zh=48,AN=class extends xe{constructor(){super(...arguments),this.type="ellipse"}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}oval(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:(s+a)/2,cy:(r+i)/2,rx:Math.abs(a-s)/2,ry:Math.abs(i-r)/2}}perimeter(t){let e=[];for(let n=0;n<=Zh;n+=1){let r=n/Zh*Math.PI*2;e.push([t.cx+t.rx*Math.cos(r),t.cy+t.ry*Math.sin(r)])}return e}hitTest(t,e,n,r){let i=this.oval(n);if(!i||i.rx<1||i.ry<1)return!1;let s=((t-i.cx)/i.rx)**2+((e-i.cy)/i.ry)**2;return this.style.fillColor&&s<=1?!0:ml(t,e,this.perimeter(i))<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.oval(t);return e?{x:e.cx-e.rx,y:e.cy-e.ry,w:e.rx*2,h:e.ry*2}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...gt,...se]}}},MN=class extends Gt{constructor(){super(...arguments),this.type="triangle"}anchorSchema(){return{min:3,max:3,slots:[{role:"v1",free:"both"},{role:"v2",free:"both"},{role:"v3",free:"both"}]}}geometry(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=l=>{let c=t.yOf(l.price,this.paneId);return c==null?null:[t.xOf(l.time),c]},i=r(e),s=r(n);if(!i||!s)return null;let a=this.anchors[2];if(!a)return{segments:[[i[0],i[1],s[0],s[1]]],fill:null};let o=r(a);return o?{segments:[[i[0],i[1],s[0],s[1]],[s[0],s[1],o[0],o[1]],[o[0],o[1],i[0],i[1]]],fill:[i,s,o]}:null}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...gt,...se]}}},TN=512,_l=class extends Gt{anchorSchema(){return{min:2,max:TN,slots:[]}}geometry(t){let e=[];for(let r of this.anchors){let i=t.yOf(r.price,this.paneId);if(i==null)return null;e.push([t.xOf(r.time),i])}if(e.length<2)return null;let n=[];for(let r=1;r<e.length;r+=1)n.push([e[r-1][0],e[r-1][1],e[r][0],e[r][1]]);return{segments:n,fill:null}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...se]}}},PN=class extends _l{constructor(){super(...arguments),this.type="polyline"}},dp=class extends _l{placementMode(){return"freehand"}handlePoints(t){return[]}bounds(t){let e=[],n=[];for(let s of this.anchors){let a=t.yOf(s.price,this.paneId);a!=null&&(e.push(t.xOf(s.time)),n.push(a))}if(e.length===0)return null;let r=Math.min(...e),i=Math.min(...n);return{x:r,y:i,w:Math.max(...e)-r,h:Math.max(...n)-i}}},DN=class extends dp{constructor(){super(...arguments),this.type="freehand"}},ON=[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Width",kind:"number",min:4,max:60,step:1,group:"line"}],RN=class extends dp{constructor(){super(...arguments),this.type="highlighter"}schema(){return{fields:ON}}},LN=class extends xe{constructor(){super(...arguments),this.type="circle"}anchorSchema(){return{min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}geom(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:s,cy:r,r:Math.hypot(a-s,i-r)}}hitTest(t,e,n,r){let i=this.geom(n);if(!i||i.r<1)return!1;let s=Math.hypot(t-i.cx,e-i.cy);return this.style.fillColor&&s<=i.r?!0:Math.abs(s-i.r)<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.geom(t);return e?{x:e.cx-e.r,y:e.cy-e.r,w:e.r*2,h:e.r*2}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...gt,...se]}}},FN=class extends Gt{constructor(){super(...arguments),this.type="rotatedrect"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"w",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.px(t,2);if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=n[0]-e[0],s=n[1]-e[1],a=Math.hypot(i,s);if(a<1e-6)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let o=-s/a,l=i/a,c=(r[0]-e[0])*o+(r[1]-e[1])*l,u=o*c,p=l*c,h=e,d=n,f=[n[0]+u,n[1]+p],m=[e[0]+u,e[1]+p];return{segments:[[h[0],h[1],d[0],d[1]],[d[0],d[1],f[0],f[1]],[f[0],f[1],m[0],m[1]],[m[0],m[1],h[0],h[1]]],fill:[h,d,f,m]}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re.map(t=>({...t,label:t.label.replace("Line","Border")})),...gt,...se]}}},VN=class extends _l{constructor(){super(...arguments),this.type="path"}},Qh=40,BN=class extends Gt{constructor(){super(...arguments),this.type="arc"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"apex",free:"both"}]}}pinApex(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];t&&e&&n&&(n.time=(t.time+e.time)/2)}onPlaced(){this.pinApex()}constrainHandleDrag(){this.pinApex()}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.anchors[2];if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=t.yOf(r.price,this.paneId);if(i==null)return null;let s=(e[0]+n[0])/2,a=(e[1]+n[1])/2,o=(n[0]-e[0])/2,l=(n[1]-e[1])/2,c=Math.hypot(o,l);if(c<1e-6)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let u=-l/c,p=o/c,h=(i-a)*p;h<0&&(u=-u,p=-p);let d=Math.abs(h),f=[];for(let _=0;_<=Qh;_+=1){let x=_/Qh*Math.PI,w=Math.cos(x),S=Math.sin(x);f.push([s+w*o+S*d*u,a+w*l+S*d*p])}let m=[];for(let _=1;_<f.length;_+=1)m.push([f[_-1][0],f[_-1][1],f[_][0],f[_][1]]);return m.push([f[f.length-1][0],f[f.length-1][1],f[0][0],f[0][1]]),{segments:m,fill:f}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re.map(t=>({...t,label:t.label.replace("Line","Border")})),...gt,...se]}}},Jh=40,$N=class extends Gt{constructor(){super(...arguments),this.type="curve"}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"control",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}geometry(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return null;let r=this.px(t,2);if(!r||this.anchors.length<3)return{segments:[[e[0],e[1],n[0],n[1]]],fill:null};let i=[];for(let a=0;a<=Jh;a+=1){let o=a/Jh,l=1-o;i.push([l*l*e[0]+2*l*o*r[0]+o*o*n[0],l*l*e[1]+2*l*o*r[1]+o*o*n[1]])}let s=[];for(let a=1;a<i.length;a+=1)s.push([i[a-1][0],i[a-1][1],i[a][0],i[a][1]]);return{segments:s,fill:i}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}schema(){return{fields:[...re,...gt,...se]}}},jN={head:11,headW:9,stemW:3.5,len:22},fp=class extends xe{anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}glyphPoints(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);if(n==null)return null;let r=t.xOf(e.time),{head:i,headW:s,stemW:a,len:o}=jN,l=[[0,0],[-s,i],[-a,i],[-a,o],[a,o],[a,i],[s,i]],c=this.dir(),u=([p,h])=>{switch(c){case"up":return[p,h];case"down":return[p,-h];case"left":return[h,p];default:return[-h,p]}};return l.map(p=>{let[h,d]=u(p);return[r+h,n+d]})}hitTest(t,e,n,r){let i=this.glyphPoints(n);return i!=null&&mi(t,e,i)}handlePoints(t){let e=this.anchors[0];if(!e)return[];let n=t.yOf(e.price,this.paneId);return n==null?[]:[[t.xOf(e.time),n]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.glyphPoints(t);if(!e)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}schema(){return{fields:[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},...se]}}},WN=class extends fp{constructor(){super(...arguments),this.type="arrowmarkup"}dir(){return"up"}},UN=class extends fp{constructor(){super(...arguments),this.type="arrowmarkdown"}dir(){return"down"}},qN=["\\u2605","\\u2606","\\u25CF","\\u25C6","\\u25B2","\\u25BC","\\u27A4","\\u2691","\\u271A","\\u2715","\\u2764","\\u2666"],zN=["small","normal","large","huge"],ep={small:16,normal:22,large:32,huge:44},mp=class extends xe{constructor(t){super(t),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal")}sizePx(){return ep[this.size]??ep.normal}anchorSchema(){return{min:1,max:1,slots:[{role:"p",free:"both"}]}}center(t){let e=this.anchors[0];if(!e)return null;let n=t.yOf(e.price,this.paneId);return n==null?null:[t.xOf(e.time),n]}hitTest(t,e,n,r){let i=this.center(n);if(!i)return!1;let s=this.sizePx()/2+r;return Math.abs(t-i[0])<=s&&Math.abs(e-i[1])<=s}handlePoints(t){let e=this.center(t);return e?[e]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.center(t);if(!e)return null;let n=this.sizePx();return{x:e[0]-n/2,y:e[1]-n/2,w:n,h:n}}priceRange(){let t=this.anchors[0];return t?{min:t.price,max:t.price}:null}schema(){return{fields:[{path:"glyph",label:"Icon",kind:"select",options:qN.map(t=>({value:t,label:t})),group:"line"},{path:"size",label:"Size",kind:"select",options:zN.map(t=>({value:t,label:t})),group:"line"},{path:"style.lineColor",label:"Color",kind:"color",group:"line"},...se]}}writeProps(){return{glyph:this.glyph,size:this.size}}readProps(t){typeof t.glyph=="string"&&(this.glyph=t.glyph),typeof t.size=="string"&&(this.size=t.size)}},HN=class extends mp{constructor(){super(...arguments),this.type="flagmark"}defaultGlyph(){return"\\u2691"}},KN=class extends mp{constructor(){super(...arguments),this.type="iconstamp"}defaultGlyph(){return"\\u2605"}},tp=t=>t==="small"||t==="normal"||t==="large"||t==="huge";function GN(t){if(!t||typeof t!="object")return null;let e=t;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==!1,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var Yt=class extends xe{constructor(t){super(t),this.levels||(this.levels=this.defaultLevels().map(e=>({...e}))),this.numbersSize||(this.numbersSize="small"),this.labelsSize||(this.labelsSize="normal")}fillBands(t){return[]}editableLevels(){return this.levels}anchorSchema(){return{min:2,max:2,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"}]}}hitTest(t,e,n,r){let i=this.entryLines(n);return i!=null&&i.some(s=>We(t,e,s.x1,s.y1,s.x2,s.y2)<=r)}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}schema(){return{fields:re.filter(t=>t.path!=="style.lineColor")}}writeProps(){return{levels:this.levels.map(t=>({...t})),numbersSize:this.numbersSize,labelsSize:this.labelsSize}}readProps(t){if(Array.isArray(t.levels)){let e=t.levels.map(GN).filter(n=>n!=null);e.length&&(this.levels=e)}tp(t.numbersSize)&&(this.numbersSize=t.numbersSize),tp(t.labelsSize)&&(this.labelsSize=t.labelsSize)}},yp=class extends Yt{levelLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=Math.min(r,i),a=Math.max(r,i),o=n.price-e.price,l=[];for(let c of this.levels){if(!c.enabled)continue;let u=e.price+c.ratio*o,p=t.yOf(u,this.paneId);p!=null&&l.push({ratio:c.ratio,color:c.color,label:c.label,price:u,x1:s,x2:a,y:p})}return l}entryLines(t){let e=this.levelLines(t);return e?e.map(n=>({color:n.color,label:n.label,x1:n.x1,y1:n.y,x2:n.x2,y2:n.y,numberText:`${n.ratio} (${n.price.toFixed(2)})`,numberX:n.x1+4,numberY:n.y-7,numberAlign:"left",labelX:(n.x1+n.x2)/2,labelY:n.y-7})):null}fillBands(t){let e=this.levelLines(t);if(!e)return[];let n=[];for(let r=1;r<e.length;r+=1){let i=e[r-1],s=e[r];n.push({color:s.color,x:i.x1,y:Math.min(i.y,s.y),w:i.x2-i.x1,h:Math.abs(s.y-i.y)})}return n}priceRange(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return null;let n=e.price-t.price,r=this.levels.filter(i=>i.enabled).map(i=>t.price+i.ratio*n);return r.length===0?null:{min:Math.min(...r),max:Math.max(...r)}}},Dr=Zn,Jn=cn,er=cl,Ss="#4caf50",fi=Kt,tr=Qn,Cs="#9c27b0",YN="#e91e63",gp="#26a69a",XN="#ab47bc",ZN="#ef5350",QN="#ffb74d",JN="#38c0fd",_p="#b2b5be",di=[JN,tr,fi,Ss,er,Jn,YN,Cs,Dr,gp,XN,ZN];function xp(t){return di[(t%di.length+di.length)%di.length]}var eC=[[0,Dr],[.125,Jn],[.236,Jn],[.25,Jn],[.382,er],[.5,Ss],[.618,fi],[.75,tr],[.786,tr],[1,Dr],[1.272,tr],[1.382,er],[1.618,Jn],[2,Dr],[2.382,er],[2.618,er],[3,Dr],[4.236,Ss],[6.854,fi],[11.09,tr]];function tC(t,e=0){return eC.find(([n])=>n===t)?.[1]??xp(e)}function _t(t){return t.map((e,n)=>{let r=typeof e=="number"?{ratio:e}:e;return{ratio:r.ratio,color:r.color??tC(r.ratio,n),enabled:r.enabled!==!1,...r.label?{label:r.label}:{}}})}function nC(t,e=t){return Array.from({length:t},(n,r)=>({ratio:r+1,color:xp(r),enabled:r<e,label:String(r+1)}))}var rC=_t([0,.236,.382,.5,.618,.786,1]),iC=class extends yp{constructor(){super(...arguments),this.type="fibretracement"}defaultLevels(){return rC}},sC=_t([0,.382,.618,1,1.272,1.618,{ratio:2.618,color:Cs}]),aC=class extends yp{constructor(){super(...arguments),this.type="fibextension"}defaultLevels(){return sC}},oC=_t([0,.382,.5,.618,1,1.618,{ratio:2.618,color:Cs}]),lC=class extends Yt{constructor(){super(...arguments),this.type="fibextensiontrend"}anchorSchema(){return{min:3,max:3,slots:[{role:"a",free:"both"},{role:"b",free:"both"},{role:"c",free:"both"}]}}defaultLevels(){return oC}entryLines(t){let e=this.anchors[0],n=this.anchors[1],r=this.anchors[2];if(!e||!n||!r)return null;let i=n.price-e.price,s=[t.xOf(e.time),t.xOf(n.time),t.xOf(r.time)],a=Math.min(...s),o=Math.max(...s),l=[];for(let c of this.levels){if(!c.enabled)continue;let u=r.price+c.ratio*i,p=t.yOf(u,this.paneId);p!=null&&l.push({color:c.color,label:c.label,x1:a,y1:p,x2:o,y2:p,numberText:`${c.ratio} (${u.toFixed(2)})`,numberX:a+4,numberY:p-7,numberAlign:"left",labelX:(a+o)/2,labelY:p-7})}return l}priceRange(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];if(!t||!e||!n)return null;let r=e.price-t.price,i=this.levels.filter(s=>s.enabled).map(s=>n.price+s.ratio*r);return i.push(t.price,e.price,n.price),{min:Math.min(...i),max:Math.max(...i)}}},cC=_t([.236,.382,.5,.618,.786,1]),uC=class extends Yt{constructor(){super(...arguments),this.type="fibfan"}defaultLevels(){return cC}fanLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.yOf(e.price,this.paneId);if(i==null)return null;let s=t.xOf(n.time),a=n.price-e.price,o=[];for(let l of this.levels){if(!l.enabled)continue;let c=t.yOf(e.price+l.ratio*a,this.paneId);if(c==null)continue;let[u,p,h,d]=it(r,i,s,c,"right",t.width,t.height);o.push({ratio:l.ratio,color:l.color,label:l.label,x1:u,y1:p,x2:h,y2:d,labelX:s+5,labelY:c})}return o}entryLines(t){let e=this.fanLines(t);return e?e.map(n=>({color:n.color,label:n.label,x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2,numberText:String(n.ratio),numberX:n.labelX,numberY:n.labelY,numberAlign:"left",labelX:n.labelX,labelY:n.labelY+13})):null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},hC=[0,1,2,3,5,8,13,21,34].map(t=>({ratio:t,color:L,enabled:!0})),pC=class extends Yt{constructor(){super(...arguments),this.type="fibtimezones"}defaultLevels(){return hC}zoneLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=n.time-e.time;if(Math.abs(r)<1e-9)return null;let i=[];for(let s of this.levels)s.enabled&&i.push({n:s.ratio,color:s.color,label:s.label,x:t.xOf(e.time+s.ratio*r)});return i}entryLines(t){let e=this.zoneLines(t);if(!e)return null;let n=t.height;return e.map(r=>({color:r.color,label:r.label,x1:r.x,y1:0,x2:r.x,y2:n,numberText:String(r.n),numberX:r.x,numberY:9,numberAlign:"center",labelX:r.x,labelY:24}))}priceRange(){return null}timeExtent(){return null}},dC=_t([0,.236,.382,.5,.618,.786,1,1.618,2.618]),fC=class extends Yt{constructor(){super(...arguments),this.type="fibchannel"}defaultLevels(){return dC}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"offset",free:"both"}]}}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=0,l=0,c=this.anchors[2];if(c){let p=t.yOf(c.price,this.paneId);if(p==null)return null;o=t.xOf(c.time)-s,l=p-r}let u=[];for(let p of this.levels){if(!p.enabled)continue;let h=p.ratio*o,d=p.ratio*l,f=a+h,m=i+d;u.push({color:p.color,label:p.label,x1:s+h,y1:r+d,x2:f,y2:m,numberText:String(p.ratio),numberX:f+5,numberY:m,numberAlign:"left",labelX:f+5,labelY:m+13})}return u}priceRange(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[2];if(!t||!e)return null;let r=n?n.price-t.price:0,i=1/0,s=-1/0;for(let a of this.levels)if(a.enabled)for(let o of[t.price,e.price]){let l=o+a.ratio*r;l<i&&(i=l),l>s&&(s=l)}return i<=s?{min:i,max:s}:null}},mC=_t([0,.236,.382,.5,.618,.786,1]),yC=class extends Yt{constructor(){super(...arguments),this.type="fibspeedfan"}defaultLevels(){return mC}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),o=t.xOf(n.time)-s,l=i-r,c=o>=0?"right":"left",u=t.width,p=t.height,h=[];for(let d of this.levels){if(!d.enabled)continue;let f=s+o,m=r+l*d.ratio,_=it(s,r,f,m,c,u,p);if(h.push({color:d.color,label:d.label,x1:_[0],y1:_[1],x2:_[2],y2:_[3],numberText:String(d.ratio),numberX:c==="right"?f+5:f-5,numberY:m,numberAlign:c==="right"?"left":"right",labelX:f,labelY:m}),d.ratio===1)continue;let x=s+o*d.ratio,w=r+l,S=it(s,r,x,w,c,u,p);h.push({color:d.color,label:d.label,x1:S[0],y1:S[1],x2:S[2],y2:S[3],numberText:String(d.ratio),numberX:x,numberY:w+(l>=0?12:-12),numberAlign:"center",labelX:x,labelY:w+12})}return h}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},gC=_t([0,.382,{ratio:.5,enabled:!1},.618,1,1.382,1.618,2,2.382,2.618,3]),_C=class extends Yt{constructor(){super(...arguments),this.type="trendfibtime"}defaultLevels(){return gC}anchorSchema(){return{min:3,max:3,slots:[{role:"p1",free:"both"},{role:"p2",free:"both"},{role:"p3",free:"both"}]}}entryLines(t){let e=this.anchors[0],n=this.anchors[1],r=this.anchors[2];if(!e||!n||!r)return null;let i=n.time-e.time;if(Math.abs(i)<1e-9)return null;let s=t.height,a=[];for(let o of this.levels){if(!o.enabled)continue;let l=t.xOf(r.time+o.ratio*i);a.push({color:o.color,label:o.label,x1:l,y1:0,x2:l,y2:s,numberText:String(o.ratio),numberX:l,numberY:9,numberAlign:"center",labelX:l,labelY:24})}return a}priceRange(){return null}timeExtent(){return null}};function xC(t,e,n){if(n-e>=Math.PI*2-.001)return!0;let r=t-e,i=Math.PI*2;for(;r<0;)r+=i;for(;r>=i;)r-=i;return r<=n-e+1e-6}var xl=class extends Yt{boundingLines(t){return[]}entryLines(t){return[]}hitTest(t,e,n,r){let i=this.radial(n);if(i){let s=Math.hypot(t-i.cx,e-i.cy),a=Math.atan2(e-i.cy,t-i.cx);if(xC(a,i.a0,i.a1)){for(let o of this.levels)if(o.enabled&&Math.abs(s-i.R0*o.ratio)<=r)return!0}}return this.boundingLines(n).some(s=>We(t,e,s[0],s[1],s[2],s[3])<=r)}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}},bC=_t([.236,.382,.5,.618,.786,1,1.618,2.618]),vC=class extends xl{constructor(){super(...arguments),this.type="fibcircles"}defaultLevels(){return bC}radial(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{cx:s,cy:r,R0:Math.hypot(a-s,i-r),a0:0,a1:Math.PI*2}}},wC=_t([.236,.382,.5,.618,.786,1,1.618,2.618]),SC=class extends xl{constructor(){super(...arguments),this.type="fibarcs"}defaultLevels(){return wC}pts(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{cx:t.xOf(e.time),cy:r,ex:t.xOf(n.time),ey:i}}radial(t){let e=this.pts(t);if(!e)return null;let n=Math.hypot(e.ex-e.cx,e.ey-e.cy),r=Math.atan2(e.ey-e.cy,e.ex-e.cx);return{cx:e.cx,cy:e.cy,R0:n,a0:r-Math.PI/2,a1:r+Math.PI/2}}boundingLines(t){let e=this.pts(t);return e?[[e.cx,e.cy,e.ex,e.ey]]:[]}},EC=_t([.236,.382,.5,.618,.786,1]),NC=class extends xl{constructor(){super(...arguments),this.type="fibwedge"}defaultLevels(){return EC}anchorSchema(){return{min:3,max:3,slots:[{role:"apex",free:"both"},{role:"radius",free:"both"},{role:"angle",free:"both"}]}}px(t,e){let n=this.anchors[e];if(!n)return null;let r=t.yOf(n.price,this.paneId);return r==null?null:[t.xOf(n.time),r]}radial(t){let e=this.px(t,0),n=this.px(t,1),r=this.px(t,2);if(!e||!n||!r)return null;let i=Math.hypot(n[0]-e[0],n[1]-e[1]);if(i<1)return null;let s=Math.atan2(n[1]-e[1],n[0]-e[0]),a=Math.atan2(r[1]-e[1],r[0]-e[0]),o=Math.min(s,a),l=Math.max(s,a);return l-o>Math.PI&&([o,l]=[l,o+Math.PI*2]),{cx:e[0],cy:e[1],R0:i,a0:o,a1:l}}boundingLines(t){let e=this.px(t,0),n=this.px(t,1);if(!e||!n)return[];let r=[[e[0],e[1],n[0],n[1]]],i=this.px(t,2);if(i){let s=Math.hypot(n[0]-e[0],n[1]-e[1]),a=Math.hypot(i[0]-e[0],i[1]-e[1]);a>1e-6&&r.push([e[0],e[1],e[0]+(i[0]-e[0])/a*s,e[1]+(i[1]-e[1])/a*s])}return r}},CC=1.6180339887,np=Math.log(CC)/(Math.PI/2),IC=Math.PI/64,kC=Math.PI,AC=.5,MC=class extends xe{constructor(){super(...arguments),this.type="fibspiral"}anchorSchema(){return{min:2,max:2,slots:[{role:"center",free:"both"},{role:"edge",free:"both"}]}}spiralPoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=Math.hypot(a-s,i-r);if(o<1)return null;let l=Math.atan2(i-r,a-s),c=Math.max(Math.log(AC/o)/np,-8*Math.PI*2),u=[];for(let p=c;p<=kC;p+=IC){let h=o*Math.exp(np*p),d=l+p;u.push([s+h*Math.cos(d),r+h*Math.sin(d)])}return u}hitTest(t,e,n,r){let i=this.spiralPoints(n);return i!=null&&i.length>=2&&ml(t,e,i)<=r}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length<2)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,...se]}}},TC=_t([{ratio:.125,color:Jn,label:"1/8"},{ratio:.25,color:er,label:"1/4"},{ratio:.333,color:QN,label:"1/3"},{ratio:.5,color:Ss,label:"1/2"},{ratio:1,color:_p,label:"1/1"},{ratio:2,color:fi,label:"2/1"},{ratio:3,color:tr,label:"3/1"},{ratio:4,color:gp,label:"4/1"},{ratio:8,color:Cs,label:"8/1"}]),PC=class extends Yt{constructor(){super(...arguments),this.type="gannfan"}defaultLevels(){return TC}entryLines(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.yOf(e.price,this.paneId);if(i==null)return null;let s=t.xOf(n.time),a=n.price-e.price,o=[];for(let l of this.levels){if(!l.enabled)continue;let c=t.yOf(e.price+a*l.ratio,this.paneId);if(c==null)continue;let[u,p,h,d]=it(r,i,s,c,"right",t.width,t.height);o.push({color:l.color,x1:u,y1:p,x2:h,y2:d,numberText:l.label??String(l.ratio),numberX:s+5,numberY:c,numberAlign:"left",labelX:s+5,labelY:c})}return o}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},DC=_t([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),OC=class extends Yt{constructor(){super(...arguments),this.type="gannbox"}defaultLevels(){return DC}corners(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.xOf(e.time),i=t.xOf(n.time),s=t.yOf(e.price,this.paneId),a=t.yOf(n.price,this.paneId);return s==null||a==null?null:{c1:e,c2:n,left:Math.min(r,i),right:Math.max(r,i),top:Math.min(s,a),bot:Math.max(s,a)}}entryLines(t){let e=this.corners(t);if(!e)return null;let{c1:n,c2:r,left:i,right:s,top:a,bot:o}=e,l=[];for(let u of this.levels){if(!u.enabled)continue;let p=t.yOf(n.price+u.ratio*(r.price-n.price),this.paneId);p!=null&&l.push({color:u.color,x1:i,y1:p,x2:s,y2:p,numberText:u.label??String(u.ratio),numberX:i-5,numberY:p,numberAlign:"right",labelX:i,labelY:p});let h=t.xOf(n.time+u.ratio*(r.time-n.time));l.push({color:u.color,x1:h,y1:a,x2:h,y2:o,numberText:"",numberX:h,numberY:a,numberAlign:"center",labelX:h,labelY:a})}let c=this.levels.find(u=>u.ratio===1)?.color??Dr;return l.push({color:c,x1:i,y1:a,x2:s,y2:o,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),l.push({color:c,x1:i,y1:o,x2:s,y2:a,numberText:"",numberX:0,numberY:0,numberAlign:"left",labelX:0,labelY:0}),l}hitTest(t,e,n,r){let i=this.corners(n);return i!=null&&Sn(t,e,i.left,i.top,i.right,i.bot,r)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}},RC=_t([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),LC=[{label:"3x1",x:3,y:1,color:Jn},{label:"2x1",x:2,y:1,color:er},{label:"1x1",x:1,y:1,color:_p},{label:"1x2",x:1,y:2,color:fi},{label:"1x3",x:1,y:3,color:tr}];var FC=class extends Yt{constructor(){super(...arguments),this.type="gannsquare"}defaultLevels(){return RC}box(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time);return{ox:s,oy:r,bx:a-s,py:i-r,left:Math.min(s,a),top:Math.min(r,i),right:Math.max(s,a),bot:Math.max(r,i)}}arcGeom(t){let e=this.box(t);return e?{ox:e.ox,oy:e.oy,bx:e.bx,py:e.py}:null}entryLines(t){let e=this.box(t);if(!e)return null;let n=this.anchors[0],r=this.anchors[1],i=[];for(let s of this.levels){if(!s.enabled)continue;let a=t.yOf(n.price+s.ratio*(r.price-n.price),this.paneId);a!=null&&i.push({color:s.color,x1:e.left,y1:a,x2:e.right,y2:a,numberText:s.label??String(s.ratio),numberX:e.left-5,numberY:a,numberAlign:"right",labelX:e.left,labelY:a});let o=t.xOf(n.time+s.ratio*(r.time-n.time));i.push({color:s.color,x1:o,y1:e.top,x2:o,y2:e.bot,numberText:"",numberX:o,numberY:e.top,numberAlign:"center",labelX:o,labelY:e.top})}for(let s of LC){let a,o;s.x>s.y?(a=e.ox+e.bx,o=e.oy+s.y/s.x*e.py):(o=e.oy+e.py,a=e.ox+s.x/s.y*e.bx),i.push({color:s.color,x1:e.ox,y1:e.oy,x2:a,y2:o,numberText:s.label,numberX:a+4,numberY:o,numberAlign:"left",labelX:a+4,labelY:o})}return i}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Sn(t,e,i.left,i.top,i.right,i.bot,r)}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}};var VC=24,BC=.75;function $C(t,e){if(!Number.isInteger(t)||!Number.isInteger(e)||e<=0)return!1;let n=t*t-1;return e%2===1?n%e===0:e%8===0?n%e!==0?!1:n/e%2!==0:!1}function jC(t){let e=[];for(let n=0;n<t;n+=1)$C(n,t)&&e.push(n);return e}var WC=class extends xe{constructor(t){super(t),this.type="dedekind",this.maxCurvature===void 0&&(this.maxCurvature=VC)}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}box(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=Math.min(t.xOf(e.time),t.xOf(n.time)),a=Math.max(t.xOf(e.time),t.xOf(n.time)),o=Math.min(r,i),l=Math.max(r,i),c=a-s,u=l-o;if(c<1||u<1)return null;let p=u,h=c/p;return{left:s,right:a,top:o,bot:l,unitPx:p,x0:0,realSpan:h}}geodesics(t){let e=this.box(t);if(!e)return null;let{left:n,top:r,bot:i,unitPx:s,x0:a,realSpan:o}=e,l=Math.max(1,Math.min(64,Math.round(this.maxCurvature))),c=a-1/l,u=a+o+1/l,p=n+o*s,h=[],d=Math.floor(c*2),f=Math.ceil(u*2);for(let m=d;m<=f;m+=1){if(m%2===0)continue;let _=n+(m/2-a)*s;_<n-.5||_>p+.5||h.push({kind:"vline",x:_,y0:i,y1:r})}for(let m=1;m<=l;m+=1){let _=1/m,x=_*s;if(x<BC)continue;let w=jC(m);if(w.length===0)continue;let S=Math.floor(c)-1,v=Math.ceil(u)+1;for(let E=S;E<=v;E+=1)for(let C of w){let I=C/m+E;if(I+_<c||I-_>u)continue;let F=n+(I-a)*s;F+x<n-1||F-x>p+1||h.push({kind:"arc",cx:F,cy:i,r:x})}}return h}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&Sn(t,e,i.left,i.top,i.right,i.bot,r)}handlePoints(t){let e=this.box(t);return e?[[e.left,e.top],[e.right,e.bot]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.box(t);return e?{x:e.left,y:e.top,w:e.right-e.left,h:e.bot-e.top}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[...re,{path:"maxCurvature",label:"Max curvature",kind:"number",min:4,max:64,step:4,group:"behavior"},...se]}}writeProps(){return{maxCurvature:this.maxCurvature}}readProps(t){typeof t.maxCurvature=="number"&&Number.isFinite(t.maxCurvature)&&(this.maxCurvature=Math.max(1,Math.min(64,Math.round(t.maxCurvature))))}};var Is=6,UC=2;function bp(t=Is){return[...nC(di.length,t)]}function qC(t){if(!t||typeof t!="object")return null;let e=t;return typeof e.ratio!="number"||typeof e.color!="string"?null:{ratio:e.ratio,color:e.color,enabled:e.enabled!==!1,...typeof e.label=="string"&&e.label?{label:e.label}:{}}}var ks={path:"showRatios",label:"Show ratios",kind:"boolean",group:"behavior"},As=class extends xe{constructor(t){super(t),this.waveCount===void 0&&(this.waveCount=Is),this.showRatios===void 0&&(this.showRatios=!0);let e=Array.isArray(t.props?.levels);this.levels||(this.levels=this.defaultLevels().map(n=>({...n}))),!e&&this.shouldSyncWaveCount()&&this.syncLevelsToWaveCount()}shouldSyncWaveCount(){return!0}syncLevelsToWaveCount(){let t=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=t;for(let e=0;e<this.levels.length;e+=1)this.levels[e].enabled=e<t}editableLevels(){return this.levels}anchorSchema(){return{min:2,max:2,slots:[{role:"d1",free:"both"},{role:"d2",free:"both"}]}}geom(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);if(r==null||i==null)return null;let s=t.xOf(e.time),a=t.xOf(n.time),o=(s+a)/2,l=(r+i)/2,c=Math.hypot(a-s,i-r)/2;if(c<1)return null;let u=a-s,p=i-r,h=Math.hypot(u,p);h<1e-9?(u=1,p=0):(u/=h,p/=h);let d=this.levels.filter(E=>E.enabled&&E.ratio>0).slice().sort((E,C)=>E.ratio-C.ratio);if(d.length===0)return null;let f=Math.max(1,this.machNumber()),m=[];for(let E of d){let C=E.ratio*c;m.push({cx:o+f*(C-c)*u,cy:l+f*(C-c)*p,r:C,color:E.color,ratio:E.ratio})}let _=o-f*c*u,x=l-f*c*p,w=m[m.length-1].r,S=f*w+2*c,v=[];if(f<=1+1e-9){let E=-p,C=u;v.push([_-E*S,x-C*S,_+E*S,x+C*S])}else{let E=Math.asin(1/f),C=Math.cos(E),I=Math.sin(E),F=(D,M,W)=>[D*C-M*W*I,D*W*I+M*C],[$,j]=F(u,p,1),[A,ue]=F(u,p,-1);v.push([_,x,_+$*S,x+j*S]),v.push([_,x,_+A*S,x+ue*S])}return{c0x:o,c0y:l,R:c,fx:u,fy:p,noseX:_,noseY:x,circles:m,rays:v}}hitTest(t,e,n,r){let i=this.geom(n);if(!i)return!1;for(let s of i.circles)if(Math.abs(Math.hypot(t-s.cx,e-s.cy)-s.r)<=r)return!0;return i.rays.some(s=>We(t,e,s[0],s[1],s[2],s[3])<=r)}handlePoints(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return[];let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?[]:[[t.xOf(e.time),r],[t.xOf(n.time),i]]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.geom(t);if(!e)return null;let n=e.noseX,r=e.noseX,i=e.noseY,s=e.noseY;for(let a of e.circles)n=Math.min(n,a.cx-a.r),r=Math.max(r,a.cx+a.r),i=Math.min(i,a.cy-a.r),s=Math.max(s,a.cy+a.r);for(let a of e.rays)n=Math.min(n,a[0],a[2]),r=Math.max(r,a[0],a[2]),i=Math.min(i,a[1],a[3]),s=Math.max(s,a[1],a[3]);return{x:n,y:i,w:r-n,h:s-i}}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}applySettings(t){if(super.applySettings(t),Object.prototype.hasOwnProperty.call(t,"waveCount")&&typeof this.waveCount=="number"){let e=Math.max(1,Math.min(this.levels.length,Math.round(this.waveCount)));this.waveCount=e;for(let n=0;n<this.levels.length;n+=1)this.levels[n].enabled=n<e}}schema(){return{fields:[...re,{path:"waveCount",label:"Waves",kind:"number",min:3,max:12,step:1,group:"behavior"},ks,...se]}}writeProps(){return{waveCount:this.waveCount,showRatios:this.showRatios,levels:this.levels.map(t=>({...t}))}}readProps(t){if(typeof t.waveCount=="number"&&Number.isFinite(t.waveCount)&&(this.waveCount=Math.max(2,Math.min(12,Math.round(t.waveCount)))),typeof t.showRatios=="boolean"&&(this.showRatios=t.showRatios),Array.isArray(t.levels)){let e=t.levels.map(qC).filter(n=>n!=null);e.length&&(this.levels=e)}}},zC=class extends As{constructor(){super(...arguments),this.type="sonic"}defaultLevels(){return bp(Is)}machNumber(){return 1}},HC=class extends As{constructor(t){super(t),this.type="supersonic",this.mach===void 0&&(this.mach=UC)}defaultLevels(){return bp(Is)}machNumber(){return Math.max(1.01,this.mach)}schema(){return{fields:[...re,{path:"mach",label:"Mach number",kind:"number",min:1.5,max:5,step:.5,group:"behavior"},{path:"waveCount",label:"Waves",kind:"number",min:3,max:12,step:1,group:"behavior"},ks,...se]}}writeProps(){return{...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)))}},vp=_t([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),KC=2,GC=class extends As{constructor(){super(...arguments),this.type="goldensonic"}shouldSyncWaveCount(){return!1}defaultLevels(){return vp}machNumber(){return 1}schema(){return{fields:[...re,ks,...se]}}},YC=class extends As{constructor(t){super(t),this.type="goldensupersonic",this.mach===void 0&&(this.mach=KC)}shouldSyncWaveCount(){return!1}defaultLevels(){return vp}machNumber(){return Math.max(1.01,this.mach)}schema(){return{fields:[...re,{path:"mach",label:"Mach number",kind:"number",min:1.5,max:5,step:.5,group:"behavior"},ks,...se]}}writeProps(){return{...super.writeProps(),mach:this.mach}}readProps(t){super.readProps(t),typeof t.mach=="number"&&Number.isFinite(t.mach)&&(this.mach=Math.max(1.01,Math.min(20,t.mach)))}},Or=class extends xe{legRatios(){return!1}fillTriangles(){return[]}necklineIndices(){return null}anchorSchema(){let t=this.vertexLabels().length,e=[];for(let n=0;n<t;n+=1)e.push({role:`p${n}`,free:"both"});return{min:t,max:t,slots:e}}handlePoints(t){let e=[];for(let n of this.anchors){let r=t.yOf(n.price,this.paneId);if(r==null)return[];e.push([t.xOf(n.time),r])}return e}hitTest(t,e,n,r){let i=this.handlePoints(n);return i.length>=2&&ml(t,e,i)<=r}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.handlePoints(t);if(e.length===0)return null;let n=e.map(a=>a[0]),r=e.map(a=>a[1]),i=Math.min(...n),s=Math.min(...r);return{x:i,y:s,w:Math.max(...n)-i,h:Math.max(...r)-s}}priceRange(){if(this.anchors.length===0)return null;let t=this.anchors.map(e=>e.price);return{min:Math.min(...t),max:Math.max(...t)}}patternName(){return null}ratioOk(t){return null}valid(){return null}ratioAt(t){let e=this.anchors[t-2],n=this.anchors[t-1],r=this.anchors[t];if(!e||!n||!r)return null;let i=Math.abs(n.price-e.price);return i<1e-9?null:Math.abs(r.price-n.price)/i}schema(){return{fields:[...re,...this.fillTriangles().length?gt:[]]}}},XC=class extends Or{constructor(){super(...arguments),this.type="xabcd"}vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}},ZC=class extends Or{constructor(){super(...arguments),this.type="abcd"}vertexLabels(){return["A","B","C","D"]}legRatios(){return!0}},QC=class extends Or{constructor(){super(...arguments),this.type="elliottimpulse"}vertexLabels(){return["1","2","3","4","5"]}},JC=class extends Or{constructor(){super(...arguments),this.type="elliottcorrection"}vertexLabels(){return["A","B","C"]}},eI=class extends Or{constructor(){super(...arguments),this.type="headshoulders"}vertexLabels(){return["","LS","","H","","RS",""]}necklineIndices(){return[2,4]}},Rr=class extends Or{vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}legValue(t){let[e,n,r,i,s]=this.anchors;if(!e||!n||!r||!i||!s)return null;let a=(u,p)=>Math.abs(p.price-u.price),o=a(e,n),l=a(n,r),c=a(r,i);switch(t){case"ab":return o<1e-9?null:l/o;case"bc":return l<1e-9?null:c/l;case"cd":return c<1e-9?null:a(i,s)/c;default:return o<1e-9?null:a(n,s)/o}}inBand(t,e){return t!=null&&t>=e.min&&t<=e.max}ratioOk(t){let e=this.ranges();return t===2?this.inBand(this.legValue("ab"),e.ab):t===3?this.inBand(this.legValue("bc"),e.bc):t===4?this.inBand(this.legValue("cd"),e.cd):null}valid(){if(this.anchors.length<5)return null;let t=this.ranges();return this.inBand(this.legValue("ab"),t.ab)&&this.inBand(this.legValue("bc"),t.bc)&&this.inBand(this.legValue("cd"),t.cd)&&this.inBand(this.legValue("ad"),t.ad)}},tI=class extends Rr{constructor(){super(...arguments),this.type="gartley"}patternName(){return"Gartley"}ranges(){return{ab:{min:.55,max:.68},bc:{min:.382,max:.886},cd:{min:1.13,max:1.618},ad:{min:.74,max:.83}}}},nI=class extends Rr{constructor(){super(...arguments),this.type="bat"}patternName(){return"Bat"}ranges(){return{ab:{min:.382,max:.5},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:.84,max:.92}}}},rI=class extends Rr{constructor(){super(...arguments),this.type="butterfly"}patternName(){return"Butterfly"}ranges(){return{ab:{min:.74,max:.83},bc:{min:.382,max:.886},cd:{min:1.618,max:2.618},ad:{min:1.272,max:1.618}}}},iI=class extends Rr{constructor(){super(...arguments),this.type="crab"}patternName(){return"Crab"}ranges(){return{ab:{min:.382,max:.618},bc:{min:.382,max:.886},cd:{min:2.618,max:3.618},ad:{min:1.55,max:1.69}}}},sI=class extends Rr{constructor(){super(...arguments),this.type="shark"}patternName(){return"Shark"}ranges(){return{ab:{min:.382,max:.618},bc:{min:1.13,max:1.618},cd:{min:1.618,max:2.24},ad:{min:.886,max:1.13}}}},aI={min:1.272,max:1.414},oI={min:.74,max:.83},lI=class extends Rr{constructor(){super(...arguments),this.type="cypher"}patternName(){return"Cypher"}ranges(){return{ab:{min:.382,max:.618},bc:{min:0,max:1/0},cd:{min:0,max:1/0},ad:{min:0,max:1/0}}}xcOverXa(){let t=this.anchors[0],e=this.anchors[1],n=this.anchors[3];if(!t||!e||!n)return null;let r=Math.abs(e.price-t.price);return r<1e-9?null:Math.abs(n.price-t.price)/r}cdOverXc(){let t=this.anchors[0],e=this.anchors[3],n=this.anchors[4];if(!t||!e||!n)return null;let r=Math.abs(e.price-t.price);return r<1e-9?null:Math.abs(n.price-e.price)/r}ratioOk(t){return t===2?this.inBand(this.legValue("ab"),this.ranges().ab):null}valid(){return this.anchors.length<5?null:this.inBand(this.legValue("ab"),this.ranges().ab)&&this.inBand(this.xcOverXa(),aI)&&this.inBand(this.cdOverXc(),oI)}};function rp(t){return`${t>=0?"+":""}${t.toFixed(2)}`}function cI(t){let e=Math.abs(t),n=864e5,r=36e5,i=6e4;if(e>=n){let s=Math.floor(e/n),a=Math.round(e%n/r);return a?`${s}d ${a}h`:`${s}d`}if(e>=r){let s=Math.floor(e/r),a=Math.round(e%r/i);return a?`${s}h ${a}m`:`${s}h`}return e>=i?`${Math.round(e/i)}m`:`${Math.round(e/1e3)}s`}var uI=class extends xe{constructor(t){super(t),this.showPrice===void 0&&(this.showPrice=!0),this.showDate===void 0&&(this.showDate=!0)}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}measureLabel(t){let e=[];return this.showPrice&&e.push(this.priceLabel()),this.showDate&&e.push(this.timeLabel(t)),e}isUp(){let t=this.anchors[0],e=this.anchors[1];return t!=null&&e!=null&&e.price>=t.price}priceLabel(){let t=this.anchors[0],e=this.anchors[1];if(!t||!e)return"";let n=e.price-t.price,r=t.price!==0?n/t.price*100:0;return`${rp(n)} (${rp(r)}%)`}timeLabel(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return"";let r=cI(n.time-e.time),i=t.barsBetween?Math.round(t.barsBetween(e.time,n.time)):null;return i!=null?`${i} bars, ${r}`:r}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i!=null&&Sn(t,e,i.x1,i.y1,i.x2,i.y2,r)}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"showPrice",label:"Show price",kind:"boolean",group:"behavior"},{path:"showDate",label:"Show date",kind:"boolean",group:"behavior"},...re.filter(t=>t.path!=="style.lineColor"),{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:fl,group:"text"}]}}writeProps(){return{showPrice:this.showPrice,showDate:this.showDate}}readProps(t){typeof t.showPrice=="boolean"&&(this.showPrice=t.showPrice),typeof t.showDate=="boolean"&&(this.showDate=t.showDate)}},hI=class extends uI{constructor(){super(...arguments),this.type="datepricerange"}},pI=[{value:"long",label:"Long"},{value:"short",label:"Short"}],un=class Rt extends xe{constructor(e){super(e),this.type="position",this.riskPercent===void 0&&(this.riskPercent=Rt.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=Rt.DEFAULT_ACCOUNT_BALANCE),this.showText===void 0&&(this.showText=!0),this.showHeader===void 0&&(this.showHeader=!0),this.showPrices===void 0&&(this.showPrices=!1),this.showLossSize===void 0&&(this.showLossSize=!0),this.showTargetLabel===void 0&&(this.showTargetLabel=!0),this.showStopLabel===void 0&&(this.showStopLabel=!0),this.profitColor===void 0&&(this.profitColor=Rt.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=Rt.DEFAULT_LOSS_COLOR)}directionLabel(){let e=this.prices();return e&&e.target>=e.entry?"LONG":"SHORT"}get direction(){return this.directionLabel()==="LONG"?"long":"short"}set direction(e){let n=this.anchors[0],r=this.anchors[1],i=this.anchors[2];!n||!r||!i||(e==="long"||e==="short")&&e!==this.direction&&(r.price=2*n.price-r.price,i.price=2*n.price-i.price)}get quantity(){return this.positionSize()}set quantity(e){let n=this.prices();if(!n||!Number.isFinite(e)||e<0)return;let r=Math.abs(n.entry-n.stop);r<1e-9||this.accountBalance<=0||(this.riskPercent=e*r/this.accountBalance*100)}get entryPrice(){return this.anchors[0]?.price??0}set entryPrice(e){let n=this.anchors[0];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(0))}get stopPrice(){return this.anchors[1]?.price??0}set stopPrice(e){let n=this.anchors[1];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(1))}get targetPrice(){return this.anchors[2]?.price??0}set targetPrice(e){let n=this.anchors[2];n&&Number.isFinite(e)&&(n.price=e,this.constrainHandleDrag(2))}anchorSchema(){return{min:2,max:2,slots:[{role:"entry",free:"both"},{role:"stop",free:"both"},{role:"target",free:"both"}]}}onPlaced(e){let n=this.anchors[0];if(!n)return;let r=e.xOf(n.time),i=e.yOf(n.price,this.paneId);if(i==null)return;let s=this.anchors[1],a=s?e.yOf(s.price,this.paneId):null,o,l;s&&a!=null&&Math.abs(a-i)>=Rt.MIN_DRAG_PX?(o=a,l=r+Math.max(Math.abs(e.xOf(s.time)-r),Rt.MIN_WIDTH_PX)):(o=i-Rt.DEFAULT_RISK_PX*Rt.DEFAULT_RR,l=r+Rt.DEFAULT_WIDTH_PX);let c=i-(o-i)/Rt.DEFAULT_RR,u=e.pxToPoint(l,i,this.paneId).time;this.anchors=[{time:n.time,price:n.price},{time:u,price:e.pxToPoint(r,c,this.paneId).price},{time:u,price:e.pxToPoint(r,o,this.paneId).price}]}constrainHandleDrag(e){let n=this.anchors[0],r=this.anchors[1],i=this.anchors[2];if(!n||!r||!i)return;let s=Math.sign(r.price-n.price),a=Math.sign(i.price-n.price);s===0||a===0||s!==a||(e===2?r.price=2*n.price-r.price:i.price=2*n.price-i.price)}resolved(){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;if(this.anchors[2])return[e,n,this.anchors[2]];let r={time:n.time,price:e.price-(n.price-e.price)/Rt.DEFAULT_RR};return[e,r,n]}prices(){let e=this.resolved();return e?{entry:e[0].price,stop:e[1].price,target:e[2].price}:null}rr(){let e=this.prices();if(!e)return 0;let n=Math.abs(e.entry-e.stop);return n<1e-9?0:Math.abs(e.target-e.entry)/n}rewardPct(){let e=this.prices();return e&&e.entry!==0?Math.abs(e.target-e.entry)/e.entry*100:0}riskPct(){let e=this.prices();return e&&e.entry!==0?Math.abs(e.entry-e.stop)/e.entry*100:0}dollarLoss(){return Math.max(0,this.accountBalance)*(Math.max(0,this.riskPercent)/100)}positionSize(){let e=this.prices();if(!e)return 0;let n=Math.abs(e.entry-e.stop);return n<1e-9?0:this.dollarLoss()/n}headerLabel(){return`${this.directionLabel()} \\xB7 R:R ${this.rr().toFixed(2)}`}lossSizeLabel(){return`Loss $${fI(this.dollarLoss())} \\xB7 Size ${mI(this.positionSize())}`}targetLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${ip(e.target)}`:"";return`Target +${this.rewardPct().toFixed(2)}%${n}`}stopLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${ip(e.stop)}`:"";return`Stop \\u2212${this.riskPct().toFixed(2)}%${n}`}levelDisplayValue(e,n){let r=this.prices();if(!r)return 0;let i=e==="stop"?r.stop:r.target;return sp(n==="price"?i:Math.abs(i-r.entry))}levelPriceFromDisplay(e,n,r){let i=this.prices();if(!i||n==="price")return r;let s=e==="stop"?i.stop:i.target,a=Math.sign(s-i.entry);return a===0&&(a=(e==="target"?1:-1)*(this.direction==="long"?1:-1)),i.entry+a*Math.abs(r)}box(e){let n=this.handlePoints(e);if(n.length<3)return null;let r=n.map(i=>i[0]);return{x1:Math.min(...r),x2:Math.max(...r),ey:n[0][1],sy:n[1][1],ty:n[2][1]}}layout(e){return this.box(e)}hitTest(e,n,r,i){let s=this.box(r);if(!s)return!1;let a=Math.min(s.ey,s.sy,s.ty),o=Math.max(s.ey,s.sy,s.ty);return Sn(e,n,s.x1,a,s.x2,o,i)}handlePoints(e){let n=this.resolved();if(!n)return[];let r=[];for(let i of n){let s=e.yOf(i.price,this.paneId);if(s==null)return[];r.push([e.xOf(i.time),s])}return r}hitHandle(e,n,r,i){return be(e,n,this.handlePoints(r),i+3)}bounds(e){let n=this.box(e);if(!n)return null;let r=Math.min(n.ey,n.sy,n.ty);return{x:n.x1,y:r,w:n.x2-n.x1,h:Math.max(n.ey,n.sy,n.ty)-r}}priceRange(){let e=this.resolved();if(!e)return null;let n=e.map(r=>r.price);return{min:Math.min(...n),max:Math.max(...n)}}schema(){return{fields:[{path:"riskPercent",label:"Risk %",kind:"number",min:0,max:100,step:.1,group:"behavior"},{path:"accountBalance",label:"Account balance",kind:"number",min:0,max:1e12,step:1,group:"behavior"},{path:"quantity",label:"Position size",kind:"number",group:"behavior"},{path:"direction",label:"Direction",kind:"select",options:pI,group:"behavior"},{path:"entryPrice",label:"Entry price",kind:"number",group:"behavior"},{path:"stopPrice",label:"Stop price",kind:"number",group:"behavior"},{path:"targetPrice",label:"Target price",kind:"number",group:"behavior"},{path:"showText",label:"Show text",kind:"boolean",group:"behavior"},{path:"showHeader",label:"Show direction & ratio",kind:"boolean",group:"behavior"},{path:"showLossSize",label:"Show loss & size",kind:"boolean",group:"behavior"},{path:"showTargetLabel",label:"Show target label",kind:"boolean",group:"behavior"},{path:"showStopLabel",label:"Show stop label",kind:"boolean",group:"behavior"},{path:"showPrices",label:"Show level prices",kind:"boolean",group:"behavior"},{path:"profitColor",label:"Profit zone",kind:"color",group:"fill"},{path:"lossColor",label:"Loss zone",kind:"color",group:"fill"},...re.filter(e=>e.path!=="style.lineColor"),{path:"text.color",label:"Text color",kind:"color",group:"text"},{path:"text.size",label:"Text size",kind:"select",options:fl,group:"text"}]}}writeProps(){return{riskPercent:this.riskPercent,accountBalance:this.accountBalance,showText:this.showText,showHeader:this.showHeader,showPrices:this.showPrices,showLossSize:this.showLossSize,showTargetLabel:this.showTargetLabel,showStopLabel:this.showStopLabel,profitColor:this.profitColor,lossColor:this.lossColor}}readProps(e){typeof e.riskPercent=="number"&&Number.isFinite(e.riskPercent)&&(this.riskPercent=e.riskPercent),typeof e.accountBalance=="number"&&Number.isFinite(e.accountBalance)&&(this.accountBalance=e.accountBalance),typeof e.showText=="boolean"&&(this.showText=e.showText),typeof e.showHeader=="boolean"&&(this.showHeader=e.showHeader),typeof e.showPrices=="boolean"&&(this.showPrices=e.showPrices),typeof e.showLossSize=="boolean"&&(this.showLossSize=e.showLossSize),typeof e.showTargetLabel=="boolean"&&(this.showTargetLabel=e.showTargetLabel),typeof e.showStopLabel=="boolean"&&(this.showStopLabel=e.showStopLabel),typeof e.profitColor=="string"&&(this.profitColor=e.profitColor),typeof e.lossColor=="string"&&(this.lossColor=e.lossColor)}};un.DEFAULT_RR=2;un.MIN_DRAG_PX=6;un.DEFAULT_RISK_PX=64;un.DEFAULT_WIDTH_PX=150;un.MIN_WIDTH_PX=48;un.DEFAULT_RISK_PERCENT=1;un.DEFAULT_ACCOUNT_BALANCE=1e4;un.DEFAULT_PROFIT_COLOR=hl;un.DEFAULT_LOSS_COLOR=pl;var dI=un;function fI(t){if(!Number.isFinite(t))return"0";let e=Math.round(t*100)/100;return Number.isInteger(e)?String(e):e.toFixed(2)}function mI(t){return!Number.isFinite(t)||t===0?"0":t>=100?t.toFixed(2):t>=1?t.toFixed(4).replace(/\\.?0+$/,""):t.toPrecision(4).replace(/\\.?0+$/,"")}function ip(t){return Number.isFinite(t)?Math.abs(t)>=1?t.toFixed(2):t.toPrecision(4).replace(/\\.?0+$/,""):"0"}function sp(t){return Math.round(t*1e8)/1e8}var yI=[{value:"auto",label:"Auto",ms:0},{value:"1",label:"1m",ms:6e4},{value:"5",label:"5m",ms:3e5},{value:"15",label:"15m",ms:9e5},{value:"30",label:"30m",ms:18e5},{value:"60",label:"1h",ms:36e5},{value:"240",label:"4h",ms:144e5},{value:"D",label:"1D",ms:864e5}];function ap(){return{timeframe:"auto",upColor:"",downColor:""}}var gI=class extends xe{constructor(t){super(t),this.type="magnifier",this.chipRect=null,this.magnifier||(this.magnifier=ap())}anchorSchema(){return{min:2,max:2,slots:[{role:"c1",free:"both"},{role:"c2",free:"both"}]}}placementMode(){return"drag"}rect(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return null;let r=t.yOf(e.price,this.paneId),i=t.yOf(n.price,this.paneId);return r==null||i==null?null:{x1:t.xOf(e.time),y1:r,x2:t.xOf(n.time),y2:i}}hitTest(t,e,n,r){let i=this.rect(n);return i?Sn(t,e,i.x1,i.y1,i.x2,i.y2)?!0:[[i.x1,i.y1,i.x2,i.y1],[i.x2,i.y1,i.x2,i.y2],[i.x2,i.y2,i.x1,i.y2],[i.x1,i.y2,i.x1,i.y1]].some(a=>We(t,e,a[0],a[1],a[2],a[3])<=r):!1}handlePoints(t){let e=this.rect(t);return e?[[e.x1,e.y1],[e.x2,e.y2]]:[]}hitHandle(t,e,n,r){return be(t,e,this.handlePoints(n),r+3)}bounds(t){let e=this.rect(t);return e?{x:Math.min(e.x1,e.x2),y:Math.min(e.y1,e.y2),w:Math.abs(e.x2-e.x1),h:Math.abs(e.y2-e.y1)}:null}priceRange(){let t=this.anchors[0],e=this.anchors[1];return!t||!e?null:{min:Math.min(t.price,e.price),max:Math.max(t.price,e.price)}}schema(){return{fields:[{path:"magnifier.timeframe",label:"Timeframe",kind:"select",options:yI,group:"behavior"},...re.map(t=>({...t,label:t.label.replace("Line","Border")})),{path:"magnifier.upColor",label:"Up candles",kind:"color",group:"fill"},{path:"magnifier.downColor",label:"Down candles",kind:"color",group:"fill"}]}}writeProps(){return{...this.magnifier}}readProps(t){this.magnifier={...ap(),...t}}},_I=new Map;function B(t){_I.set(t.type,t)}var xI=P(\'<line x1="4" y1="19" x2="20" y2="5"/>\'),bI=P(\'<line x1="3" y1="12" x2="21" y2="12"/>\');B({type:"trendline",group:"lines",label:"Trend Line",icon:xI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new UE(t)});B({type:"hline",group:"lines",label:"Horizontal Line",icon:bI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"dashed"},create:t=>new qE(t)});var vI=P(\'<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>\'),wI=P(\'<rect x="4" y="6" width="16" height="12" rx="1"/>\'),SI=P(\'<path d="M5 6h14M12 6v13"/>\');B({type:"ray",group:"lines",label:"Ray",icon:vI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new zE(t)});var EI=P(\'<path d="M5 19 19 5"/><path d="M5 19 8.5 19M5 19 5 15.5"/><path d="M19 5 15.5 5M19 5 19 8.5"/>\'),NI=P(\'<line x1="12" y1="3" x2="12" y2="21"/>\'),CI=P(\'<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>\'),II=P(\'<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>\'),kI=P(\'<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>\'),AI=P(\'<path d="M4 20 20 6"/><path d="M4 20 15 20"/><path d="M11 20a7 7 0 0 0-2-4.9"/>\');B({type:"extendedline",group:"lines",label:"Extended Line",icon:EI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new HE(t)});B({type:"vline",group:"lines",label:"Vertical Line",icon:NI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new KE(t)});B({type:"hray",group:"lines",label:"Horizontal Ray",icon:CI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new GE(t)});B({type:"crossline",group:"lines",label:"Cross Line",icon:II,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new YE(t)});B({type:"infoline",group:"lines",label:"Info Line",icon:kI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new XE(t)});B({type:"trendangle",group:"lines",label:"Trend Angle",icon:AI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new ZE(t)});B({type:"box",group:"shapes",label:"Rectangle",icon:wI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}26`},create:t=>new QE(t)});B({type:"text",group:"annotations",label:"Text",icon:SI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new eN(t)});var MI=P(\'<path d="M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-6l-5 5v-5H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"/>\');B({type:"callout",group:"annotations",label:"Callout",icon:MI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new iN(t)});var TI=P(\'<path d="M5 4h14a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-7l-4 4v-4H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1Z"/><path d="M8 8.5h8M8 12h5"/>\'),PI=P(\'<rect x="10" y="4.5" width="11" height="8" rx="1.5"/><path d="M10 8.5 4 16"/><circle cx="3.5" cy="16.5" r="1.6" fill="currentColor" stroke="none"/>\'),DI=P(\'<path d="M5 4.5h14a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2h-7l-4 4v-4H5a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2Z"/>\'),OI=P(\'<path d="M3 12 7 8h12a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7Z"/><path d="M10.5 12.5h6" stroke-width="1.4"/>\'),RI=P(\'<path d="M12 11.5V21"/><rect x="5" y="4" width="14" height="7" rx="1"/><path d="M9 7.5h6"/>\');B({type:"note",group:"annotations",label:"Note",icon:TI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new tN(t)});B({type:"pricenote",group:"annotations",label:"Price Note",icon:PI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new sN(t)});B({type:"comment",group:"annotations",label:"Comment",icon:DI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new aN(t)});B({type:"pricelabel",group:"annotations",label:"Price Label",icon:OI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new nN(t)});B({type:"signpost",group:"annotations",label:"Signpost",icon:RI,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid",fillColor:`${L}d9`},create:t=>new oN(t)});var LI=P(\'<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>\'),FI=P(\'<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>\'),VI=P(\'<circle cx="4" cy="12" r="1.6" fill="currentColor"/><line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\');B({type:"parallelchannel",group:"channels",label:"Parallel Channel",icon:LI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new lN(t)});B({type:"disjointchannel",group:"channels",label:"Disjoint Channel",icon:FI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new cN(t)});var BI=P(\'<line x1="3" y1="7" x2="21" y2="7"/><line x1="3" y1="18" x2="21" y2="11"/>\');B({type:"flattopbottom",group:"channels",label:"Flat Top/Bottom",icon:BI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new uN(t)});var $I=P(\'<line x1="3" y1="8" x2="21" y2="4"/><line x1="3" y1="16" x2="21" y2="12"/><line x1="3" y1="12" x2="21" y2="8" stroke-dasharray="3 3"/>\');B({type:"regressionchannel",group:"channels",label:"Linear Regression",icon:$I,defaultStyle:{lineColor:Zn,lineWidth:1,lineStyle:"solid"},create:t=>new dN(t)});B({type:"pitchfork",group:"pitchforks",label:"Pitchfork",icon:VI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new EN(t)});var jI=P(\'<circle cx="4" cy="8" r="1.6" fill="currentColor"/><line x1="4" y1="8" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\'),WI=P(\'<circle cx="6" cy="9" r="1.6" fill="currentColor"/><line x1="6" y1="9" x2="10" y2="12"/><line x1="10" y1="6" x2="10" y2="18"/><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/>\'),UI=P(\'<line x1="4" y1="12" x2="10" y2="12"/><line x1="10" y1="8" x2="10" y2="16"/><line x1="10" y1="8" x2="21" y2="8"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="16" x2="21" y2="16"/>\');B({type:"schiffpitchfork",group:"pitchforks",label:"Schiff Pitchfork",icon:jI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new NN(t)});B({type:"modifiedschiffpitchfork",group:"pitchforks",label:"Modified Schiff Pitchfork",icon:WI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new CN(t)});B({type:"insidepitchfork",group:"pitchforks",label:"Inside Pitchfork",icon:UI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new IN(t)});var qI=P(\'<path d="M7 7h10v10"/><path d="M7 17 17 7"/>\'),zI=P(\'<ellipse cx="12" cy="12" rx="9" ry="6"/>\'),HI=P(\'<path d="M12 4 20 19 4 19Z"/>\');B({type:"arrow",group:"shapes",label:"Arrow",icon:qI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",arrowRight:!0},create:t=>new kN(t)});B({type:"ellipse",group:"shapes",label:"Ellipse",icon:zI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new AN(t)});B({type:"triangle",group:"shapes",label:"Triangle",icon:HI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new MN(t)});var KI=P(\'<polyline points="3 17 9 10 13 14 21 5"/>\'),GI=P(\'<path d="M9.5 12 17 4.5a2.12 2.12 0 0 1 3 3L12.5 15"/><path d="M7 14a3 3 0 0 0-3 3c0 1.3-1.2 1.5-1.5 2 .8.9 2 1.5 3.5 1.5a3.5 3.5 0 0 0 3.5-3.5 3 3 0 0 0-2.5-3Z"/>\'),YI=P(\'<path d="M9 11 15 5l4 4-6 6H9Z"/><path d="M9 15l-2 2"/><path d="M4 21h6"/>\');B({type:"polyline",group:"shapes",label:"Polyline",icon:KI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new PN(t)});B({type:"freehand",group:"shapes",label:"Brush",icon:GI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new DN(t)});B({type:"highlighter",group:"shapes",label:"Highlighter",icon:YI,defaultStyle:{lineColor:`${ul}59`,lineWidth:14,lineStyle:"solid"},create:t=>new RN(t)});var XI=P(\'<circle cx="12" cy="12" r="8"/>\'),ZI=P(\'<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>\'),QI=P(\'<path d="M4 19 9 11 13 14 17 8 20 4"/><path d="M17.2 5.5 20 4 19.4 7.1"/>\'),JI=P(\'<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>\'),e2=P(\'<path d="M4 18Q12 1 20 14"/>\'),t2=P(\'<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>\'),n2=P(\'<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>\');B({type:"circle",group:"shapes",label:"Circle",icon:XI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}1a`},create:t=>new LN(t)});B({type:"rotatedrect",group:"shapes",label:"Rotated Rectangle",icon:ZI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}26`},create:t=>new FN(t)});B({type:"path",group:"shapes",label:"Path",icon:QI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new VN(t)});B({type:"arc",group:"shapes",label:"Arc",icon:JI,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid",fillColor:`${L}26`},create:t=>new BN(t)});B({type:"curve",group:"shapes",label:"Curve",icon:e2,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new $N(t)});B({type:"arrowmarkup",group:"shapes",label:"Arrow Mark Up",icon:t2,defaultStyle:{lineColor:Kt,lineWidth:1,lineStyle:"solid"},create:t=>new WN(t)});B({type:"arrowmarkdown",group:"shapes",label:"Arrow Mark Down",icon:n2,defaultStyle:{lineColor:cn,lineWidth:1,lineStyle:"solid"},create:t=>new UN(t)});var r2=P(\'<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>\'),i2=P(\'<path d="m12 3 2.6 5.8 6.4.6-4.8 4.2 1.4 6.2L12 16.9 6.4 19.8 7.8 13.6 3 9.4l6.4-.6Z"/>\');B({type:"flagmark",group:"stamps",label:"Flag",icon:r2,defaultStyle:{lineColor:Xn,lineWidth:1,lineStyle:"solid"},create:t=>new HN(t)});B({type:"iconstamp",group:"stamps",label:"Icon",icon:i2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new KN(t)});var s2=P(\'<line x1="3" y1="5" x2="21" y2="5"/><line x1="3" y1="10" x2="21" y2="10"/><line x1="3" y1="14" x2="21" y2="14"/><line x1="3" y1="19" x2="21" y2="19"/>\'),a2=P(\'<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="11" x2="21" y2="11"/><line x1="3" y1="15" x2="14" y2="15"/><line x1="3" y1="20" x2="14" y2="20"/>\');B({type:"fibretracement",group:"fibonacci",label:"Fib Retracement",icon:s2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new iC(t)});B({type:"fibextension",group:"fibonacci",label:"Fib Extension",icon:a2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new aC(t)});var o2=P(\'<path d="M3 20 10 9l4 5"/><path d="M14 14h7M14 9h7M14 4h7"/>\');B({type:"fibextensiontrend",group:"fibonacci",label:"Trend-Based Fib Extension",icon:o2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new lC(t)});var l2=P(\'<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>\'),c2=P(\'<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>\');B({type:"fibfan",group:"fibonacci",label:"Fib Fan",icon:l2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new uC(t)});B({type:"fibtimezones",group:"fibonacci",label:"Fib Time Zones",icon:c2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"dashed"},create:t=>new pC(t)});var u2=P(\'<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>\'),h2=P(\'<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>\'),p2=P(\'<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>\');B({type:"fibchannel",group:"fibonacci",label:"Fib Channel",icon:u2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new fC(t)});B({type:"fibspeedfan",group:"fibonacci",label:"Fib Speed Resistance Fan",icon:h2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new yC(t)});B({type:"trendfibtime",group:"fibonacci",label:"Trend-Based Fib Time",icon:p2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"dashed"},create:t=>new _C(t)});var d2=P(\'<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>\'),f2=P(\'<path d="M8 20a4 4 0 0 1 8 0"/><path d="M4.5 20a7.5 7.5 0 0 1 15 0"/><circle cx="12" cy="20" r="1.4" fill="currentColor" stroke="none"/>\'),m2=P(\'<path d="M4 20 20 16M4 20 14 4"/><path d="M11.8 18.1A8 8 0 0 0 8.2 13.2"/><path d="M16.6 16.9A13 13 0 0 0 10.9 9"/>\'),y2=P(\'<path d="M13 12a2 2 0 1 1-2-2 4 4 0 0 1 4 4 6 6 0 0 1-9 5.2 9 9 0 0 1 .5-15"/>\');B({type:"fibcircles",group:"fibonacci",label:"Fib Circles",icon:d2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new vC(t)});B({type:"fibarcs",group:"fibonacci",label:"Fib Speed Resistance Arcs",icon:f2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new SC(t)});B({type:"fibwedge",group:"fibonacci",label:"Fib Wedge",icon:m2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new NC(t)});B({type:"fibspiral",group:"fibonacci",label:"Fib Spiral",icon:y2,defaultStyle:{lineColor:L,lineWidth:2,lineStyle:"solid"},create:t=>new MC(t)});var g2=P(\'<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>\'),_2=P(\'<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 12h16M12 4v16M4 4 20 20" opacity="0.6"/>\');B({type:"gannfan",group:"fibonacci",label:"Gann Fan",icon:g2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new PC(t)});B({type:"gannbox",group:"fibonacci",label:"Gann Box",icon:_2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new OC(t)});var x2=P(\'<rect x="4" y="4" width="16" height="16" rx="1"/><path d="M4 20 20 4M4 20 20 12M4 20 12 4" opacity="0.7"/><path d="M4 20a16 16 0 0 1 16-16" opacity="0.5"/>\');B({type:"gannsquare",group:"fibonacci",label:"Gann Square",icon:x2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new FC(t)});var b2=P(\'<path d="M2 20h20"/><path d="M4 20a8 8 0 0 1 16 0" opacity="0.9"/><path d="M6 20a4 4 0 0 1 8 0" opacity="0.75"/><path d="M10 20a2 2 0 0 1 4 0" opacity="0.6"/><path d="M8 20v-6M12 20v-9M16 20v-6" opacity="0.45"/>\');B({type:"dedekind",group:"geometry",label:"Dedekind Tessellation",icon:b2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new WC(t)});var v2=P(\'<circle cx="16" cy="12" r="5" opacity="0.55"/><circle cx="13" cy="12" r="3.5" opacity="0.75"/><circle cx="10.5" cy="12" r="2"/><path d="M8 4v16"/>\'),w2=P(\'<circle cx="17" cy="12" r="4.5" opacity="0.45"/><circle cx="13" cy="12" r="3" opacity="0.7"/><circle cx="10" cy="12" r="1.6"/><path d="M6 12 16 5M6 12 16 19"/>\');B({type:"sonic",group:"geometry",label:"Sonic",icon:v2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new zC(t)});B({type:"supersonic",group:"geometry",label:"Supersonic",icon:w2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new HC(t)});var S2=P(\'<circle cx="16" cy="12" r="5" opacity="0.4"/><circle cx="13" cy="12" r="3.2" opacity="0.65"/><circle cx="10.8" cy="12" r="1.8"/><path d="M8 4v16"/><path d="M15 8.5h2M12.5 10h2" opacity="0.5"/>\'),E2=P(\'<circle cx="17" cy="12" r="4.5" opacity="0.4"/><circle cx="12.5" cy="12" r="2.8" opacity="0.65"/><circle cx="9.8" cy="12" r="1.4"/><path d="M6 12 16 5M6 12 16 19"/>\');B({type:"goldensonic",group:"geometry",label:"Golden Sonic",icon:S2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new GC(t)});B({type:"goldensupersonic",group:"geometry",label:"Golden Supersonic",icon:E2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new YC(t)});var N2=P(\'<path d="M3 18 7 8 11 14 15 6 20 16"/>\'),C2=P(\'<path d="M4 17 9 7 14 15 20 5"/>\'),I2=P(\'<path d="M3 19 8 9 12 13 17 5 21 9"/>\'),k2=P(\'<path d="M4 7 11 16 20 9"/>\'),A2=P(\'<path d="M3 18 6 12 9 16 12 5 15 16 18 12 21 18"/>\');B({type:"xabcd",group:"patterns",label:"XABCD Pattern",icon:N2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new XC(t)});B({type:"abcd",group:"patterns",label:"ABCD Pattern",icon:C2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new ZC(t)});B({type:"elliottimpulse",group:"patterns",label:"Elliott Impulse Wave (1-5)",icon:I2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new QC(t)});B({type:"elliottcorrection",group:"patterns",label:"Elliott Correction Wave (ABC)",icon:k2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new JC(t)});B({type:"headshoulders",group:"patterns",label:"Head & Shoulders",icon:A2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new eI(t)});var M2=P(\'<path d="M3 17 7 6 12 14 17 5 21 16"/><path d="M3 17 21 16" opacity="0.45"/>\'),Lr={group:"patterns",icon:M2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"}};B({type:"gartley",label:"Gartley",...Lr,create:t=>new tI(t)});B({type:"bat",label:"Bat",...Lr,create:t=>new nI(t)});B({type:"butterfly",label:"Butterfly",...Lr,create:t=>new rI(t)});B({type:"crab",label:"Crab",...Lr,create:t=>new iI(t)});B({type:"shark",label:"Shark",...Lr,create:t=>new sI(t)});B({type:"cypher",label:"Cypher",...Lr,create:t=>new lI(t)});var T2=P(\'<rect x="4" y="6" width="16" height="12" rx="1"/><path d="M4 18 20 6" opacity="0.5"/>\');B({type:"datepricerange",group:"measure",label:"Date & Price Range",icon:T2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new hI(t)});var P2=P(\'<rect x="4.5" y="4.5" width="15" height="7.5" rx="1" fill="currentColor" fill-opacity="0.25"/><rect x="4.5" y="12" width="15" height="7.5" rx="1"/>\');B({type:"position",group:"measure",label:"Long/Short Position",icon:P2,defaultStyle:{lineColor:L,lineWidth:1,lineStyle:"solid"},create:t=>new dI(t)});var D2=P(\'<circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.3 15.3 5.2 5.2"/><path d="M8 12.5v-3M10.5 13.5v-5.5M13 12v-2"/>\');B({type:"magnifier",group:"measure",label:"Magnifier",icon:D2,defaultStyle:{lineColor:"",lineWidth:1,lineStyle:"solid"},coversSeries:!0,placementHint:"Drag an area on the chart to view it at a lower timeframe",create:t=>new gI(t)});var O2=P(\'<line x1="5" y1="3" x2="5" y2="21"/><path d="M5 16c4 0 5-9 8-9s3 5 8 3"/>\');B({type:"anchoredvwap",group:"measure",label:"Anchored VWAP",icon:O2,defaultStyle:{lineColor:Qn,lineWidth:2,lineStyle:"solid"},create:t=>new mN(t)});var R2=P(\'<path d="M4 4v16"/><path d="M4 8h10"/><path d="M4 12h14"/><path d="M4 16h8"/><path d="M4 20h12"/>\');B({type:"fixedrangevp",group:"measure",label:"Fixed Range Volume Profile",icon:R2,defaultStyle:{lineColor:Kt,lineWidth:1,lineStyle:"solid"},create:t=>new SN(t)});function bl(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var L2=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var wp=["indicators","screenshot"],jk=new Set(wp),Wk=new Set(L2);var Sp=280;var Uk=`\n.vela-panel[hidden] { display: none !important; }\n.vela-panel {\n position: relative;\n width: var(--vela-panel-w, ${Sp}px);\n flex: none;\n border-left: 1px solid var(--vela-border);\n display: flex;\n flex-direction: column;\n color: var(--vela-fg);\n font-size: 13px;\n box-sizing: border-box;\n background: var(--vela-bg);\n}\n.vela-panel-header {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 10px 8px 10px 14px;\n border-bottom: 1px solid var(--vela-border);\n font-size: 14px;\n font-weight: 600;\n color: var(--vela-fg-bright);\n}\n.vela-panel-title { flex: none; }\n.vela-panel-title:empty { display: none; }\n/* The contributed slot claims the space between title and close; its children lay out\n inline and the close button stays pinned right. */\n.vela-panel-header-slot { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; }\n.vela-panel-close {\n all: unset;\n cursor: pointer;\n width: 26px;\n height: 26px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: var(--vela-fg-muted);\n font-size: 16px;\n}\n.vela-panel-close .vela-icon { width: 16px; height: 16px; }\n.vela-panel-close:hover { background: var(--vela-hover); color: var(--vela-fg-bright); }\n/* The pin: same footprint as the close button it sits beside; filled + bright once pinned. */\n.vela-panel-pin {\n all: unset;\n cursor: pointer;\n width: 26px;\n height: 26px;\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n color: var(--vela-fg-muted);\n}\n.vela-panel-pin .vela-icon { width: 15px; height: 15px; }\n.vela-panel-pin:hover { background: var(--vela-hover); color: var(--vela-fg-bright); }\n.vela-panel-pin[data-on=\'1\'] { color: var(--vela-fg-bright); }\n.vela-panel-body { flex: 1; overflow: auto; padding: 8px; }\n.vela-panel-body::-webkit-scrollbar { width: 8px; }\n.vela-panel-body::-webkit-scrollbar-thumb { background: var(--vela-scroll); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }\n/* Straddles the panel\'s inner border so the whole seam is grabbable; it paints only under the\n pointer \\u2014 a permanently visible bar would read as a second border. */\n.vela-panel-resizer {\n position: absolute;\n top: 0;\n bottom: 0;\n left: -3px;\n width: 7px;\n cursor: col-resize;\n touch-action: none;\n z-index: 1;\n}\n.vela-panel-resizer::after {\n content: \'\';\n position: absolute;\n top: 0;\n bottom: 0;\n left: 3px;\n width: 1px;\n background: transparent;\n}\n/* The same hover ink as the workspace grid splitters and the canvas pane separators, so\n every draggable seam in the shell reads as one family. */\n.vela-panel-resizer:hover::after,\n.vela-panel-resizer[data-dragging]::after { background: var(--vela-separator-hover-line); }\n/* An OVERLAY panel floats over the chart\'s right edge instead of taking a column: the\n chart keeps its width and layout (the dock host is position:relative \\u2014 the anchoring the\n mobile rule below relies on too). Same z-order as that mobile overlay, above the chart\'s\n own DOM overlays; the shadow separates it from the plot it covers. */\n.vela-panel[data-overlay] {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n max-width: 100%;\n z-index: 25;\n box-shadow: var(--vela-shadow);\n}\n/* Mobile: a 280px column would crush a phone-width chart \\u2014 the panel overlays the\n chart area instead (its flex parent is position:relative), full-bleed, closed by\n the same header \\u2715. Width dragging is a pointer affordance; off on mobile. */\n[data-layout=\'mobile\'] .vela-panel {\n position: absolute;\n inset: 0;\n width: auto;\n z-index: 25;\n border-left: none;\n}\n[data-layout=\'mobile\'] .vela-panel-resizer { display: none; }\n`;var Ms=class{constructor(){jl(this,"ordinals",new Map)}next(e,n,r){let i=`${n}:${r.trim().toLowerCase()}`,s=this.ordinals.get(i)??0;return this.ordinals.set(i,s+1),bl({instanceId:e,kind:n,title:r,ordinal:s})}};function Fr(t){let e=t.data;if(e.length===0)return[];let n=e[e.length-1]?.value;return Array.isArray(n)?n:[]}function Ne(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t&&typeof t=="object"){let e=t;if(Array.isArray(e.data)){let n=typeof e.offset=="number"?e.offset:0,r=e.data[e.data.length-1-n];return typeof r=="number"&&Number.isFinite(r)?r:void 0}}}function Ts(t){let e=(G(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function Np(t){let e=(G(t)??"none").toLowerCase();return e==="b"||e==="both"?"both":e==="l"||e==="left"?"left":e==="r"||e==="right"?"right":"none"}function wl(t){let e=(G(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function Cp(t){if(t===void 0)return{invisible:!1};if(t===null)return{invisible:!0};if(typeof t=="number")return{invisible:!0};if(typeof t=="string"){if(t==="")return{invisible:!1};let e=ce(t);return e?{color:e,invisible:!1}:{invisible:!0}}return{invisible:!0}}function vl(t,e){let n=Ne(t.x1),r=Ne(t.y1),i=Ne(t.x2),s=Ne(t.y2);if(n===void 0||r===void 0||i===void 0||s===void 0)return null;let a=(G(t.style)??"").toLowerCase(),o=a==="style_arrow_left"||a==="style_arrow_both",l=a==="style_arrow_right"||a==="style_arrow_both",{color:c,invisible:u}=Cp(t.color);return{id:e,paneId:"unrouted",xloc:Ts(t.xloc),x1:n,y1:r,x2:i,y2:s,extend:Np(t.extend),color:c,invisible:u,width:Math.max(1,Ne(t.width)??1),style:wl(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function Ip(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let s=vl(i,n.next(e,"line",String(i.id??r.length)));s&&r.push(s)}return r}function kp(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let s=i.line1,a=i.line2;if(!s||!a)continue;let o=n.next(e,"linefill",String(i.id??r.length)),l=vl(s,`${o}:a`),c=vl(a,`${o}:b`);!l||!c||r.push({id:o,paneId:"unrouted",line1:l,line2:c,color:ce(i.color),overlay:i.force_overlay===!0})}return r}function Ap(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function F2(t){if(typeof t=="number"&&Number.isFinite(t))return Ap(t);let e=(G(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function Sl(t){let e=(G(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function Mp(t){let e=(G(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function El(t){return(G(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function Tp(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let s=Ne(i.left),a=Ne(i.top),o=Ne(i.right),l=Ne(i.bottom);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c=(G(i.text_formatting)??"").toLowerCase(),u=G(i.text);r.push({id:n.next(e,"box",String(i.id??r.length)),paneId:"unrouted",xloc:Ts(i.xloc),left:s,top:a,right:o,bottom:l,extend:Np(i.extend),bgColor:ce(i.bgcolor),borderColor:ce(i.border_color),borderWidth:Math.max(0,Ne(i.border_width)??1),borderStyle:wl(i.border_style),text:u&&u.length>0?u:void 0,textColor:ce(i.text_color),textSize:F2(i.text_size),hAlign:Sl(i.text_halign),vAlign:Mp(i.text_valign),wrap:(G(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:El(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return r}var V2=["label_up","label_down","label_left","label_right","label_center","label_lower_left","label_lower_right","label_upper_left","label_upper_right","circle","square","diamond","flag","arrowup","arrowdown","triangleup","triangledown","cross","xcross","text_outline","none"];function B2(t){let e=(G(t)??"").toLowerCase().replace(/^style_/,"");return V2.includes(e)?e:"label_down"}function $2(t){let e=(G(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function Pp(t){if(typeof t=="number"&&Number.isFinite(t))return Ap(t);let e=(G(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function Dp(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let s=Ne(i.x),a=$2(i.yloc),o=Ne(i.y);if(s===void 0||a==="price"&&o===void 0)continue;let l=G(i.text),c=G(i.tooltip),{color:u,invisible:p}=Cp(i.color);r.push({id:n.next(e,"label",String(i.id??r.length)),paneId:"unrouted",xloc:Ts(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:B2(i.style),color:u,noFill:p,textColor:ce(i.textcolor),size:Pp(i.size),textAlign:Sl(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:El(i.text_font_family),overlay:i.force_overlay===!0})}return r}function Op(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=Ts(i.xloc),o=[];for(let c of s){let u=Ne(c.price),p=Ne(c.index),h=Ne(c.time),d=a==="bar_time"?h:p,f=a==="bar_time"?p:h,m,_;if(d!==void 0)m=d,_=a;else if(f!==void 0)m=f,_=a==="bar_time"?"bar_index":"bar_time";else continue;u!==void 0&&o.push({xloc:_,x:m,price:u})}if(o.length<2)continue;let l=(G(i.line_style)??"").toLowerCase();r.push({id:n.next(e,"polyline",String(i.id??r.length)),paneId:"unrouted",points:o,curved:i.curved===!0,closed:i.closed===!0,lineColor:ce(i.line_color),fillColor:ce(i.fill_color),lineWidth:Math.max(1,Ne(i.line_width)??1),lineStyle:wl(i.line_style),arrowLeft:l==="style_arrow_left"||l==="style_arrow_both",arrowRight:l==="style_arrow_right"||l==="style_arrow_both",overlay:i.force_overlay===!0})}return r}var j2=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function W2(t){let e=(G(t)??"").toLowerCase();return j2.includes(e)?e:"top_right"}function U2(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:Pp(t)}function Ep(t){let e=Ne(t);return e!==void 0&&e>0?e:void 0}function q2(t){if(!t||typeof t!="object")return null;let e=t,n=G(e.text),r=G(e.tooltip),i=(G(e.text_formatting)??"").toLowerCase();return{text:n&&n.length>0?n:void 0,textColor:ce(e.text_color),bgColor:ce(e.bgcolor),hAlign:Sl(e.text_halign),vAlign:Mp(e.text_valign),textSize:U2(e.text_size),fontFamily:El(e.text_font_family),tooltip:r&&r.length>0?r:void 0,bold:i.includes("bold"),italic:i.includes("italic"),width:Ep(e.width),height:Ep(e.height),merged:e._merged===!0}}function z2(t){if(!Array.isArray(t))return[];let e=[],n=new Set;for(let r of t){if(!r||typeof r!="object")continue;let i=r,s=Ne(i.startCol??i.start_column??i.startColumn),a=Ne(i.startRow??i.start_row),o=Ne(i.endCol??i.end_column??i.endColumn),l=Ne(i.endRow??i.end_row);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c={startCol:Math.min(Math.round(s),Math.round(o)),startRow:Math.min(Math.round(a),Math.round(l)),endCol:Math.max(Math.round(s),Math.round(o)),endRow:Math.max(Math.round(a),Math.round(l))},u=`${c.startCol}:${c.startRow}:${c.endCol}:${c.endRow}`;n.has(u)||(n.add(u),e.push(c))}return e}function Rp(t,e,n){let r=[];for(let i of Fr(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(l=>(Array.isArray(l)?l:[]).map(c=>q2(c))),o=z2(i.merges);for(let l of o){let c=a[l.startRow]?.[l.startCol];c?.merged&&(c.merged=!1)}r.push({id:n.next(e,"table",String(i.id??r.length)),paneId:"unrouted",position:W2(i.position),columns:Math.max(0,Math.round(Ne(i.columns)??0)),rows:Math.max(0,Math.round(Ne(i.rows)??0)),bgColor:ce(i.bgcolor),frameColor:ce(i.frame_color),frameWidth:Math.max(0,Ne(i.frame_width)??0),borderColor:ce(i.border_color),borderWidth:Math.max(0,Ne(i.border_width)??0),cells:a,merges:o,overlay:i.force_overlay===!0})}return r}var Fp=Xn;function Vp(t,e){let n=new Ms,r=[],i=[],s=[],a=[],o=[],l=[],c=[],u=[],p=[],h=[],d=[],f=[],m=new Map,_=new Set,x=[];for(let v of t.plots){let E=zh(v.style),C=v.title??v.key;switch(E){case"skip":break;case"barcolor":{if(!yi(v.options.display))break;let I=gi(v.data.length,pe(v.options.show_last));for(let F=I;F<v.data.length;F+=1){let $=v.data[F],j=ce($.options?.color);j&&f.push({time:$.time,color:j})}break}case"fill":yi(v.options.display)&&x.push(v);break;case"hline":{let I=rk(v,C,e,n);I&&o.push(I);break}case"background":yi(v.options.display)&&a.push(...ik(v,C,e,n));break;case"drawing_line":l.push(...Ip(v,e,n));break;case"drawing_box":c.push(...Tp(v,e,n));break;case"label":u.push(...Dp(v,e,n));break;case"drawing_polyline":p.push(...Op(v,e,n));break;case"linefill":h.push(...kp(v,e,n));break;case"table":d.push(...Rp(v,e,n));break;case"markers":yi(v.options.display)&&u.push(...sk(v,e,n));break;default:{let I=n.next(e,E,C);m.set(v.key,I),v.options.force_overlay===!0&&_.add(v.key),i.push(K2(E,v,I,C));let F=Z2(v,C,e,n);F&&o.push(F)}}}for(let v of x){let E=v.plot1?m.get(v.plot1):void 0,C=v.plot2?m.get(v.plot2):void 0;if(!E||!C){r.push(`fill "${v.key}" references unknown plots (${v.plot1??"?"}/${v.plot2??"?"})`);continue}let I=_.has(v.plot1)&&_.has(v.plot2);s.push({id:n.next(e,"fill",v.title??v.key),paneId:"unrouted",fromSeriesId:E,toSeriesId:C,...nk(v),...I?{overlay:!0}:{}})}let w=t.trades?H2(t.trades):[];return{model:{id:e,title:t.meta.title,overlay:t.meta.overlay,paneHint:t.meta.overlay?"price":"new",series:i,fills:s,backgrounds:a,priceLines:o,lines:l,boxes:c,labels:u,polylines:p,linefills:h,tables:d,barColors:f.length?f:void 0,trades:w.length?w:void 0,inputs:[],inputValues:{}},warnings:r}}function H2(t){let e=new Map,n=r=>{let i=`${r.time}|${r.side}|${r.label??""}`,s=e.get(i);if(!s){e.set(i,r);return}s.qty=(s.qty??0)+(r.qty??0),r.kind==="entry"&&s.kind==="exit"&&(s.kind="entry",s.price=r.price,s.tradeId=r.tradeId)};for(let r of t){let i=r.size>0,s=Math.abs(r.size);n({time:r.entry_time,price:r.entry_price,side:i?"buy":"sell",kind:"entry",label:r.entry_comment??r.entry_id,qty:s,tradeId:r.id}),r.status==="closed"&&r.exit_time!=null&&r.exit_price!=null&&n({time:r.exit_time,price:r.exit_price,side:i?"sell":"buy",kind:"exit",label:r.exit_comment??r.exit_id,qty:s,tradeId:r.id})}return[...e.values()].sort((r,i)=>r.time-i.time)}function K2(t,e,n,r){let i=pe(e.options.show_last),s=e.options.force_overlay===!0?{overlay:!0}:{},a=Bp(e.options.display);if(t==="candle"||t==="bar"){let m={id:n,title:r,paneId:"unrouted",kind:t,bars:tk(e,gi(e.data.length,i)),visible:a.pane,display:a,...s},_=Q2(e);return _&&(m.barColors=_),m}let o=t,l=ce(jp(e)),c={...a,pane:a.pane&&!!l},u=pe(e.options.linewidth)??1,p=o==="line"||o==="step"||o==="area",h=ek(X2(J2(e),i,p),pe(e.options.offset)),d={color:l??Fp,width:u,lineStyle:Wp(e.options.linestyle)??"solid"},f=pe(e.options.histbase);return f!==void 0&&(o==="histogram"||o==="columns"||o==="area")&&(d.base=f),{id:n,title:r,paneId:"unrouted",kind:o,points:h,style:d,visible:c.pane,display:c,...s}}var Lp={pane:!0,priceScale:!0,legend:!0,dataWindow:!0},G2={pane:"pane",data_window:"dataWindow",status_line:"legend",price_scale:"priceScale"},Y2=["all","none","pane","data_window","status_line","price_scale"];function Bp(t){if(typeof t!="string")return{...Lp};let e={pane:!1,priceScale:!1,legend:!1,dataWindow:!1};for(let n=0;n<t.length;){let r=Y2.find(i=>t.startsWith(i,n));if(!r||r==="all")return{...Lp};r!=="none"&&(e[G2[r]]=!0),n+=r.length}return e}function yi(t){return Bp(t).pane}function gi(t,e){return e===void 0||e<=0?0:Math.max(0,t-Math.floor(e))}function X2(t,e,n){let r=gi(t.length,e);return n&&(r-=1),r<=0?t:t.map((i,s)=>s<r?{...i,value:null}:i)}function Z2(t,e,n,r){if(t.options.trackprice!==!0)return null;for(let i=t.data.length-1;i>=0;i-=1){let s=t.data[i];if(!(typeof s.value!="number"||!Number.isFinite(s.value)))return{id:r.next(n,"hline",e),paneId:"unrouted",price:s.value,color:ce(s.options?.color)??ce(jp(t)),lineStyle:"dotted",width:pe(t.options.linewidth),title:e}}return null}function Q2(t){let e=!1,n=t.data.map(r=>{let i=r.options??{},s=ce(i.color),a=ce(i.wickcolor),o=ce(i.bordercolor);return!s&&!a&&!o?null:(e=!0,{color:s,wickColor:a,borderColor:o})});return e?n:void 0}function J2(t){let e=t.data.some(n=>ws(n.options?.color));return t.data.map(n=>{let r=typeof n.value=="number"&&Number.isFinite(n.value)?n.value:null,i=ce(n.options?.color);return i?{time:n.time,value:r,color:i}:e?{time:n.time,value:r,color:Hh}:{time:n.time,value:r}})}function $p(t){let e=[];for(let n=1;n<t.length;n+=1){let r=t[n].time-t[n-1].time;r>0&&e.push(r)}return e.length===0?0:(e.sort((n,r)=>n-r),e[e.length>>1]??0)}function ek(t,e){if(!e)return t;let n=e*$p(t);return n?t.map(r=>({...r,time:r.time+n})):t}function tk(t,e=0){let n=e>0?new Array(t.data.length):[];for(let r=e;r<t.data.length;r+=1){let i=t.data[r],s=i.value;if(!Array.isArray(s)||s.length<4)continue;let a={time:i.time,open:s[0]??0,high:s[1]??0,low:s[2]??0,close:s[3]??0};e>0?n[r]=a:n.push(a)}return n}function jp(t){for(let e of t.data)if(typeof e.options?.color=="string"&&e.options.color)return e.options.color;return G(t.options.color)}function nk(t){if(t.options.gradient===!0||t.data.some(s=>s.options&&(typeof s.options.top_color=="string"||typeof s.options.bottom_color=="string")))return{gradient:t.data.map(a=>{let o=a.options??{},l=pe(o.top_value),c=pe(o.bottom_value),u=typeof o.top_color=="string"?o.top_color:void 0,p=typeof o.bottom_color=="string"?o.bottom_color:void 0;return l===void 0||c===void 0||!u&&!p?null:{topValue:l,bottomValue:c,topColor:u??"rgba(0,0,0,0)",bottomColor:p??"rgba(0,0,0,0)"}})};let n=t.data.map(s=>ce(s.options?.color)??null),r=new Set(n.filter(s=>s!==null)),i=n.some(s=>s===null);return r.size===0?{color:ce(t.options.color)}:r.size===1&&!i?{color:[...r][0]}:{colors:n}}function rk(t,e,n,r){if(!yi(t.options.display))return null;let i;for(let s of t.data)if(typeof s.value=="number"&&Number.isFinite(s.value)){i=s.value;break}return i===void 0?null:{id:r.next(n,"hline",e),paneId:"unrouted",price:i,color:ce(t.options.color),lineStyle:Wp(t.options.linestyle)??"dashed",title:e,width:pe(t.options.linewidth)}}function Wp(t){let e=G(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="solid"||e==="dashed"||e==="dotted"?e:void 0}function ik(t,e,n,r){let i=[],s=t.options.force_overlay===!0?{overlay:!0}:{},a=t.data,o=a.length>1?(a[1]?.time??0)-(a[0]?.time??0):0,l=gi(a.length,pe(t.options.show_last));for(;l<a.length;){let c=a[l],u=ce(c.options?.color);if(c.value===!0&&u){let p=c.time,h=c.time,d=l;for(;d+1<a.length;){let f=a[d+1];if(f.value===!0&&ce(f.options?.color)===u)h=f.time,d+=1;else break}i.push({id:r.next(n,"background",e),paneId:"unrouted",from:p,to:h+o,color:u,...s}),l=d+1}else l+=1}return i}function sk(t,e,n){let r=pe(t.options.offset),i=r?r*$p(t.data):0,s=t.style==="char"||t.options.char!==void 0,a=!s&&!("shape"in t.options)&&t.data.some(p=>p.options!==void 0&&"height"in p.options),o=a?ak(t):null,l=t.options.force_overlay===!0?{overlay:!0}:{},c=[],u=gi(t.data.length,pe(t.options.show_last));for(let p=u;p<t.data.length;p+=1){let h=t.data[p],d=h.value,f=typeof d=="number"&&Number.isFinite(d);if(d!==!0&&!f||a&&(!f||d===0))continue;let m=h.options??t.options,_=m.color!==void 0?m.color:t.options.color;if(_!==void 0&&!ws(_))continue;let x=G(m.text)??G(t.options.text),w=x&&x.trim().length>0?x:void 0,S=a?f&&d>0?Kt:cn:void 0,v=ce(m.color)??ce(t.options.color)??S??Fp,E=s?G(m.char)??G(t.options.char)??"\\u2605":void 0;c.push({id:n.next(e,"label",`${t.key}#${c.length}`),paneId:"unrouted",xloc:"bar_time",x:h.time+i,y:f?d:0,yloc:lk(G(m.location)??G(t.options.location)),text:E!==void 0?w!==void 0?`${E}\n${w}`:E:w,style:E!==void 0?"none":ck(G(m.shape)??G(t.options.shape)),color:v,textColor:ce(m.textcolor)??ce(t.options.textcolor)??(E!==void 0?v:void 0),size:o!==null&&f?ok(Math.abs(d),o):uk(G(m.size)??G(t.options.size)),textAlign:"center",fontFamily:"default",...l})}return c}function ak(t){let e=0;for(let n of t.data)typeof n.value=="number"&&Number.isFinite(n.value)&&(e=Math.max(e,Math.abs(n.value)));return{maxAbs:e,minH:pe(t.options.minheight)??5,maxH:pe(t.options.maxheight)??100}}function ok(t,e){let n=e.maxAbs>0?t/e.maxAbs:1,r=e.minH+n*(e.maxH-e.minH);return r<=12?"tiny":r<=24?"small":r<=44?"normal":r<=72?"large":"huge"}function lk(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function ck(t){switch((t??"").toLowerCase().replace(/^shape_/,"").replace(/_/g,"")){case"diamond":return"diamond";case"triangleup":return"triangleup";case"triangledown":return"triangledown";case"labelup":return"label_up";case"labeldown":return"label_down";case"arrowup":return"arrowup";case"arrowdown":return"arrowdown";case"square":return"square";case"cross":return"cross";case"xcross":return"xcross";case"flag":return"flag";default:return"circle"}}function uk(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function hk(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";case"source":return"source";case"color":return"color";case"price":return"price";case"time":return"time";case"session":return"session";case"timeframe":return"timeframe";case"symbol":return"symbol";case"text_area":return"text_area";default:return"string"}}function pk(t){return t==="int"||t==="float"||t==="price"||t==="time"}var Up={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 dk(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return Up[e]??t}function fk(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?Up[e[1].toLowerCase()]:void 0}function mk(t){return(t.type==="string"||t.type==null)&&fk(t.defval)!==void 0}function yk(t,e){if(e==="bool")return!!t;if(pk(e))return typeof t=="number"?t:Number(t)||0;let n=typeof t=="string"?t:t==null?"":String(t);return e==="color"?dk(n):n}function qp(t){return t.map((e,n)=>{let r=mk(e)?"color":hk(e.type);return{key:e.varId??e.title??`input${n}`,title:e.title??e.varId??`Input ${n+1}`,type:r,defval:yk(e.defval,r),min:e.minval,max:e.maxval,step:e.step,options:Array.isArray(e.options)?e.options.map(i=>String(i)):void 0,group:e.group,inline:e.inline,tooltip:e.tooltip}})}function gk(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";default:return"string"}}function Nl(t,e){return e==="bool"?!!t:e==="int"||e==="float"?typeof t=="number"?t:Number(t)||0:typeof t=="string"?t:t==null?"":String(t)}function _k(t){let e=t.replace(/_/g," ");return e.charAt(0).toUpperCase()+e.slice(1)}function zp(t,e){let n=t.getPropsMeta(),r=t.prop;return n.filter(i=>i.mutable&&i.name).map(i=>{let s=i.name,a=gk(i.type),o=Nl(i.defval,a),l=Nl(r[s]??i.defval,a),c=e?.[s],u=l!==o?l:c!==void 0?Nl(c,a):o;return{key:s,title:_k(s),type:a,defval:u,min:i.minval,max:i.maxval,options:Array.isArray(i.options)?i.options.map(p=>String(p)):void 0}})}function Hp(t,e){for(let[n,r]of Object.entries(e))try{t.prop[n]=r}catch(i){console.warn(`[vela-pinets] prop "${n}" rejected:`,i instanceof Error?i.message:i)}}var Kp=!1;function Cl(){if(Kp)return;Kp=!0;let t=Cr.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!=="table")return;let s=this.pine.table,a=n;if(!s||typeof s.cell_set_text_formatting=="function"||typeof a._setCellProp!="function")return;let o=(c,u,p,h)=>a._setCellProp(c,u,p,"text_formatting",h);s.cell_set_text_formatting=(c,u,p,h)=>o(c,u,p,h);let l=s.cell;typeof l=="function"&&(s.cell=(...c)=>{let u=c[c.length-1],p=u&&typeof u=="object"&&!Array.isArray(u)&&"text_formatting"in u?u:null;if(!p&&c.length<14)return l(...c);let h=p?c.slice(0,-1):c.slice(0,13),d,f;if(p){let{text_formatting:S,...v}=p;d=S,f=Object.keys(v).length>0?[...h,v]:h}else d=c[13],f=h;let m=l(...f),_=p??{},x=h.length>1?h[1]:_.column??0,w=h.length>2?h[2]:_.row??0;return o(h[0],x,w,d),m})})}var Gp=["plotshape","plotchar","plotarrow"],Yp=!1;function Il(){if(Yp)return;Yp=!0;let t=Cr.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!==void 0||!Gp.some(a=>r.includes(a)))return;let s={idx:void 0,n:0,len:0};for(let a of Gp){let o=this.pine[a];if(typeof o!="function")continue;let l=o;this.pine[a]=(...c)=>{let u=c[c.length-1];if(!(u!==null&&typeof u=="object"&&"__callsiteId"in u)){let h=this.idx;s.len===0&&s.idx!==void 0&&h!==s.idx&&(s.len=s.n,s.n=0),s.idx=h;let d=s.len>0?s.n%s.len:s.n;s.n+=1,c.push({__callsiteId:`~m${d}`})}return l(...c)}}})}function kl(t,e,n){return t?{getFootprintData:(r,i,s,a,o)=>t(xk(r??e()),i??n(),{from:a,to:o,limit:s})}:{}}function xk(t){return t.split(";")[0]??t}function bk(t,e,n){if(n==="none")return[];if(n==="strategy"&&t.getDeclarationType()!=="strategy")return[];let r=zp(t,e);if(typeof n=="string")return r;let i=new Map(r.map(s=>[s.key,s]));return n.map(s=>i.get(s)).filter(s=>s!==void 0)}function ed(t,e,n,r="all"){let i=zn.from(t),s=qp(i.getInputsMeta()),a=bk(i,n,r),o=i.prop.overlay,l=typeof o=="boolean"?o:void 0,c=l??/(?<![\\w.$])overlay\\s*[:=]\\s*true/.test(t),p=/^\\s*(?:indicator|strategy)\\s*\\(\\s*(?:title\\s*=\\s*)?(["\'])((?:\\\\.|(?!\\1).)*)\\1/m.exec(t)?.[2]?.replace(/\\\\(.)/g,"$1").trim()||"Indicator",h=/chart\\.(left|right)_visible_bar(_time)?\\b/.test(t),d={source:t,instanceId:e,...l!==void 0?{declaredOverlay:l}:{}};return{language:"pine",inputs:s,...a.length>0?{props:a}:{},meta:{title:p,overlay:c},reactsToViewport:h,token:d}}function Ml(t,e,n,r={}){let i=JSON.stringify([n,r]);if(t.lastKey!==i||!t.lastInd){let s=new zn(e,n);Hp(s,r),t.lastInd=s,t.lastKey=i}return t.lastInd}async function td(t){let{ind:e,bars:n,market:r,visibleRange:i,prepared:s,instanceId:a,inputs:o,props:l,fetchSeries:c,footprints:u}=t;Cl(),Il();let p=Tl(n,r.timeframe,r.symbolInfo),h={getMarketData:(_,x,w,S,v)=>rd(_,x,r)?Promise.resolve(p):id(c,_,x,w,S,v,Ds(r,_)),getSymbolInfo:async _=>Ds(r,_),...kl(u,()=>r.symbol,()=>r.timeframe)},d=new Rn(h,Pl(r),r.timeframe,p.length);await d.ready(),i&&d.setVisibleRange(i.left,i.right);let f=await d.run(e),m=typeof d.usesVisibleRange=="function"?d.usesVisibleRange():!1;return{model:ol(f)?nd(f,a,s,o,l??{},n[0]?.time):null,alerts:(f.alerts??[]).map(ad),warnings:(f.warnings??[]).map(od),reactsToViewport:m,ctx:f}}function nd(t,e,n,r,i,s){let{model:a}=Vp(vs(t),e),o=typeof i.overlay=="boolean"?i.overlay:n.token.declaredOverlay;return o!==void 0&&(a.overlay=o,a.paneHint=o?"price":"new"),a.inputs=n.inputs,a.inputValues={...Jp(n.inputs),...r},n.props&&(a.props=n.props,a.propValues={...Jp(n.props),...i}),s!=null&&(a.anchorTime=s),a}function Xp(t){if(typeof t!="string")return null;let e=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/.exec(t);return e?{start:Number(e[1])*60+Number(e[2]),end:Number(e[3])*60+Number(e[4])}:null}var Al=(t,e)=>e.start<=e.end?t>=e.start&&t<e.end:t>=e.start||t<e.end,Ps=new Map;function Zp(t,e){let n=`${e}:${Math.floor(t/36e5)}`,r=Ps.get(n);if(r==null){try{let i=new Intl.DateTimeFormat("en-US",{timeZone:e,hour12:!1,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).formatToParts(t),s=a=>Number(i.find(o=>o.type===a)?.value??NaN);r=Math.round((Date.UTC(s("year"),s("month")-1,s("day"),s("hour")%24,s("minute"))-t)/6e4)}catch{r=NaN}Ps.size>1e5&&Ps.clear(),Ps.set(n,r)}return Number.isNaN(r)?null:((Math.floor(t/6e4)+r)%1440+1440)%1440}function vk(t){return t==null?null:/^\\d+$/.test(t)?Number(t):/^1?D$/i.test(t)?1440:null}function wk(t,e,n){let r=typeof n=="object"&&n!=null?n:null,i=vk(e),s=Xp(r?.session),a=typeof r?.timezone=="string"?r.timezone:null;if(i==null||s==null||a==null||t.length===0)return null;let o=Xp(r?.session_extended),l=s;if(o)for(let c of t){let u=Zp(c.time,a);if(u!=null&&!Al(u,s)&&Al(u,o)){l=o;break}}return c=>{let u=Zp(c,a);if(u==null||!Al(u,l))return null;let p=(l.end-u+1440)%1440||1440;return c+Math.min(i,p)*6e4}}function Tl(t,e,n){let r=wk(t,e,n);return t.map(i=>{let s={openTime:i.time,open:i.open,high:i.high,low:i.low,close:i.close,volume:i.volume??0},a=r?.(i.time);return a!=null&&(s.closeTime=a),s})}function Pl(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function rd(t,e,n){return(t==null||t===Pl(n))&&(e==null||e===n.timeframe)}async function id(t,e,n,r,i,s,a){if(!t||!e||!n)return[];let o=await t(e,n,{from:i,to:s,limit:r});return Tl(o,n,a)}function Sk(t,e,n,r){let i="",s=!1;return{...kl(r,()=>e().symbol,()=>e().timeframe),markDirty:()=>{s=!0},getMarketData:async(a,o,l,c,u)=>{let p=e();if(!rd(a,o,p))return id(n,a,o,l,c,u,Ds(p,a));let h=Tl(t(),p.timeframe,p.symbolInfo);if(c==null)return h;let d=h.filter(_=>(_.openTime??0)>=c),f=d[d.length-1],m=f?`${d.length}|${f.openTime}|${f.close}|${f.high}|${f.low}|${f.volume}`:"";return!s&&m===i?[]:(s=!1,i=m,d)},getSymbolInfo:async a=>Ds(e(),a)}}function sd(t){let e=t.bars();Cl(),Il();let n=Ml(t.cache,t.token.source,t.inputs,t.props??{}),r=e[0]?.time,i=Math.max(1,e.length),s=Sk(t.bars,t.market,t.fetchSeries,t.footprints),a=new Rn(s,Pl(t.market()),t.market().timeframe,i);t.visibleRange&&a.setVisibleRange(t.visibleRange.left,t.visibleRange.right);let o=a.stream(n,{live:!0,interval:1e3,pageSize:i}),l=!1,c=null;return o.on("data",u=>{if(!l&&(c=u,!!ol(u)))try{t.onModel(nd(u,t.token.instanceId,t.prepared,t.inputs,t.props??{},r))}catch(p){t.onError?.(p instanceof Error?p:new Error(String(p)))}}),o.on("alert",u=>t.onAlert?.(ad(u))),o.on("warning",u=>t.onWarning?.(od(u))),o.on("error",u=>t.onError?.(u instanceof Error?u:new Error(String(u)))),{stop:()=>{l=!0,o.stop()},setVisibleRange:(u,p)=>{a.setVisibleRange(u,p),s.markDirty()},markDirty:()=>s.markDirty(),lastCtx:()=>c}}function Ds(t,e){let n=e&&e.split(";")[0];return n&&n!==t.symbol?Qp({symbol:n,timeframe:t.timeframe}):Qp(t)}function Qp(t){if(t.symbolInfo)return t.symbolInfo;let e=t.symbol,n=e.replace(/(USDT|USDC|USD|PERP|BUSD)$/i,"")||e;return{ticker:e,tickerid:e,main_tickerid:e,description:e,prefix:"",root:e,type:"crypto",basecurrency:n,currency:"USD",timezone:"UTC",session:"regular",mintick:.01,minmove:1,pointvalue:1,pricescale:100}}function Jp(t){let e={};for(let n of t)e[n.key]=n.defval;return e}function ad(t){return{id:String(t.id??""),message:String(t.message??""),title:t.title,time:Number(t.time??0),barIndex:Number(t.bar_index??0),freq:t.freq}}function od(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var St=t=>pe(t)??0;function ld(t){if(t==null||typeof t!="object")return;let e=t;return{position:St(e.position_size),avgPrice:St(e.position_avg_price),equity:St(e.equity),openPnl:St(e.openprofit),netPnl:St(e.netprofit),grossProfit:St(e.grossprofit),grossLoss:St(e.grossloss),wins:St(e.wintrades),losses:St(e.losstrades),even:St(e.eventrades),maxDrawdown:St(e.max_drawdown),maxRunup:St(e.max_runup),initialCapital:St(e.initial_capital)}}var Os=(t,e)=>{let n=pe(e);return n===void 0?{}:{[t]:n}};function cd(t){if(t==null||typeof t!="object")return[];let e=t,n=[];for(let r of[...Array.isArray(e.closedtrades)?e.closedtrades:[],...Array.isArray(e.opentrades)?e.opentrades:[]]){let i=r??{},s=pe(i.entry_price),a=pe(i.entry_time),o=pe(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=pe(i.exit_price),c=pe(i.exit_time);n.push({id:G(i.id)??`trade_${n.length}`,side:o>0?"long":"short",qty:Math.abs(o),entry:{id:G(i.entry_id)??"",time:a,price:s,...G(i.entry_comment)!==void 0?{comment:G(i.entry_comment)}:{}},...l!==void 0&&c!==void 0?{exit:{id:G(i.exit_id)??"",time:c,price:l,...G(i.exit_comment)!==void 0?{comment:G(i.exit_comment)}:{}}}:{},open:i.status!=="closed",...Os("pnl",i.profit),...Os("commission",i.commission),...Os("maxDrawdown",i.max_drawdown),...Os("maxRunup",i.max_runup)})}return n}function ud(t){try{return structuredClone(t)}catch{return}}function Ek(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return ud(e?e[e.length-1]:t)}function Nk(t){return t.replace(/^glb\\d+_/,"")}function Dl(t,e){if(t)for(let[n,r]of Object.entries(t)){if(n.startsWith("_"))continue;let i=Ek(r);i!==void 0&&(e[Nk(n)]=i)}}function hd(t,e,n){let r=t??{},i=r.fullContext??r,s=h=>!n||n.includes(h),a=s("meta")||s("plots")?vs(t):null,o={};if(a&&s("plots"))for(let h of a.plots)h.key.startsWith("__")||(o[h.key]=h.data.map(d=>({time:d.time,value:ud(d.value)??null})));let l={};s("variables")&&(Dl(i.const,l),Dl(i.var,l),Dl(i.let,l));let c=s("strategy")?ld(i.strategy):void 0,u=s("trades")&&i.strategy?cd(i.strategy):void 0,p=typeof i.idx=="number"?i.idx:typeof i.length=="number"?i.length-1:-1;return{language:"pine",phase:e,barIndex:p,meta:a&&s("meta")?{title:a.meta.title,overlay:a.meta.overlay,precision:a.meta.precision,shorttitle:a.meta.shorttitle}:{title:"",overlay:!1},plots:o,variables:l,...c?{strategy:c}:{},...u&&u.length>0?{trades:u}:{},warnings:s("warnings")?(i.warnings??[]).map(h=>({message:String(h.message??""),method:typeof h.method=="string"?h.method:void 0,bar:Number(h.bar??0)})):[]}}var pd=self,Ue=t=>pd.postMessage(t),Fn=new Map,Rl=new Map,Ll=new Map,dd=0,fd=(t,e,n)=>new Promise((r,i)=>{let s=++dd;Rl.set(s,{resolve:r,reject:i}),Ue({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:n})}),Ck=(t,e,n)=>new Promise((r,i)=>{let s=++dd;Ll.set(s,{resolve:r,reject:i}),Ue({kind:"fetchFootprints",reqId:s,symbol:t,timeframe:e,range:n})});function Rs(t){t.chain=t.chain.then(()=>kk(t))}function Ik(t,e){let n=t.bars[t.bars.length-1];n&&e.time===n.time?t.bars[t.bars.length-1]=e:(!n||e.time>n.time)&&t.bars.push(e)}function Ol(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=sd({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,props:t.props,bars:()=>t.bars,market:()=>t.market,fetchSeries:fd,footprints:t.footprints,visibleRange:t.visibleRange,onModel:e=>{t.stopped||Ue({kind:"model",sessionId:t.id,model:e})},onAlert:e=>Ue({kind:"alert",sessionId:t.id,alert:e}),onWarning:e=>Ue({kind:"warning",sessionId:t.id,warning:e}),onError:e=>Ue({kind:"error",sessionId:t.id,message:e.message})}))}async function kk(t){if(!t.stopped)try{let e=t.prepared.token,n=await td({ind:Ml(t.cache,e.source,t.inputs,t.props),bars:t.bars,market:t.market,visibleRange:t.visibleRange,prepared:t.prepared,instanceId:e.instanceId,inputs:t.inputs,props:t.props,fetchSeries:fd,footprints:t.footprints});if(t.stopped)return;Ue({kind:"reactsToViewport",sessionId:t.id,value:n.reactsToViewport});for(let r of n.alerts)Ue({kind:"alert",sessionId:t.id,alert:r});for(let r of n.warnings)Ue({kind:"warning",sessionId:t.id,warning:r});t.lastCtx=n.ctx,n.model&&Ue({kind:"model",sessionId:t.id,model:n.model}),Ue({kind:"done",sessionId:t.id})}catch(e){Ue({kind:"error",sessionId:t.id,message:e instanceof Error?e.message:String(e)})}}pd.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{Ue({kind:"prepared",reqId:e.reqId,prepared:ed(e.source,e.instanceId,e.defaultProps,e.propsVisibility)})}catch(n){Ue({kind:"prepared",reqId:e.reqId,error:n instanceof Error?n.message:String(n)})}return;case"execute":{let n={id:e.sessionId,mode:e.mode??"static",prepared:e.prepared,market:e.market,bars:e.bars,inputs:e.inputs,props:e.props??{},visibleRange:e.visibleRange,cache:{},stopped:!1,deferred:e.historyState==="backfill",chain:Promise.resolve(),stream:null,lastCtx:null,footprints:e.footprints?Ck:void 0};if(Fn.set(n.id,n),n.mode==="live"){n.deferred||Ol(n);return}n.deferred?Ue({kind:"done",sessionId:n.id}):Rs(n);return}case"update":{let n=Fn.get(e.sessionId);if(!n)return;if(n.inputs={...n.inputs,...e.inputs},e.props&&(n.props={...n.props,...e.props}),n.mode==="live"){n.deferred||Ol(n);return}n.deferred?Ue({kind:"done",sessionId:n.id}):Rs(n);return}case"setVisibleRange":{let n=Fn.get(e.sessionId);if(!n)return;if(n.visibleRange=e.range,n.mode==="live"){n.stream?.setVisibleRange(e.range.left,e.range.right);return}n.deferred?Ue({kind:"done",sessionId:n.id}):Rs(n);return}case"notifyBars":{let n=Fn.get(e.sessionId);if(!n||n.mode==="live")return;n.bars=e.bars,n.deferred=!1,Rs(n);return}case"bars":{let n=Fn.get(e.sessionId);if(!n||n.mode!=="live")return;if(e.restart){n.bars=e.bars,n.deferred=!1,Ol(n);return}for(let r of e.bars)Ik(n,r);return}case"getContext":{let n=Fn.get(e.sessionId),r=n?n.mode==="live"?n.stream?.lastCtx()??null:n.lastCtx:null,i=!n||n.stopped?"idle":n.mode==="live"?"streaming":"idle";Ue({kind:"contextResult",reqId:e.reqId,snapshot:r==null?null:hd(r,i,e.select)});return}case"stop":{let n=Fn.get(e.sessionId);n&&(n.stopped=!0,n.stream?.stop()),Fn.delete(e.sessionId);return}case"fetchSeriesResult":{let n=Rl.get(e.reqId);if(!n)return;Rl.delete(e.reqId),e.error?n.reject(new Error(e.error)):n.resolve(e.bars??[]);return}case"fetchFootprintsResult":{let n=Ll.get(e.reqId);if(!n)return;Ll.delete(e.reqId),e.error?n.reject(new Error(e.error)):n.resolve(e.bars??[]);return}}});})();\n';
|
|
1712
1729
|
|
|
1713
1730
|
// src/pinets-worker/PineWorkerEngine.ts
|
|
1714
1731
|
function spawnWorker(workerUrl) {
|
|
@@ -1725,6 +1742,7 @@ var PineWorkerEngine = class {
|
|
|
1725
1742
|
spawn;
|
|
1726
1743
|
defaultProps;
|
|
1727
1744
|
propsVisibility;
|
|
1745
|
+
footprints;
|
|
1728
1746
|
prepares = /* @__PURE__ */ new Map();
|
|
1729
1747
|
sessions = /* @__PURE__ */ new Map();
|
|
1730
1748
|
reqId = 0;
|
|
@@ -1734,6 +1752,7 @@ var PineWorkerEngine = class {
|
|
|
1734
1752
|
this.spawn = opts.createWorker ?? (() => spawnWorker(opts.workerUrl));
|
|
1735
1753
|
this.defaultProps = opts.defaultProps;
|
|
1736
1754
|
this.propsVisibility = opts.props;
|
|
1755
|
+
this.footprints = opts.footprints;
|
|
1737
1756
|
}
|
|
1738
1757
|
prepare(source, instanceId) {
|
|
1739
1758
|
const reqId = ++this.reqId;
|
|
@@ -1765,7 +1784,8 @@ var PineWorkerEngine = class {
|
|
|
1765
1784
|
...req.props ? { props: { ...req.props } } : {},
|
|
1766
1785
|
visibleRange: req.visibleRange,
|
|
1767
1786
|
mode,
|
|
1768
|
-
historyState: req.historyState
|
|
1787
|
+
historyState: req.historyState,
|
|
1788
|
+
...this.footprints ? { footprints: true } : {}
|
|
1769
1789
|
};
|
|
1770
1790
|
if (mode === "live") this.post(msg);
|
|
1771
1791
|
else this.postRun(entry, msg);
|
|
@@ -1893,6 +1913,9 @@ var PineWorkerEngine = class {
|
|
|
1893
1913
|
case "fetchSeries":
|
|
1894
1914
|
void this.serveFetch(msg.reqId, msg.symbol, msg.timeframe, msg.range);
|
|
1895
1915
|
return;
|
|
1916
|
+
case "fetchFootprints":
|
|
1917
|
+
void this.serveFootprints(msg.reqId, msg.symbol, msg.timeframe, msg.range);
|
|
1918
|
+
return;
|
|
1896
1919
|
case "contextResult": {
|
|
1897
1920
|
const waiter = this.contextWaits.get(msg.reqId);
|
|
1898
1921
|
this.contextWaits.delete(msg.reqId);
|
|
@@ -1918,6 +1941,22 @@ var PineWorkerEngine = class {
|
|
|
1918
1941
|
this.post({ kind: "fetchSeriesResult", reqId, error: err instanceof Error ? err.message : String(err) });
|
|
1919
1942
|
}
|
|
1920
1943
|
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Answer a worker's footprint request from the engine's `footprints` option. The
|
|
1946
|
+
* worker only asks when `execute` flagged a source, so a missing one here is a
|
|
1947
|
+
* host bug — answer empty rather than hang the script's await.
|
|
1948
|
+
*/
|
|
1949
|
+
async serveFootprints(reqId, symbol, timeframe, range) {
|
|
1950
|
+
if (!this.footprints) {
|
|
1951
|
+
this.post({ kind: "fetchFootprintsResult", reqId, bars: [] });
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
try {
|
|
1955
|
+
this.post({ kind: "fetchFootprintsResult", reqId, bars: await this.footprints(symbol, timeframe, range) });
|
|
1956
|
+
} catch (err) {
|
|
1957
|
+
this.post({ kind: "fetchFootprintsResult", reqId, error: err instanceof Error ? err.message : String(err) });
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1921
1960
|
};
|
|
1922
1961
|
|
|
1923
1962
|
export { PineEngine, PineWorkerEngine };
|