@luxalgo/vela-pinets 0.2.12 → 0.2.14
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 +55 -8
- package/dist/index.d.cts +83 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +55 -8
- package/dist/vela-pinets.global.js +5261 -3982
- package/dist/vela-pinets.global.min.js +44 -41
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -111,6 +111,10 @@ function toStrategyState(raw) {
|
|
|
111
111
|
initialCapital: num(s.initial_capital)
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
+
var optNum = (key, v) => {
|
|
115
|
+
const n = asNumber(v);
|
|
116
|
+
return n === void 0 ? {} : { [key]: n };
|
|
117
|
+
};
|
|
114
118
|
function toStrategyTrades(raw) {
|
|
115
119
|
if (raw == null || typeof raw !== "object") return [];
|
|
116
120
|
const s = raw;
|
|
@@ -141,7 +145,11 @@ function toStrategyTrades(raw) {
|
|
|
141
145
|
...asString(t.exit_comment) !== void 0 ? { comment: asString(t.exit_comment) } : {}
|
|
142
146
|
}
|
|
143
147
|
} : {},
|
|
144
|
-
open: t.status !== "closed"
|
|
148
|
+
open: t.status !== "closed",
|
|
149
|
+
...optNum("pnl", t.profit),
|
|
150
|
+
...optNum("commission", t.commission),
|
|
151
|
+
...optNum("maxDrawdown", t.max_drawdown),
|
|
152
|
+
...optNum("maxRunup", t.max_runup)
|
|
145
153
|
});
|
|
146
154
|
}
|
|
147
155
|
return out;
|
|
@@ -1317,6 +1325,17 @@ function ensurePineMarkerPatch() {
|
|
|
1317
1325
|
};
|
|
1318
1326
|
}
|
|
1319
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
|
+
|
|
1320
1339
|
// src/pinets/runtime.ts
|
|
1321
1340
|
function propsFor(scanned, defaultProps, filter) {
|
|
1322
1341
|
if (filter === "none") return [];
|
|
@@ -1350,13 +1369,14 @@ function indicatorFor(cache, source, inputs, props = {}) {
|
|
|
1350
1369
|
return cache.lastInd;
|
|
1351
1370
|
}
|
|
1352
1371
|
async function runPineStatic(opts) {
|
|
1353
|
-
const { ind, bars, market, visibleRange, prepared, instanceId, inputs, props, fetchSeries } = opts;
|
|
1372
|
+
const { ind, bars, market, visibleRange, prepared, instanceId, inputs, props, fetchSeries, footprints } = opts;
|
|
1354
1373
|
ensurePineTablePatch();
|
|
1355
1374
|
ensurePineMarkerPatch();
|
|
1356
1375
|
const klines = toKlines(bars, market.timeframe, market.symbolInfo);
|
|
1357
1376
|
const source = {
|
|
1358
1377
|
getMarketData: (sym, tf, limit, sDate, eDate) => isChartSeries(sym, tf, market) ? Promise.resolve(klines) : secondaryKlines(fetchSeries, sym, tf, limit, sDate, eDate, syminfoForSymbol(market, sym)),
|
|
1359
|
-
getSymbolInfo: async (sym) => syminfoForSymbol(market, sym)
|
|
1378
|
+
getSymbolInfo: async (sym) => syminfoForSymbol(market, sym),
|
|
1379
|
+
...footprintSurface(footprints, () => market.symbol, () => market.timeframe)
|
|
1360
1380
|
};
|
|
1361
1381
|
const pine = new PineTS(source, chartTickerOf(market), market.timeframe, klines.length);
|
|
1362
1382
|
await pine.ready();
|
|
@@ -1463,10 +1483,11 @@ async function secondaryKlines(fetchSeries, sym, tf, limit, sDate, eDate, syminf
|
|
|
1463
1483
|
const bars = await fetchSeries(sym, tf, { from: sDate, to: eDate, limit });
|
|
1464
1484
|
return toKlines(bars, tf, syminfo);
|
|
1465
1485
|
}
|
|
1466
|
-
function makeLiveProvider(getBars, getMarket, fetchSeries) {
|
|
1486
|
+
function makeLiveProvider(getBars, getMarket, fetchSeries, footprints) {
|
|
1467
1487
|
let lastKey = "";
|
|
1468
1488
|
let dirty = false;
|
|
1469
1489
|
return {
|
|
1490
|
+
...footprintSurface(footprints, () => getMarket().symbol, () => getMarket().timeframe),
|
|
1470
1491
|
markDirty: () => {
|
|
1471
1492
|
dirty = true;
|
|
1472
1493
|
},
|
|
@@ -1495,7 +1516,7 @@ function openLiveStream(opts) {
|
|
|
1495
1516
|
const ind = indicatorFor(opts.cache, opts.token.source, opts.inputs, opts.props ?? {});
|
|
1496
1517
|
const anchorTime = bars[0]?.time;
|
|
1497
1518
|
const initialLen = Math.max(1, bars.length);
|
|
1498
|
-
const provider = makeLiveProvider(opts.bars, opts.market, opts.fetchSeries);
|
|
1519
|
+
const provider = makeLiveProvider(opts.bars, opts.market, opts.fetchSeries, opts.footprints);
|
|
1499
1520
|
const pine = new PineTS(provider, chartTickerOf(opts.market()), opts.market().timeframe, initialLen);
|
|
1500
1521
|
if (opts.visibleRange) pine.setVisibleRange(opts.visibleRange.left, opts.visibleRange.right);
|
|
1501
1522
|
const evt = pine.stream(ind, { live: true, interval: 1e3, pageSize: initialLen });
|
|
@@ -1578,9 +1599,11 @@ var PineEngine = class {
|
|
|
1578
1599
|
capabilities = { streaming: true, visibleRange: true, inputs: true, props: true };
|
|
1579
1600
|
defaultProps;
|
|
1580
1601
|
propsVisibility;
|
|
1602
|
+
footprints;
|
|
1581
1603
|
constructor(opts = {}) {
|
|
1582
1604
|
this.defaultProps = opts.defaultProps;
|
|
1583
1605
|
this.propsVisibility = opts.props ?? "all";
|
|
1606
|
+
this.footprints = opts.footprints;
|
|
1584
1607
|
}
|
|
1585
1608
|
prepare(source, instanceId) {
|
|
1586
1609
|
return Promise.resolve(preparePine(source, instanceId, this.defaultProps, this.propsVisibility));
|
|
@@ -1607,6 +1630,7 @@ var PineEngine = class {
|
|
|
1607
1630
|
bars: getBars,
|
|
1608
1631
|
market: () => req.market,
|
|
1609
1632
|
fetchSeries: req.fetchSeries,
|
|
1633
|
+
footprints: this.footprints,
|
|
1610
1634
|
visibleRange,
|
|
1611
1635
|
onModel: (m) => {
|
|
1612
1636
|
if (!stopped) handlers.onModel(m);
|
|
@@ -1661,7 +1685,8 @@ var PineEngine = class {
|
|
|
1661
1685
|
instanceId: token.instanceId,
|
|
1662
1686
|
inputs,
|
|
1663
1687
|
props,
|
|
1664
|
-
fetchSeries: req.fetchSeries
|
|
1688
|
+
fetchSeries: req.fetchSeries,
|
|
1689
|
+
footprints: this.footprints
|
|
1665
1690
|
});
|
|
1666
1691
|
if (stopped) return;
|
|
1667
1692
|
lastCtx = outcome.ctx;
|
|
@@ -1700,7 +1725,7 @@ var PineEngine = class {
|
|
|
1700
1725
|
};
|
|
1701
1726
|
|
|
1702
1727
|
// inline-worker:C:\Users\alexgroverr\projects\LuxAlgo-vela\repos\Vela-pinets\src\pinets-worker\worker.ts
|
|
1703
|
-
var worker_default = '"use strict";(()=>{var Ju=Object.defineProperty;var eh=(t,e,n)=>e in t?Ju(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var ro=(t,e,n)=>eh(t,typeof e!="symbol"?e+"":e,n);function th(t){return e=>new X(e.array.map(n=>Math.abs(n)),e.type,t)}function nh(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 rh(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 ih(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 sh(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 ah(t){return e=>{e.array.length=0}}function oh(t){return(e,n)=>(e.array.push(...n.array),e)}function lh(t){return e=>new X([...e.array],e.type,t)}function ch(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 uh(t){return e=>e.array.every(n=>!isNaN(n)&&n)}function hh(t){return t.every(e=>typeof e=="number")?t.every(e=>Number.isInteger(e))?Y.int:Y.float:t.every(e=>typeof e=="string")?Y.string:t.every(e=>typeof e=="boolean")?Y.bool:Y.any}function $t(t){return typeof t=="number"?Number.isInteger(t)?Y.int:Y.float:typeof t=="string"?Y.string:typeof t=="boolean"?Y.bool:Y.any}function vr(t,e){if(t===void 0||typeof t=="number"&&isNaN(t)||e===Y.any)return!0;switch(e){case Y.int:return Number.isInteger(t)||isNaN(t);case Y.float:return typeof t=="number";case Y.string:return typeof t=="string";case Y.bool:return typeof t=="boolean";case Y.box:case Y.label:case Y.line:case Y.linefill:case Y.table:case Y.color:return t===null||typeof t=="object"||typeof t=="string"}return!1}function ph(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(!vr(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 dh(t){return e=>e.array.length>0?e.array[0]:t.NA}var fh=Object.defineProperty,mh=(t,e,n)=>e in t?fh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,yh=(t,e,n)=>mh(t,typeof e!="symbol"?e+"":e,n),et=class extends Error{constructor(e,n){super(e),yh(this,"method"),this.name="PineRuntimeError",this.method=n}};function gh(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new et(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.get");return e.array[r]}}function xh(t){return(e,n)=>e.array.includes(n)}function _h(t){return(e,n)=>typeof n=="number"&&n!==n?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(n)}function bh(t){return(e,n,r)=>{if(!vr(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 et(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.insert");e.array.splice(i,0,r)}}function vh(t){return(e,n=",")=>e.array.join(n)}function wh(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function Sh(t){return(e,n)=>e.array.lastIndexOf(n)}function Eh(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 Ch(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 Nh(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 Ih(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 kh(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 Ah(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 Mh(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 Th(t){return e=>e.array.pop()}function Ph(t){return(e,n)=>{if(!vr(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 Dh(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function Rh(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new et(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.remove");return e.array.splice(r,1)[0]}}function Oh(t){return e=>{e.array.reverse()}}function Lh(t){return(e,n,r)=>{if(!vr(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 et(`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 Fh(t){return e=>e.array.shift()}function Bh(t){return e=>e.array.length}function Vh(t){return(e,n,r)=>{let i=r!==void 0?r:void 0;return new X(e.array.slice(n,i),e.type,t)}}function Wh(t){return e=>e.array.some(n=>!isNaN(n)&&n)}var jn=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(jn||{}),zo=(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))(zo||{}),qo=(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))(qo||{}),Ho=(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))(Ho||{}),Yr=["pane","data_window","status_line","price_scale"],$h=[...Yr,"all","none"];function Gr(t){let e=new Set;if(typeof t!="string")return e;for(let n=0;n<t.length;){let r=$h.find(i=>t.startsWith(i,n));if(!r)break;if(r==="all")return new Set(Yr);r!=="none"&&e.add(r),n+=r.length}return e}function Ko(t){let e=Yr.filter(n=>t.has(n));return e.length===Yr.length?"all":e.length===0?"none":e.join("")}function jh(t,e){return Ko(new Set([...Gr(t),...Gr(e)]))}function Uh(t,e){let n=Gr(t);for(let r of Gr(e))n.delete(r);return Ko(n)}var Yo=(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))(Yo||{}),Go=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(Go||{}),Xo=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(Xo||{}),Zo=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Zo||{}),zh=(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))(zh||{}),Qo=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(Qo||{}),Jo=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Jo||{}),el=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(el||{}),tl=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(tl||{}),nl=(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))(nl||{}),rl=(t=>(t.family_default="default",t.family_monospace="monospace",t))(rl||{}),il=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(il||{}),sl=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(sl||{}),al=(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))(al||{}),ol=(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))(ol||{}),ll=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(ll||{}),cl=(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))(cl||{}),ul=(t=>(t.left="left",t.none="none",t.right="right",t))(ul||{}),hl=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(hl||{}),qh={order:jn,currency:zo,dayofweek:qo,display:{...Ho,__union:jh,__minus:Uh},shape:Yo,location:Go,size:Xo,format:Zo,barmerge:Qo,xloc:Jo,yloc:el,extend:tl,text:nl,font:rl,adjustment:il,backadjustment:sl,earnings:al,dividends:ol,splits:ll,position:cl,scale:ul,settlement_as_close:hl};function Hh(t){return(e,n=jn.ascending)=>{e.array.sort((r,i)=>{let s=isNaN(r)?1/0:r,a=isNaN(i)?1/0:i;return n===jn.ascending?s-a:a-s})}}function Kh(t){return(e,n=jn.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===jn.ascending?a-o:o-a}),new X(r,Y.int,t)}}function Yh(t){return e=>{let n=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new X(e.array.map(()=>NaN),Y.int,t):r===0?new X(e.array.map(()=>1),Y.int,t):new X(e.array.map(i=>(i-n)/r),Y.int,t)}}function Gh(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 Xh(t){return e=>t.precision(e.array.reduce((n,r)=>{let i=Number(r);return isNaN(i)?n:n+i},0))}function Zh(t){return(e,n)=>{if(!vr(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 Qh(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 Jh=Object.defineProperty,ep=(t,e,n)=>e in t?Jh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Q=(t,e,n)=>ep(t,typeof e!="symbol"?e+"":e,n),Y=(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))(Y||{}),X=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=th(this.context),this._avg=nh(this.context),this._binary_search=rh(this.context),this._binary_search_leftmost=ih(this.context),this._binary_search_rightmost=sh(this.context),this._clear=ah(this.context),this._concat=oh(this.context),this._copy=lh(this.context),this._covariance=ch(this.context),this._every=uh(this.context),this._fill=ph(this.context),this._first=dh(this.context),this._get=gh(this.context),this._includes=xh(this.context),this._indexof=_h(this.context),this._insert=bh(this.context),this._join=vh(this.context),this._last=wh(this.context),this._lastindexof=Sh(this.context),this._max=Eh(this.context),this._median=Ch(this.context),this._min=Nh(this.context),this._mode=Ih(this.context),this._percentile_linear_interpolation=kh(this.context),this._percentile_nearest_rank=Ah(this.context),this._percentrank=Mh(this.context),this._pop=Th(this.context),this._push=Ph(this.context),this._range=Dh(this.context),this._remove=Rh(this.context),this._reverse=Oh(this.context),this._set=Lh(this.context),this._shift=Fh(this.context),this._size=Bh(this.context),this._slice=Vh(this.context),this._some=Wh(this.context),this._sort=Hh(this.context),this._sort_indices=Kh(this.context),this._standardize=Yh(this.context),this._stdev=Gh(this.context),this._sum=Xh(this.context),this._unshift=Zh(this.context),this._variance=Qh(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 tp(t){return(...e)=>new X([...e],hh(e),t)}function np(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 X(i,Y.any,t)}return new X(Array(r).fill(t.precision(n||0)),$t(n||0),t)}}function rp(t){return(e=0,n=!1)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.bool,t)}}function ip(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.box,t)}}function sp(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.color,t)}}function ap(t){return(e=0,n=NaN)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(t.precision(n)),Y.float,t)}}function op(t){return(e=0,n=0)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(t.precision(n)),Y.int,t)}}function lp(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.label,t)}}function cp(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.line,t)}}function up(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.linefill,t)}}function hp(t){return(e=0,n="")=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.string,t)}}function pp(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),Y.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 dp(t){return(e,n=0)=>y.from(e).get(n)}var ss=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=tp(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=np(e),this.new_bool=rp(e),this.new_box=ip(e),this.new_color=sp(e),this.new_float=ap(e),this.new_int=op(e),this.new_label=lp(e),this.new_line=cp(e),this.new_linefill=up(e),this.new_string=hp(e),this.new_table=pp(e),this.param=dp(),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 fp(t){return e=>{e.map.clear()}}function mp(t){return(e,n)=>e.map.has(n)}function yp(t){return e=>{let n=new Xr(t);return n.map=new Map(e.map),n}}function gp(t){return(e,n)=>{let r=e.map.get(n);return r===void 0?NaN:r}}function xp(t){return e=>{let n=Array.from(e.map.keys()),r=$t(n[0]);return new X(n,r,t)}}function _p(t){return(e,n,r)=>{let i=e.map.get(n);return e.map.set(n,r),i===void 0?NaN:i}}function bp(t){return(e,n)=>{for(let[r,i]of n.map)e.map.set(r,i)}}function vp(t){return(e,n)=>{let r=e.map.get(n);return e.map.delete(n)?r:NaN}}function wp(t){return e=>e.map.size}function Sp(t){return e=>{let n=Array.from(e.map.values()),r=$t(n[0]);return new X(n,r,t)}}var Ep=Object.defineProperty,Cp=(t,e,n)=>e in t?Ep(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,bt=(t,e,n)=>Cp(t,typeof e!="symbol"?e+"":e,n),Xr=class{constructor(e){this.context=e,bt(this,"map"),bt(this,"_clear"),bt(this,"_contains"),bt(this,"_copy"),bt(this,"_get"),bt(this,"_keys"),bt(this,"_put"),bt(this,"_put_all"),bt(this,"_remove"),bt(this,"_size"),bt(this,"_values"),this.map=new Map,this._clear=fp(this.context),this._contains=mp(this.context),this._copy=yp(this.context),this._get=gp(this.context),this._keys=xp(this.context),this._put=_p(this.context),this._put_all=bp(this.context),this._remove=vp(this.context),this._size=wp(this.context),this._values=Sp(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 Np(t){return()=>new Xr(t)}function Ip(t){return(e,n=0)=>y.from(e).get(n)}var as=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=Np(e),this.param=Ip(),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 kp(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r&&(r instanceof X?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 Ap(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r)if(r instanceof X)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 Mp(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 Tp(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n<0||n>=i)throw new et(`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=$t(s[0]);return new X(s,a,t)}}function Pp(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function Dp(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 Rp(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 Op(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 Lp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;return n!==r?NaN:Op(e.matrix)}}function Fp(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 Bp(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 Vp(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r){let a=$t(e.matrix[0][0]);return new X([],a,t)}let i=Bp(e.matrix),s=$t(i[0]);return new X(i,s,t)}}function Wp(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 $p(t){return e=>{let n=e.matrix.length;return n===0?0:n*e.matrix[0].length}}function jp(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 Up(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 et(`Row index ${n} is out of bounds, matrix has ${i} rows.`,"matrix.get");if(r<0||r>=s)throw new et(`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 jr(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 zp(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=jr(e.matrix),s=new le(n,r,NaN,t);return s.matrix=i,s}}function qp(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 Hp(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 Kp(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 Yp(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 Gp(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 Xp(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;return n===r}}function Zp(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 Qp(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 Jp(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 ed(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 td(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 nd(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 rd(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 id(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 sd(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 ad(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 X||Array.isArray(n.array||n)){let s=n.array||n;if(i!==s.length)return new X([],"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 X(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 od(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=jr(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 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=jr(u);l=s(p,o)}else{let u=s(a,o),p=jr(u);l=s(o,p)}let c=new le(r,n,NaN,t);return c.matrix=l,c}}function ld(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 cd(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 ud(t){return(e,n)=>{let r=e.matrix.length;if(r===0){let a=$t(e.matrix[0][0]);return new X([],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=$t(i[0]);return new X(i,s,t)}}function hd(t){return(e,n)=>{let r=e.matrix.splice(n,1),i=$t(r[0][0]);return new X(r[0]||[],i,t)}}function pd(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 dd(t){return e=>{e.matrix.reverse();for(let n of e.matrix)n.reverse()}}function fd(t){return(e,n)=>{let r=e.matrix.length;if(n<0||n>=r)throw new et(`Row index ${n} is out of bounds, matrix has ${r} rows.`,"matrix.row");let i=$t(e.matrix[n][0]);return new X([...e.matrix[n]],i,t)}}function md(t){return e=>e.matrix.length}function yd(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 et(`Row index ${n} is out of bounds, matrix has ${s} rows.`,"matrix.set");if(r<0||r>=a)throw new et(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.set");e.matrix[n][r]=i}}function gd(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 xd(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 _d(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 bd(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 vd(t){return(e,n,r)=>{let i=e.matrix[n];e.matrix[n]=e.matrix[r],e.matrix[r]=i}}function wd(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 Sd(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 Ed=Object.defineProperty,Cd=(t,e,n)=>e in t?Ed(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e,n)=>Cd(t,typeof e!="symbol"?e+"":e,n),le=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=kp(this.context),this._add_row=Ap(this.context),this._avg=Mp(this.context),this._col=Tp(this.context),this._columns=Pp(this.context),this._concat=Dp(this.context),this._copy=Rp(this.context),this._det=Lp(this.context),this._diff=Fp(this.context),this._eigenvalues=Vp(this.context),this._eigenvectors=Wp(this.context),this._elements_count=$p(this.context),this._fill=jp(this.context),this._get=Up(this.context),this._inv=zp(this.context),this._is_antidiagonal=qp(this.context),this._is_antisymmetric=Hp(this.context),this._is_binary=Kp(this.context),this._is_diagonal=Yp(this.context),this._is_identity=Gp(this.context),this._is_square=Xp(this.context),this._is_stochastic=Zp(this.context),this._is_symmetric=Qp(this.context),this._is_triangular=Jp(this.context),this._is_zero=ed(this.context),this._kron=td(this.context),this._max=nd(this.context),this._median=rd(this.context),this._min=id(this.context),this._mode=sd(this.context),this._mult=ad(this.context),this._pinv=od(this.context),this._pow=ld(this.context),this._rank=cd(this.context),this._remove_col=ud(this.context),this._remove_row=hd(this.context),this._reshape=pd(this.context),this._reverse=dd(this.context),this._row=fd(this.context),this._rows=md(this.context),this._set=yd(this.context),this._sort=gd(this.context),this._submatrix=xd(this.context),this._sum=_d(this.context),this._swap_columns=bd(this.context),this._swap_rows=vd(this.context),this._trace=wd(this.context),this._transpose=Sd(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 vt(t){return(e,n,r)=>new le(e,n,r,t)}function Nd(t){return(e,n=0)=>y.from(e).get(n)}var os=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=vt(e),this.param=Nd(),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=vt(e),this.new_int=vt(e),this.new_string=vt(e),this.new_bool=vt(e),this.new_color=vt(e),this.new_line=vt(e),this.new_label=vt(e),this.new_box=vt(e),this.new_linefill=vt(e),this.new_table=vt(e)}},Id=Object.defineProperty,kd=(t,e,n)=>e in t?Id(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ad=(t,e,n)=>kd(t,typeof e!="symbol"?e+"":e,n),ls=class{constructor(e){this.context=e,Ad(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}},Md=Object.defineProperty,Td=(t,e,n)=>e in t?Md(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Gi=(t,e,n)=>Td(t,typeof e!="symbol"?e+"":e,n),He=class t{constructor(e,n,r){Gi(this,"time"),Gi(this,"index"),Gi(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 Pd(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}var io={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 He,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 He)&&!Pd(t)};function Ct(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(io.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=io[n[p]];typeof d=="function"&&d(l)?i[p]=l:a[u]=!1}}}return{...i,...s,...r}}var Dd=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/;function Rd(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(Dd);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 Od(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 Ld=Object.defineProperty,Fd=(t,e,n)=>e in t?Ld(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Vn=(t,e,n)=>Fd(t,typeof e!="symbol"?e+"":e,n);function cs(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 us(t,e){let n=Bd(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 Bd(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 on(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 Vd(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 Wd=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],$d={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},Zr=class{constructor(e,n="openTime"){Vn(this,"context"),Vn(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,Wd,$d),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=cs(s),u=cs(l),p;if(!c||c===u?p=o:p=us(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=Rd(n);if(!i)throw new et(`Invalid session specification: "${n}"`,"time");let s=on(e,r),a=s.hour*60+s.minute;return Od(i,a,s.dayOfWeek)}},jd=[[],["time"],["time","timezone"]],Ud={time:"number",timezone:"string"},Rt=class{constructor(e,n){Vn(this,"context"),Vn(this,"extractor"),Vn(this,"_cache",[]),Vn(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(on(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=e.map(o=>o instanceof y?o.get(0):o);if(n.length===0)return this.__value.get(0);let r=ye(n,jd,Ud),i=r.time;if(i===void 0||isNaN(i))return NaN;let s=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=on(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=>Vd(t.year,t.month,t.day),year:t=>t.year},zd=Object.defineProperty,qd=(t,e,n)=>e in t?zd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,so=(t,e,n)=>qd(t,typeof e!="symbol"?e+"":e,n),hs=class{constructor(e){this.context=e,so(this,"regular","regular"),so(this,"extended","extended")}get _timezone(){return this.context.pine?.syminfo?.timezone||"UTC"}_dayKey(e){let n=on(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}},Hd=Object.defineProperty,Kd=(t,e,n)=>e in t?Hd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Yd=(t,e,n)=>Kd(t,typeof e!="symbol"?e+"":e,n),rn=class t{constructor(e,n,r){this._definition=e,this.context=n,Yd(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 pl=Object.defineProperty,Gd=Object.getOwnPropertyDescriptor,Xd=(t,e,n)=>e in t?pl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dl=(t,e,n,r)=>{for(var i=r>1?void 0:r?Gd(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},Wn=(t,e,n)=>Xd(t,typeof e!="symbol"?e+"":e,n),Zd=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],Qd={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"],ef={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 tf(t){return ye(t,Jd,ef)}var lt=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}},Tn={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"},Qr=class{constructor(e){this.context=e,Wn(this,"_firedKeys",new Set),Wn(this,"_fallbackCounter",0),Wn(this,"_fallbackLastExecTick",-1)}get freq_all(){return Tn.freq_all}get freq_once_per_bar(){return Tn.freq_once_per_bar}get freq_once_per_bar_close(){return Tn.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):Tn.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===Tn.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===Tn.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})}};dl([M],Qr.prototype,"any",1);var Jr=class{constructor(e){this.context=e,Wn(this,"_acCounter",0),Wn(this,"_acLastExecTick",-1),Wn(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=tf(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,Zd,Qd);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 rn)){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 rn(a,this.context,i)},copy:function(s){return new rn(s.__def__,this.context,i)},_fieldDefaults:r,_definitionKeys:n};return i}};dl([M],Jr.prototype,"alertcondition",1);function fn(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 nf(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 fl(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]),fn(e)}function ps(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 rf(t){let e=fl(t);return e?ps(e[0],e[1],e[2],e[3]):t}function Pt(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 ds=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=Pt(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=Pt(e),n=Pt(n),r=Pt(r),i=Pt(i),s=Pt(s),e==null||typeof e=="number"&&isNaN(e))return NaN;if(n==null||typeof n=="number"&&isNaN(n))return NaN;if(r==null||typeof r=="number"&&isNaN(r))return NaN;if(i==null||typeof i=="number"&&isNaN(i))return NaN;if(s==null||typeof s=="number"&&isNaN(s))return NaN;let a=0;r!==n&&(a=(e-n)/(r-n)),a=Math.max(0,Math.min(1,a));let o=fn(typeof i=="string"?i:"#000000")||[0,0,0,1],l=fn(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 nf(c,u,p,h)}r(e){if(e=Pt(e),!e||typeof e!="string")return NaN;let n=fn(e);return n?n[0]:NaN}g(e){if(e=Pt(e),!e||typeof e!="string")return NaN;let n=fn(e);return n?n[1]:NaN}b(e){if(e=Pt(e),!e||typeof e!="string")return NaN;let n=fn(e);return n?n[2]:NaN}t(e){if(e=Pt(e),!e||typeof e!="string")return NaN;let n=fn(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}},oa=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]);function ml(t,e){if(!oa.has(e))return;let n=t?.data?.[e];if(n!=null)return y.from(n).get(0)}var sf=[["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"]],af={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"};function nt(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,sf,af);return e!==void 0&&(r.__varId=e),r}function ct(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 of(t){return(...e)=>{let n=nt(e),r=ct(t,n);if(typeof r=="string"&&typeof n.defval=="number"){let i=ml(t,r);if(i!==void 0)return i}return r}}function lf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function cf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function uf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function hf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function pf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function df(t){return(e,n=0)=>y.from(e).get(n)}function ff(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function mf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function yf(t){return(...e)=>{let n=nt(e),r=ct(t,n);if(typeof r=="string"){let i=ml(t,r);return i!==void 0?i:n.defval}return r}}function gf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function xf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function _f(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function bf(t){return(...e)=>{let n=nt(e);return ct(t,n)}}function vf(t){return(...e)=>nt(e).defval}var wf=Object.defineProperty,Sf=(t,e,n)=>e in t?wf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ze=(t,e,n)=>Sf(t,typeof e!="symbol"?e+"":e,n),Ef={any:of,bool:lf,color:cf,enum:uf,float:hf,int:pf,param:df,price:ff,session:mf,source:yf,string:gf,symbol:xf,text_area:_f,time:bf,timeframe:vf},fs=class{constructor(e){this.context=e,ze(this,"any"),ze(this,"bool"),ze(this,"color"),ze(this,"enum"),ze(this,"float"),ze(this,"int"),ze(this,"param"),ze(this,"price"),ze(this,"session"),ze(this,"source"),ze(this,"string"),ze(this,"symbol"),ze(this,"text_area"),ze(this,"time"),ze(this,"timeframe"),Object.entries(Ef).forEach(([n,r])=>{this[n]=r(e)})}};function Cf(t){return e=>Math.abs(y.from(e).get(0))}function Nf(t){return e=>Math.acos(y.from(e).get(0))}function If(t){return e=>Math.asin(y.from(e).get(0))}function kf(t){return e=>Math.atan(y.from(e).get(0))}function Af(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function Mf(t){return e=>Math.ceil(y.from(e).get(0))}function Tf(t){return e=>Math.cos(y.from(e).get(0))}function Pf(t){return()=>Math.E}function Df(t){return e=>Math.exp(y.from(e).get(0))}function Rf(t){return e=>Math.floor(y.from(e).get(0))}function Of(t){return e=>Math.log(y.from(e).get(0))}function Lf(t){return e=>Math.log(y.from(e).get(0))}function Ff(t){return e=>Math.log10(y.from(e).get(0))}function Bf(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.max(...n)}}function Vf(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.min(...n)}}function Wf(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 $f(t){return()=>1.618033988749895}function jf(t){return()=>Math.PI}function Uf(t){return(e,n)=>Math.pow(y.from(e).get(0),y.from(n).get(0))}function zf(t){return()=>Math.random()}var ao=t=>Number.isNaN(t)?NaN:Math.sign(t)*Math.round(Math.abs(t));function qf(t){return(e,n)=>{let r=y.from(e).get(0),i=n==null?0:y.from(n).get(0);if(!i)return ao(r);let s=10**i;return ao(r*s)/s}}function Hf(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Kf(t){return()=>.6180339887498948}function Yf(t){return e=>Math.sign(y.from(e).get(0))}function Gf(t){return e=>Math.sin(y.from(e).get(0))}function Xf(t){return e=>Math.sqrt(y.from(e).get(0))}function Zf(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 Qf(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 em(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(Math.PI/180)}}function tm(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 nm(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 rm(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 im(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 sm(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 am(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 om(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 lm=Object.defineProperty,cm=(t,e,n)=>e in t?lm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J=(t,e,n)=>cm(t,typeof e!="symbol"?e+"":e,n),um={abs:Cf,acos:Nf,asin:If,atan:kf,avg:Af,ceil:Mf,cos:Tf,e:Pf,exp:Df,floor:Rf,ln:Of,log:Lf,log10:Ff,max:Bf,min:Vf,param:Wf,phi:$f,pi:jf,pow:Uf,random:zf,round:qf,round_to_mintick:Hf,rphi:Kf,sign:Yf,sin:Gf,sqrt:Xf,sum:Zf,tan:Qf,todegrees:Jf,toradians:em,__eq:tm,__ge:nm,__gt:rm,__idiv:im,__le:sm,__lt:am,__neq:om},ms=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(um).forEach(([n,r])=>{this[n]=r(e)})}};function hm(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 pm=new Set(["heikinashi","standard"]);function yr(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 pm.has(n)?{symbol:t.slice(0,e),modifier:n}:{symbol:t,modifier:null}}function sn(t){return yr(t).symbol}function ys(t,e){return`${sn(t)};${e}`}var Un=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Tr={"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 ei(t){if(Un.includes(t))return t;if(Tr[t])return Tr[t];let e=t.toLowerCase();if(Tr[e])return Tr[e];let n=t.toUpperCase();return Un.includes(n)?n:t}function oo(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 lo(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 co=[["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"]],dm={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function la(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function fm(t,e){return t.map(n=>la(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Pn(t){return la(t)?t[0]:t}function mm(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(la(r))return r[1]}function gs(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(gs):t}function ym(t){return async(...e)=>{let n=[],r=fm(e,n),i=ye(r,co,dm),s=Pn(i.symbol),a=Pn(i.timeframe),o=Pn(i.expression),l=Pn(i.gaps),c=Pn(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"?yr(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=mm("expression",co,n,i.expression),w=l,N=c,E=w===!0||w==="gaps_on",A=N===!0||N==="lookahead_on",F=(()=>{let Le=Pn(i.calc_bars_count);return typeof Le=="number"&&Le>0?Le:void 0})();if(t.isSecondaryContext){let Le=gs(v);return Array.isArray(Le)?[Le]:Le}let I=Un.indexOf(ei(t.timeframe)),j=Un.indexOf(ei(b));if(I==-1||j==-1)throw new Error("Invalid timeframe");let P=typeof m=="string"?yr(m):{symbol:m,modifier:null},q=P.modifier==="standard"?null:P.modifier,B=!m||m===""||P.symbol===h.symbol&&q===d;if(I===j&&B){let Le=gs(v);return Array.isArray(Le)?[Le]:Le}let O=I>j,K=y.from(t.data.openTime).get(0),oe=y.from(t.data.closeTime).get(0),ke=t.idx===t.length-1&&oe>Date.now(),he=`${m}_${b}_${S}`,Ue=`${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 tr=Le.context,Mr=O?lo(K,oe,tr.data.openTime.data,tr.data.closeTime.data,A,t.eDate,E):oo(K,oe,tr.data.openTime.data,tr.data.closeTime.data,A,ke);if(Mr==-1)return NaN;let Mn=tr.params[S][Mr];if(!O&&E){let no=t.cache[Ue];return no!==void 0&&no===Mr?NaN:(t.cache[Ue]=Mr,Array.isArray(Mn)?[Mn]:Mn)}return Array.isArray(Mn)?[Mn]:Mn}let er=1e3*60*60*24*30,Ja=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),Xu=F?void 0:Ja?Ja-er:void 0,Zu=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),Ar=new un(t.source,m,b,F,Xu,Zu);Ar.markAsSecondary();let eo=typeof S=="string"?S:"",Qu=eo.match(/p\\d+$/)?.[0]??eo,to=t._ltfTruncatedBodies?.[Qu],An=to?await Ar.runPretranspiled(to):await Ar.run(t.pineTSCode);t.cache[he]={pineTS:Ar,context:An,dataVersion:t.dataVersion};let Ki=O?lo(K,oe,An.data.openTime.data,An.data.closeTime.data,A,t.eDate,E):oo(K,oe,An.data.openTime.data,An.data.closeTime.data,A,ke);if(Ki==-1)return NaN;let Yi=An.params[S][Ki];return!O&&E?(t.cache[Ue]=Ki,NaN):Array.isArray(Yi)?[Yi]:Yi}}var uo=[["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"]],gm={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function ca(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function xm(t,e){return t.map(n=>ca(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Dn(t){return ca(t)?t[0]:t}function _m(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(ca(r))return r[1]}function Rn(t){return typeof t=="number"?Y.float:typeof t=="boolean"?Y.bool:typeof t=="string"?Y.string:Y.any}var yl={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 xs(t,e){if(!(t instanceof y))return null;let n=e?.data;if(!n)return null;for(let r of Object.keys(yl))if(t===n[r])return r;return null}function bm(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof rn))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=xs(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:r,udt:n}}function vm(t,e){if(t===void 0)return null;if(Array.isArray(t)){let r=[];for(let i of t){let s=xs(i,e);if(s===null)return null;r.push(s)}return r.length>0?{kind:"tuple",builtinNames:r}:null}let n=xs(t,e);return n!==null?{kind:"series",builtinNames:[n]}:bm(t,e)}async function ho(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 un(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=>yl[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 rn(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function wm(t){return async(...e)=>{let n=[],r=xm(e,n),i=ye(r,uo,gm),s=Dn(i.symbol),a=Dn(i.timeframe),o=Dn(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=_m("expression",uo,n,i.expression);Dn(i.ignore_invalid_symbol);let m=Dn(i.ignore_invalid_timeframe),_=(()=>{let O=Dn(i.calc_bars_count);return typeof O=="number"&&O>0?O:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(O=>new X([O],Rn(O),t))]:new X([d],Rn(d),t);let b=Un.indexOf(ei(t.timeframe)),v=Un.indexOf(ei(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 X([O],Rn(O),t))]:new X([d],Rn(d),t);let S=`${u}_${h}_${f}_lower`,w=t._requestParamSources?.[f],N=vm(w,t);if(!t.cache[S])if(N!==null){let O=await ho(t,u,h,_,N,f);t.cache[S]={pineTS:null,context:O,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:N}}}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(),oe=new un(t.source,u,h,_,O,K);oe.markAsSecondary();let ke=typeof f=="string"?f:"",he=ke.match(/p\\d+$/)?.[0]??ke,Ue=t._ltfTruncatedBodies?.[he],er;Ue?er=await oe.runPretranspiled(Ue):er=await oe.run(t.pineTSCode),t.cache[S]={pineTS:oe,context:er,dataVersion:t.dataVersion}}let E=t.cache[S];if(t.dataVersion>E.dataVersion)if(E._fastPath){let O=await ho(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),I=y.from(t.data.closeTime).get(0),j=A.data.openTime.data,P=A.data.closeTime.data,q=A.params[f];if(!q)return Array.isArray(d)?[d.map(()=>new X([],Y.float,t))]:new X([],Y.float,t);let B=[];for(let O=0;O<j.length;O++){let K=j[O];if(!(P[O]<=F)){if(K>=I)break;K>=F&&K<I&&B.push(q[O])}}if(B.length>0&&Array.isArray(B[0])){let O=B[0].length,K=[];for(let oe=0;oe<O;oe++){let ke=B.map(Ue=>Ue[oe]),he=ke.length>0?Rn(ke[0]):Y.float;K.push(new X(ke,he,t))}return[K]}else{let O=B.length>0?Rn(B[0]):Y.float;return new X(B,O,t)}}}var Sm=Object.defineProperty,Em=(t,e,n)=>e in t?Sm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Pr=(t,e,n)=>Em(t,typeof e!="symbol"?e+"":e,n),Cm={param:hm,security:ym,security_lower_tf:wm},_s=class{constructor(e){this.context=e,Pr(this,"_cache",{}),Pr(this,"param"),Pr(this,"security"),Pr(this,"security_lower_tf"),Object.entries(Cm).forEach(([n,r])=>{this[n]=r(e)})}};function Nm(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 Im(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 km(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 Am(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 Mm(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 Tm(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 Pm(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 Dm(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 Rm(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 Om(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 Lm(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 Fm(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 Bm(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 Vm(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 Wm(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 $m(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 jm(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,N=o.prevPlusInitSum,E=o.prevMinusInitSum,A=o.prevSmoothedTR,F=o.prevSmoothedPlus,I=o.prevSmoothedMinus;if(S++,S<=i)w+=f,N+=b,E+=v,S===i&&(A=w/i,F=N/i,I=E/i);else{let he=1/i;A=he*f+(1-he)*A,F=he*b+(1-he)*F,I=he*v+(1-he)*I}if(o.currentInitCount=S,o.currentTrInitSum=w,o.currentPlusInitSum=N,o.currentMinusInitSum=E,o.currentSmoothedTR=A,o.currentSmoothedPlus=F,o.currentSmoothedMinus=I,S<i)return[[NaN,NaN,NaN]];let j=A===0?0:100*F/A,P=A===0?0:100*I/A,q=j+P,B=q===0?0:100*Math.abs(j-P)/q,O=o.prevAdxInitCount,K=o.prevDxInitSum,oe=o.prevADX,ke=NaN;if(O++,O<=s)K+=B,O===s&&(oe=K/s,ke=oe);else{let he=1/s;oe=he*B+(1-he)*oe,ke=oe}return o.currentAdxInitCount=O,o.currentDxInitSum=K,o.currentADX=oe,[[t.precision(j),t.precision(P),t.precision(ke)]]}}function Um(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 zm(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 qm(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 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=-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 Km(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 N=a-w;b+=_[w]*N,v+=N}let S=b/v;return t.precision(S)}}function Ym(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 Gm(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,N,E,A)=>{if(isNaN(E))return Object.assign(N,w),N.prevEma!==null?N.prevEma:NaN;let F=w.initCount,I=w.initSum,j=w.prevEma;if(F<A){if(I+=E,F++,N.initSum=I,N.initCount=F,N.prevEma=j,F===A){let B=I/A;return N.prevEma=B,B}return NaN}let P=2/(A+1),q=E*P+j*(1-P);return N.prevEma=q,N.initSum=I,N.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 Xm(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,N,E)=>{if(isNaN(N))return Object.assign(w,S),w.prevEma!==null?w.prevEma:NaN;let A=S.initCount,F=S.initSum,I=S.prevEma;if(A<E){if(F+=N,A++,w.initSum=F,w.initCount=A,w.prevEma=I,A===E){let q=F/E;return w.prevEma=q,q}return NaN}let j=2/(E+1),P=N*j+I*(1-j);return w.prevEma=P,w.initSum=F,w.initCount=A,P},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 Zm(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 N=s-1-w,E=u[w];h+=N,d+=E,f+=N*E,m+=N*N}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 Qm(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 ey(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 ty(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 ny(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 ry(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 iy(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 sy(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 ay(t){return(e,n,r)=>{let i=y.from(n).get(0);return t.pine.ta.change(e,i,r)}}function oy(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 ly(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 cy(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 uy(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 hy(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 py(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 dy(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 fy(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=dy(o,s,a),c=t.idx;return t.precision(l[c])}}function my(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 yy(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=my(o,s,a),c=t.idx;return t.precision(l[c])}}function gy(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 xy(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 _y(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 by(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 vy(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 wy(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 Sy(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 Ey(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),N=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,N)))),f++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function Cy(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 Ny(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 Iy(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 ky(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,N=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||S>w||h<w||(S=w),isNaN(o.prevUpperBand)||v<N||h>N||(v=N);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 Ay(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 My(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 Ty(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,N=l.prevEma1AbsValue;if(S++,S<=a?(w+=p,S===a&&(N=w/a)):N=p*f+N*(1-f),isNaN(v)||isNaN(N))return l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=S,l.currentEma1AbsSum=w,l.currentEma1AbsValue=N,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 I=l.prevEma2AbsCount,j=l.prevEma2AbsSum,P=l.prevEma2AbsValue;if(I++,I<=s?(j+=N,I===s&&(P=j/s)):P=N*m+P*(1-m),l.currentEma1PcCount=_,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=S,l.currentEma1AbsSum=w,l.currentEma1AbsValue=N,l.currentEma2PcCount=E,l.currentEma2PcSum=A,l.currentEma2PcValue=F,l.currentEma2AbsCount=I,l.currentEma2AbsSum=j,l.currentEma2AbsValue=P,isNaN(F)||isNaN(P))return NaN;if(P===0)return t.precision(0);let q=F/P;return t.precision(q)}}function Py(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 Dy(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 Ry(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=on(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 Oy(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 Ly(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 Fy(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 By(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 Vy(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 Wy=Object.defineProperty,$y=(t,e,n)=>e in t?Wy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,V=(t,e,n)=>$y(t,typeof e!="symbol"?e+"":e,n),jy={accdist:Nm,alma:Im,atr:km,barssince:Am,bb:Mm,bbw:Tm,cci:Pm,change:Dm,cmo:Rm,cog:Om,correlation:Lm,cross:Fm,crossover:Bm,crossunder:Vm,cum:Wm,dev:$m,dmi:jm,ema:Um,falling:zm,highest:qm,highestbars:Hm,hma:Km,iii:Ym,kc:Gm,kcw:Xm,linreg:Zm,lowest:Qm,lowestbars:Jm,macd:ey,max:ty,median:ny,mfi:ry,min:iy,mode:sy,mom:ay,nvi:oy,obv:ly,param:cy,percentile_linear_interpolation:uy,percentile_nearest_rank:hy,percentrank:py,pivothigh:fy,pivotlow:yy,pvi:gy,pvt:xy,range:_y,rising:by,rma:vy,roc:wy,rsi:Sy,sar:Ey,sma:Cy,stdev:Ny,stoch:Iy,supertrend:ky,swma:Ay,tr:My,tsi:Ty,valuewhen:Py,variance:Dy,vwap:Ry,vwma:Oy,wad:Ly,wma:Fy,wpr:By,wvad:Vy},bs=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,"max"),V(this,"median"),V(this,"mfi"),V(this,"min"),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(jy).forEach(([n,r])=>{this[n]=r(e)})}};function Uy(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 ir(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 ti(t,e,n,r){return Math.abs(t)*e*r*n/100}function zy(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of Ni(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 qy(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+=ti(s.size,e,a,r)}return i}function ua(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 Hy(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=_)}ni(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=an(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=an(c.direction);(h===1&&i>=c.stop||h===-1&&s<=c.stop)&&(u=!0,p=c.stop)}break}if(u){if(Yy(e,c)){c.status="cancelled";continue}let h=an(c.direction);p=vs(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=qy(t,r));let w=e.equity-S;if(ti(b,p,d,v)>w){let N=Math.min(Math.abs(f),c.qty);_&&N>0?(yn(t,N,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}}}Xy(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"),ni(t,a),og(t)}function an(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function gl(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 vs(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 xl(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 Ky(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 Yy(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 Gy(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 Dr(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=gl(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 I of l.pending_orders){if((I.category??"entry")!=="exit"||I.from_entry&&I.from_entry!==e)continue;let j;I.stop!==void 0?j=I.stop:I.loss!==void 0&&(j=n===1?i-I.loss*b:i+I.loss*b);let P;I.limit!==void 0?P=I.limit:I.profit!==void 0&&(P=n===1?i+I.profit*b:i-I.profit*b),n===1?(j!==void 0&&j>v&&(v=j),P!==void 0&&P<S&&(S=P)):(j!==void 0&&j<v&&(v=j),P!==void 0&&P>S&&(S=P))}let w=t.pine?.syminfo?.pointvalue??1,N=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,N)+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 I=Math.abs(A)*l.position_avg_price+r*i,j=Math.abs(F);l.position_avg_price=I/j,l.position_size=F}xl(l)}function Xy(t,e,n,r){let i=t.strategy,s=an(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(yn(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?(Dr(t,e.id,s,p,n,r,e.comment,!0),Dr(t,e.id,s,c-p,n,r,e.comment,!0)):Dr(t,e.id,s,c,n,r,e.comment,!0)}}else Dr(t,e.id,s,e.qty,n,r,e.comment)}function Zy(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 yn(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=gl(t,s,b,n),N=S?w/2:w,E=Zy(s,h,b);for(let A of E){let F=N*(A.qty/b),I=(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:I-A.commission-F};i?.triggerKind==="loss"&&(j.max_runup=0),i?.triggerKind==="profit"&&(j.max_drawdown=A.commission),s.netprofit+=I-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}}Gy(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,xl(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 Ni(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 Ni(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 ni(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of Ni(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 Qy(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 Ni(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 po(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],yn(t,Math.min(n,f),r,i,s);return}if(!e||e===""){yn(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],yn(t,p,r,i,s)}function Jy(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(P=>!c.from_entry||P.entry_id===c.from_entry);if(c._intended_trade_ids){let P=new Set(c._intended_trade_ids);u=u.filter(q=>P.has(q.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}let p=u.reduce((P,q)=>P+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 P=c.immediately?a:r;P=vs(t,-h,P);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)),po(t,c.from_entry,q,P,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=P,c.fill_bar=t.idx,c.fill_time=o;continue}let d=0;for(let P of u)d+=Math.abs(P.size)*P.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 P;c.trail_price!==void 0?P=c.trail_price:c.trail_points!==void 0&&(P=m?f+c.trail_points*l:f-c.trail_points*l),P!==void 0&&(m?i>=P:s<=P)&&(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,N=[],E=[],A=n._mc_exit_lock,F=A&&A.bar===t.idx;for(let P of u){if(F&&P.id!==A.tradeId)continue;let q=P._bracket_entry??P.entry_price,B=Math.abs(P.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 oe=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(oe&&ke?he=w?"profit":"loss":oe?he="profit":ke&&(he="loss"),he==="loss"){let Ue=m?r<=K:r>=K;!m&&Ue&&P.entry_bar_index===t.idx?oe&&(he="profit"):E.push({qty:B,price:Ue?r:K,kind:"loss",tradeId:P.id})}if(he==="profit"){let Ue=m?r>=O:r<=O;N.push({qty:B,price:Ue?r:O,kind:"profit",tradeId:P.id})}}N.sort((P,q)=>m?P.price-q.price:q.price-P.price),E.sort((P,q)=>m?q.price-P.price:P.price-q.price);let I=null;if(e==="intrabar"&&!F&&c.trail_armed&&c.trail_offset!==void 0){let P=()=>{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=>{I={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){P();let O=q();(m?s<=O:i>=O)&&B(O)}else{let O=q();if(m?s<=O:i>=O)B(O);else{P();let K=q();(m?a<=K:a>=K)&&B(K)}}}let j=w?[...N,...E,...I?[I]:[]]:[...E,...I?[I]:[],...N];if(j.length>0){let P=p;c.qty&&c.qty>0?P=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(P=p*(c.qty_percent/100));let q=()=>n.opentrades.filter(K=>!c.from_entry||K.entry_id===c.from_entry).reduce((K,oe)=>K+Math.abs(oe.size),0),B=NaN,O=!1;for(let K of j){if(P<=1e-9)break;let oe=q();if(oe<=1e-9)break;let ke=Math.min(K.qty===1/0?oe:K.qty,P,oe),he=vs(t,-h,K.price),Ue=K.kind==="profit"?c.comment_profit??c.comment:K.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;po(t,c.from_entry,ke,he,o,{triggerKind:K.kind,exitId:c.id,exitComment:Ue},K.tradeId),P-=ke,B=he,O=!0}O&&(q()<=1e-9||P<=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"),ni(t,a)}function eg(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)&&(yn(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&&an(r.direction)===n.dir&&(r.status="cancelled");e.pending_orders=e.pending_orders.filter(r=>r.status==="pending")}}function tg(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 Xi(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=zy(t,p),f=ti(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],N=Math.abs(w.size),E=w.entry_price;if(yn(t,v,p,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&v>=N-1e-9&&Math.abs(n.position_size)>1e-9){let F=ti(N,p,i,u),I=N*(p-E)*r*u,j=m-F+I;if(j>0){let P=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:P,time:c,dir:r})}}let A=S.find(F=>F.status==="open");n._mc_exit_lock={bar:t.idx,tradeId:A?.id??null}}}function ng(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);ni(t,i),Qy(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 rg(t){let e=t?.strategy;if(!e)return;e.cagr=sg(t),ag(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 ig=1440*60*1e3;function sg(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)/ig;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 ag(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 og(t){t.strategy}function lg(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 sr(t){if(Array.isArray(t))return t.map(sr);if(t instanceof Map){let e=new Map;return t.forEach((n,r)=>e.set(r,sr(n))),e}if(t!==null&&typeof t=="object"){let e={};for(let n of Object.keys(t))e[n]=sr(t[n]);return e}return t}function cg(t){if(!t)return null;let e={};for(let n of Object.keys(t))n==="config"||n==="closedtrades"||(e[n]=sr(t[n]));return{fields:e,closedtradesLength:t.closedtrades.length}}function ug(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]=sr(e.fields[n])}}function hg(t){return(...e)=>{let n=Uy(e);return t.strategy?t.strategy.config={...t.strategy.config,...n,...t._propOverrides??{}}:lg(t,n),t.strategy.config}}var pg=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],dg={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 fg(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let n=ye(e,pg,dg),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=an(s),d=y.from(t.data.close).get(0),f=ua(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 mg(t){return(e,n)=>y.from(e).get(n||0)}function yg(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 gg(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 xg(t){return()=>t.strategy?.netprofit??0}function _g(t){return()=>t.strategy?.position_size??0}function bg(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function vg(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function wg(t){return()=>"long"}function Sg(t){return()=>"short"}function Eg(t){return()=>"cash"}function Cg(t){return()=>"percent_of_equity"}function Ng(t){return()=>"fixed"}function Ig(t){return()=>t.strategy?.openprofit??0}function kg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function Ag(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function Mg(t){return()=>t.strategy?.grossprofit??0}function Tg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function Pg(t){return()=>t.strategy?.grossloss??0}function Dg(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function Rg(t){return()=>t.strategy?.wintrades??0}function Og(t){return()=>t.strategy?.losstrades??0}function Lg(t){return()=>t.strategy?.eventrades??0}function Fg(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function Bg(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 Vg(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function Wg(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 $g(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function jg(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 Ug(t){return()=>t.strategy?.max_drawdown??0}function zg(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function qg(t){return()=>t.strategy?.max_runup??0}function Hg(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function Kg(t){return()=>t.strategy?.max_contracts_held_all??0}function Yg(t){return()=>t.strategy?.max_contracts_held_long??0}function Gg(t){return()=>t.strategy?.max_contracts_held_short??0}function Xg(t){return()=>t.strategy?.position_entry_name??""}function Zg(t){return()=>t.strategy?.initial_capital??0}function Qg(t){return()=>t.strategy?.account_currency??"USD"}function Jg(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 e0=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],t0={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 n0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let n=ye(e,e0,t0),r=I=>I==null||typeof I=="string"||typeof I=="number"||typeof I=="boolean"?I:typeof I=="function"?I():I instanceof y?I.get(0):Array.isArray(I)?I[I.length-1]:typeof I=="object"&&I.get!==void 0?I.get(0):I,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=an(s),d=t.strategy,f=d.position_size;for(let I of d.pending_orders)I.bar===t.idx&&I.category==="entry"&&I.type==="market"&&(f+=an(I.direction)*I.qty);if(Math.sign(f)===h&&f!==0&&Ky(d,h))return;let m=y.from(t.data.close).get(0),_=ua(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,N=o!==void 0?ir(o,m,w):void 0,E=l!==void 0?ir(l,m,w):void 0,A=y.from(t.data.openTime).get(0),F={id:i,direction:h,qty:v,type:S,limit:N,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 r0=[["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"]],i0={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 s0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let n=Ct(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,r0,i0),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?ir(u,b,_):void 0,S=h!==void 0?ir(h,b,_):void 0,w=d!==void 0?ir(d,b,_):void 0,N=a??"",E=!!(N?t.strategy.pending_orders.find(B=>B.category==="entry"&&B.id===N&&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),I=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:N,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:I,_callsiteId:n},P=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===P&&(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 a0=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],o0={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function l0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let n=ye(e,a0,o0),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 c0=[["comment","alert_message","immediately","disable_alert"]],u0={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function h0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let n=ye(e,c0,u0);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 p0=[["id","immediately"]],d0={id:"string",immediately:"boolean"};function f0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let n=ye(e,p0,d0).id;n!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===n)))}}function m0(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 y0(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 g0(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function x0(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function _0(t){return e=>t.strategy?ua(t,void 0,1,e):0}var b0={any:hg,order:fg,param:mg,opentrades:yg,closedtrades:gg,netprofit:xg,position_size:_g,position_avg_price:bg,equity:vg,long:wg,short:Sg,cash:Eg,percent_of_equity:Cg,fixed:Ng,openprofit:Ig,openprofit_percent:kg,netprofit_percent:Ag,grossprofit:Mg,grossprofit_percent:Tg,grossloss:Pg,grossloss_percent:Dg,wintrades:Rg,losstrades:Og,eventrades:Lg,avg_trade:Fg,avg_trade_percent:Bg,avg_winning_trade:Vg,avg_winning_trade_percent:Wg,avg_losing_trade:$g,avg_losing_trade_percent:jg,max_drawdown:Ug,max_drawdown_percent:zg,max_runup:qg,max_runup_percent:Hg,max_contracts_held_all:Kg,max_contracts_held_long:Yg,max_contracts_held_short:Gg,position_entry_name:Xg,initial_capital:Zg,account_currency:Qg,margin_liquidation_price:Jg,entry:n0,exit:s0,close:l0,close_all:h0,cancel:f0,cancel_all:m0,convert_to_account:g0,convert_to_symbol:x0,default_entry_qty:_0},v0={long:"long",short:"short",all:"all"},w0={none:"none",cancel:"cancel",reduce:"reduce"},S0={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},ws=class{constructor(e){this.context=e,Object.entries(b0).forEach(([r,i])=>{this[r]=i(e)}),this.direction=()=>v0,this.oca=()=>w0,this.commission=()=>S0;let n=y0(e);this.risk=()=>n}};function E0(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=on(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 C0(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 Ss=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=E0(e,n);return C0(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)}`)}},Es=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 et(typeof n=="string"?n:String(n??""),"runtime.error")}},N0=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],I0=["January","February","March","April","May","June","July","August","September","October","November","December"],k0=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A0=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],st=(t,e)=>String(t).padStart(e,"0"),Cs=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 X(String(e).split(n),Y.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=on(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?st(a.year%100,2):m>=4?st(a.year,4):String(a.year);break;case"M":m>=4?h+=I0[a.month-1]:m===3?h+=N0[a.month-1]:m===2?h+=st(a.month,2):h+=String(a.month);break;case"d":h+=m===2?st(a.day,2):String(a.day);break;case"D":h+=m>=3?st(u,3):m===2?st(u,2):String(u);break;case"E":h+=m>=4?A0[a.dayOfWeek]:k0[a.dayOfWeek];break;case"a":h+=a.hour<12?"AM":"PM";break;case"h":h+=m===2?st(p,2):String(p);break;case"H":h+=m===2?st(a.hour,2):String(a.hour);break;case"m":h+=m===2?st(a.minute,2):String(a.minute);break;case"s":h+=m===2?st(a.second,2):String(a.second);break;case"S":{let _=i-Math.floor(i/1e3)*1e3;h+=st(_,3).substring(0,m);break}case"Z":{let _=l>=0?"+":"-",b=Math.abs(l);h+=`${_}${st(Math.floor(b/60),2)}${st(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)})}},M0=Object.defineProperty,T0=(t,e,n)=>e in t?M0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,P0=(t,e,n)=>T0(t,typeof e!="symbol"?e+"":e,n),Rr={"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 fo(t){if(!t||/^\\d+$/.test(t))return t;if(Rr[t])return Rr[t];let e=t.toLowerCase();if(Rr[e])return Rr[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 Ns=class{constructor(e){this.context=e,P0(this,"_normalized",null)}param(e,n=0,r){return y.from(e).get(n)}get normalized(){return this._normalized===null&&(this._normalized=fo(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=cs(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=us(s,i),l=us(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=fo(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}},D0=Object.defineProperty,R0=Object.getOwnPropertyDescriptor,Ot=(t,e,n,r)=>{for(var i=r>1?void 0:r?R0(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&&D0(e,n,i),i},O0=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],L0=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],F0={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"},B0=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],V0=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],W0=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],$0=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],mo=["color","offset","editable","show_last","title","display","force_overlay"],j0=["price","title","color","linestyle","linewidth","editable","display"],U0=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],z0={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"},q0={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"},H0={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"},K0={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"},Y0={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"},yo={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},G0={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},X0={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},Nt=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=Ct(e),r=ye(e,L0,F0),{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=Ct(e),r=ye(e,O0,z0),{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=Ct(e),r=ye(e,B0,q0),{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=Ct(e),r=ye(e,V0,H0),{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=Ct(e),r=ye(e,W0,K0),{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=Ct(e),r=ye(e,$0,Y0),{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=Ct(e),r=ye(e,mo,yo),{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=Ct(e),r=ye(e,mo,yo),{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]}};Ot([M],Nt.prototype,"plotchar",1),Ot([M],Nt.prototype,"any",1),Ot([M],Nt.prototype,"plotshape",1),Ot([M],Nt.prototype,"plotarrow",1),Ot([M],Nt.prototype,"plotbar",1),Ot([M],Nt.prototype,"plotcandle",1),Ot([M],Nt.prototype,"bgcolor",1),Ot([M],Nt.prototype,"barcolor",1);var ri=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=Ct(e),r=ye(e,j0,G0),{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)}};Ot([M],ri.prototype,"any",1);var ii=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=Ct(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,U0,X0),{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:_}})}}};Ot([M],ii.prototype,"any",1);var Z0=Object.defineProperty,Q0=(t,e,n)=>e in t?Z0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J0=(t,e,n)=>Q0(t,typeof e!="symbol"?e+"":e,n),Is=class{constructor(e){this.context=e,J0(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 He(r(i),r(s),r(a)??NaN)},from_index(i,s){return new He(void 0,r(i),r(s))},from_time(i,s){return new He(r(i),void 0,r(s))},copy(i){return i.copy()},now(i){let s=n.idx,a=n.marketData[s]?.openTime;return new He(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}},ex=Object.defineProperty,tx=(t,e,n)=>e in t?ex(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fe=(t,e,n)=>tx(t,typeof e!="symbol"?e+"":e,n),nx=0,ar=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=nx++,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}}},_l=Object.defineProperty,rx=Object.getOwnPropertyDescriptor,ix=(t,e,n)=>e in t?_l(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?rx(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&&_l(e,n,i),i},sx=(t,e,n)=>ix(t,typeof e!="symbol"?e+"":e,n),ax=[["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"]],ox={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,sx(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 lt)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 ar(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,ax,ox),r,i,s=n.xloc;if(n.point instanceof He){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 lt||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)}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 lx=Object.defineProperty,cx=(t,e,n)=>e in t?lx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xe=(t,e,n)=>cx(t,typeof e!="symbol"?e+"":e,n),ux=0,or=class t{constructor(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){Xe(this,"id"),Xe(this,"x1"),Xe(this,"y1"),Xe(this,"x2"),Xe(this,"y2"),Xe(this,"xloc"),Xe(this,"extend"),Xe(this,"color"),Xe(this,"style"),Xe(this,"width"),Xe(this,"force_overlay"),Xe(this,"_deleted"),Xe(this,"_helper"),Xe(this,"_createdAtBar",-1),this.id=ux++,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}}},bl=Object.defineProperty,hx=Object.getOwnPropertyDescriptor,px=(t,e,n)=>e in t?bl(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?hx(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&&bl(e,n,i),i},dx=(t,e,n)=>px(t,typeof e!="symbol"?e+"":e,n),fx=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],mx={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,dx(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 lt?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 or(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,fx,mx),r,i,s,a,o=n.xloc;if(n.first_point instanceof He){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 He?(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 lt||typeof n=="number"&&isNaN(n))return null;if(n instanceof or)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof or)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 yx=Object.defineProperty,gx=(t,e,n)=>e in t?yx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,we=(t,e,n)=>gx(t,typeof e!="symbol"?e+"":e,n),xx=0,lr=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){we(this,"id"),we(this,"left"),we(this,"top"),we(this,"right"),we(this,"bottom"),we(this,"xloc"),we(this,"extend"),we(this,"border_color"),we(this,"border_style"),we(this,"border_width"),we(this,"bgcolor"),we(this,"text"),we(this,"text_color"),we(this,"text_size"),we(this,"text_halign"),we(this,"text_valign"),we(this,"text_wrap"),we(this,"text_font_family"),we(this,"text_formatting"),we(this,"force_overlay"),we(this,"_deleted"),we(this,"_helper"),we(this,"_createdAtBar",-1),this.id=xx++,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)}},vl=Object.defineProperty,_x=Object.getOwnPropertyDescriptor,bx=(t,e,n)=>e in t?vl(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?_x(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&&vl(e,n,i),i},vx=(t,e,n)=>bx(t,typeof e!="symbol"?e+"":e,n),wx=[["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"]],Sx={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,vx(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 lt?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 lr(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,wx,Sx),r,i,s,a,o=n.xloc;if(n.top_left instanceof He){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 He?(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 lt||typeof n=="number"&&isNaN(n))return null;if(n instanceof lr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof lr)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 Ex=Object.defineProperty,Cx=(t,e,n)=>e in t?Ex(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,On=(t,e,n)=>Cx(t,typeof e!="symbol"?e+"":e,n),Nx=0,si=class{constructor(e,n,r){On(this,"id"),On(this,"line1"),On(this,"line2"),On(this,"color"),On(this,"_deleted"),On(this,"_createdAtBar",-1),this.id=Nx++,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}}},wl=Object.defineProperty,Ix=Object.getOwnPropertyDescriptor,kx=(t,e,n)=>e in t?wl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Zi=(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&&wl(e,n,i),i},Ax=(t,e,n)=>kx(t,typeof e!="symbol"?e+"":e,n),$n=class{constructor(e){this.context=e,Ax(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 lt?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 si(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 lt||typeof n=="number"&&isNaN(n)?null:n instanceof si?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()}};Zi([M],$n.prototype,"new",1),Zi([M],$n.prototype,"set_color",1),Zi([M],$n.prototype,"delete",1);var Mx=Object.defineProperty,Tx=(t,e,n)=>e in t?Mx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ht=(t,e,n)=>Tx(t,typeof e!="symbol"?e+"":e,n),Px=0,cr=class{constructor(e,n=!1,r=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){ht(this,"id"),ht(this,"points"),ht(this,"curved"),ht(this,"closed"),ht(this,"xloc"),ht(this,"line_color"),ht(this,"fill_color"),ht(this,"line_style"),ht(this,"line_width"),ht(this,"force_overlay"),ht(this,"_deleted"),ht(this,"_createdAtBar",-1),this.id=Px++,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}}},Sl=Object.defineProperty,Dx=Object.getOwnPropertyDescriptor,Rx=(t,e,n)=>e in t?Sl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,go=(t,e,n,r)=>{for(var i=r>1?void 0:r?Dx(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&&Sl(e,n,i),i},Ox=(t,e,n)=>Rx(t,typeof e!="symbol"?e+"":e,n),gr=class{constructor(e){this.context=e,Ox(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 lt?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 He):[]}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 He);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 cr(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 lt||typeof n=="number"&&isNaN(n))return null;if(n instanceof cr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof cr)return r}return null}return this.new(...e)}delete(e){e&&(e._deleted=!0)}get all(){return this._polylines.filter(e=>!e._deleted)}rollbackFromBar(e){this._polylines=this._polylines.filter(n=>n._createdAtBar<e),this.syncToPlot()}};go([M],gr.prototype,"new",1),go([M],gr.prototype,"delete",1);var Lx=Object.defineProperty,Fx=(t,e,n)=>e in t?Lx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ze=(t,e,n)=>Fx(t,typeof e!="symbol"?e+"":e,n),Bx=0;function $e(t){return Number.isFinite(t)?Math.trunc(t):NaN}var xr=class{constructor(e="top_right",n=1,r=1,i="",s="",a=0,o="",l=0,c=!1){Ze(this,"id"),Ze(this,"position"),Ze(this,"columns"),Ze(this,"rows"),Ze(this,"bgcolor"),Ze(this,"frame_color"),Ze(this,"frame_width"),Ze(this,"border_color"),Ze(this,"border_width"),Ze(this,"force_overlay"),Ze(this,"_deleted"),Ze(this,"cells"),Ze(this,"merges"),Ze(this,"_helper"),this.id=Bx++,this.position=e,this.columns=$e(n),this.rows=$e(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=$e(e),n=$e(n),!(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 e=$e(e),n=$e(n),n>=0&&n<this.rows&&e>=0&&e<this.columns?this.cells[n][e]:null}clearCell(e,n){e=$e(e),n=$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}}},El=Object.defineProperty,Vx=Object.getOwnPropertyDescriptor,Wx=(t,e,n)=>e in t?El(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?Vx(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&&El(e,n,i),i},$x=(t,e,n)=>Wx(t,typeof e!="symbol"?e+"":e,n),jx=["position","columns","rows","bgcolor","frame_color","frame_width","border_color","border_width","force_overlay"],Ux=["column","row","text","width","height","text_color","text_halign","text_valign","text_size","bgcolor","tooltip","text_font_family"],xo=["start_column","start_row","end_column","end_row"];function Or(t,e){return!!t&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof xr)&&e.some(n=>n in t)}var _e=class{constructor(e){this.context=e,$x(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(Or(p,jx)){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 xr(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 xr?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(Or(m,Ux)){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(Or(o,xo)){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=$e(this._resolve(r)??0),u=$e(this._resolve(i)??0),p=$e(this._resolve(s)??c),h=$e(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(Or(o,xo)){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=$e(this._resolve(r)??0),u=$e(this._resolve(i)??0),p=$e(this._resolve(s)??0),h=$e(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.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 ks=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=sn(this._coerce(n)),{modifier:s}=yr(r);return s&&s!=="standard"?ys(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?sn(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):sn(this._coerce(e))}heikinashi(e){return ys(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)}},zx=Object.defineProperty,qx=(t,e,n)=>e in t?zx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Z=(t,e,n)=>qx(t,typeof e!="symbol"?e+"":e,n),As=class Ur{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 Jr(this),p={Type:u.Type.bind(u),na:new lt,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new Qr(this),error:u.error.bind(u),max_bars_back:u.max_bars_back.bind(u),timestamp:u.timestamp.bind(u),time:new Zr(this,"openTime"),time_close:new Zr(this,"closeTime"),dayofmonth:new Rt(this,en.dayofmonth),dayofweek:new Rt(this,en.dayofweek),hour:new Rt(this,en.hour),minute:new Rt(this,en.minute),month:new Rt(this,en.month),second:new Rt(this,en.second),weekofyear:new Rt(this,en.weekofyear),year:new Rt(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 fs(this),ta:new bs(this),math:new ms(this),request:new _s(this),array:new ss(this),map:new as(this),matrix:new os(this),ticker:new ks(this),strategy:new ws(this),syminfo:null,timeframe:new Ns(this),barstate:new ls(this),session:new hs(this),get bar_index(){return h.data.bar_index},get last_bar_index(){let I=h.marketData;return Array.isArray(I)&&I.length>0?I.length-1:h.data.close.length-1},get last_bar_time(){let I=h.marketData;return Array.isArray(I)&&I.length>0?I[I.length-1].openTime:h.data.openTime.get(0)},get timenow(){return new Date().getTime()},get time_tradingday(){let I=y.from(h.data.closeTime).get(0);if(isNaN(I))return NaN;let j=h.pine?.syminfo?.timezone||"UTC",P=on(I,j);return Date.UTC(P.year,P.month-1,P.day,0,0,0)},get inputs(){return h.inputs},log:new Ss(this),runtime:new Es(this),str:new Cs(this),...p,...qh};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 Nt(this),m=new ri(this),_=new ii(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 Is(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 I=h.marketData;return Array.isArray(I)&&I.length>0?I[0].openTime:NaN},get right_visible_bar_time(){if(h.viewportRight!==void 0)return h.viewportRight;let I=h.marketData;return Array.isArray(I)&&I.length>0?I[I.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 N=new $n(this);this.bindContextObject(N,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>N.all});let E=new gr(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,N,E,A];let F=new ds(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 rn){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?Ur.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}`;Ur._deprecationWarningsShown.has(r)||(Ur._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(As,"_deprecationWarningsShown",new Set),Z(As,"PRECISION_EPSILON",10**10);var zn=As,Hx=[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],Cl=[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],Kx="\\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",Nl="\\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",Qi={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"},Ji="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",Yx={5:Ji,"5module":Ji+" export import",6:Ji+" const class extends export import super"},Il=/^in(stanceof)?$/,Gx=new RegExp("["+Nl+"]"),Xx=new RegExp("["+Nl+Kx+"]");function Ms(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 jt(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&Gx.test(String.fromCharCode(t)):e===!1?!1:Ms(t,Cl)}function ln(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&&Xx.test(String.fromCharCode(t)):e===!1?!1:Ms(t,Cl)||Ms(t,Hx)}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 pt(t,e){return new ie(t,{beforeExpr:!0,binop:e})}var dt={beforeExpr:!0},Qe={startsExpr:!0},ha={};function ne(t,e){return e===void 0&&(e={}),e.keyword=t,ha[t]=new ie(t,e)}var g={num:new ie("num",Qe),regexp:new ie("regexp",Qe),string:new ie("string",Qe),name:new ie("name",Qe),privateId:new ie("privateId",Qe),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(",",dt),semi:new ie(";",dt),colon:new ie(":",dt),dot:new ie("."),question:new ie("?",dt),questionDot:new ie("?."),arrow:new ie("=>",dt),template:new ie("template"),invalidTemplate:new ie("invalidTemplate"),ellipsis:new ie("...",dt),backQuote:new ie("`",Qe),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:pt("||",1),logicalAND:pt("&&",2),bitwiseOR:pt("|",3),bitwiseXOR:pt("^",4),bitwiseAND:pt("&",5),equality:pt("==/!=/===/!==",6),relational:pt("</>/<=/>=",7),bitShift:pt("<</>>/>>>",8),plusMin:new ie("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:pt("%",10),star:pt("*",10),slash:pt("/",10),starstar:new ie("**",{beforeExpr:!0}),coalesce:pt("??",1),_break:ne("break"),_case:ne("case",dt),_catch:ne("catch"),_continue:ne("continue"),_debugger:ne("debugger"),_default:ne("default",dt),_do:ne("do",{isLoop:!0,beforeExpr:!0}),_else:ne("else",dt),_finally:ne("finally"),_for:ne("for",{isLoop:!0}),_function:ne("function",Qe),_if:ne("if"),_return:ne("return",dt),_switch:ne("switch"),_throw:ne("throw",dt),_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",Qe),_super:ne("super",Qe),_class:ne("class",Qe),_extends:ne("extends",dt),_export:ne("export"),_import:ne("import",Qe),_null:ne("null",Qe),_true:ne("true",Qe),_false:ne("false",Qe),_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})},tt=/\\r\\n?|\\n|\\u2028|\\u2029/,Zx=new RegExp(tt.source,"g");function qn(t){return t===10||t===13||t===8232||t===8233}function kl(t,e,n){n===void 0&&(n=t.length);for(var r=e;r<n;r++){var i=t.charCodeAt(r);if(qn(i))return r<n-1&&i===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var Al=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,je=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,Ml=Object.prototype,Qx=Ml.hasOwnProperty,Jx=Ml.toString,Hn=Object.hasOwn||(function(t,e){return Qx.call(t,e)}),_o=Array.isArray||(function(t){return Jx.call(t)==="[object Array]"}),bo=Object.create(null);function nn(t){return bo[t]||(bo[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function Xt(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var e_=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,_r=function(t,e){this.line=t,this.column=e};_r.prototype.offset=function(t){return new _r(this.line,this.column+t)};var Ii=function(t,e,n){this.start=e,this.end=n,t.sourceFile!==null&&(this.source=t.sourceFile)};function Tl(t,e){for(var n=1,r=0;;){var i=kl(t,r,e);if(i<0)return new _r(n,e-r);++n,r=i}}var Ts={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},vo=!1;function t_(t){var e={};for(var n in Ts)e[n]=t&&Hn(t,n)?t[n]:Ts[n];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!vo&&typeof console=="object"&&console.warn&&(vo=!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),_o(e.onToken)){var r=e.onToken;e.onToken=function(i){return r.push(i)}}if(_o(e.onComment)&&(e.onComment=n_(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function n_(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 Ii(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var gn=1,_n=2,pa=4,Pl=8,da=16,Dl=32,ki=64,Rl=128,bn=256,wr=512,Ol=1024,Ai=gn|_n|bn;function fa(t,e){return _n|(t?pa:0)|(e?Pl:0)}var ai=0,ma=1,Qt=2,Ll=3,Fl=4,Bl=5,Re=function(t,e,n){this.options=t=t_(t),this.sourceFile=t.sourceFile,this.keywords=nn(Yx[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var r="";t.allowReserved!==!0&&(r=Qi[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(r+=" await")),this.reservedWords=nn(r);var i=(r?r+" ":"")+Qi.strict;this.reservedWordsStrict=nn(i),this.reservedWordsStrictBind=nn(i+" "+Qi.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(tt).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"?_n:gn),this.regexpState=null,this.privateNameStack=[]},gt={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)};gt.inFunction.get=function(){return(this.currentVarScope().flags&_n)>0};gt.inGenerator.get=function(){return(this.currentVarScope().flags&Pl)>0};gt.inAsync.get=function(){return(this.currentVarScope().flags&pa)>0};gt.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(bn|wr))return!1;if(n&_n)return(n&pa)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};gt.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&gn)};gt.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&ki)>0||this.options.allowSuperOutsideMethod};gt.allowDirectSuper.get=function(){return(this.currentThisScope().flags&Rl)>0};gt.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};gt.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(bn|wr)||n&_n&&!(n&da))return!0}return!1};gt.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Ol||!this.inModule&&e&gn)};gt.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&bn)>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,gt);var Ye=Re.prototype,r_=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;Ye.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){je.lastIndex=t,t+=je.exec(this.input)[0].length;var e=r_.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){je.lastIndex=t+e[0].length;var n=je.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===";"||i==="}"||tt.test(n[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,je.lastIndex=t,t+=je.exec(this.input)[0].length,this.input[t]===";"&&t++}};Ye.eat=function(t){return this.type===t?(this.next(),!0):!1};Ye.isContextual=function(t){return this.type===g.name&&this.value===t&&!this.containsEsc};Ye.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};Ye.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};Ye.canInsertSemicolon=function(){return this.type===g.eof||this.type===g.braceR||tt.test(this.input.slice(this.lastTokEnd,this.start))};Ye.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};Ye.semicolon=function(){!this.eat(g.semi)&&!this.insertSemicolon()&&this.unexpected()};Ye.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};Ye.expect=function(t){this.eat(t)||this.unexpected()};Ye.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var Mi=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};Ye.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")}};Ye.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")};Ye.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")};Ye.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 ya={kind:"loop"},i_={kind:"switch"};$.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;je.lastIndex=this.pos;var e=je.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(jt(r)){var i=n;do n+=r<=65535?1:2;while(ln(r=this.fullCharCodeAt(n)));if(r===92)return!0;var s=this.input.slice(i,n);if(!Il.test(s))return!0}return!1};$.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;je.lastIndex=this.pos;var t=je.exec(this.input),e=this.pos+t[0].length,n;return!tt.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(ln(n=this.fullCharCodeAt(e+8))||n===92))};$.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;je.lastIndex=this.pos;var n=je.exec(this.input),r=this.pos+n[0].length;if(tt.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||ln(s=this.fullCharCodeAt(i))||s===92)return!1;je.lastIndex=i;var a=je.exec(this.input);if(r=i+a[0].length,a&&tt.test(this.input.slice(i,r)))return!1}var o=this.fullCharCodeAt(r);if(!jt(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(ln(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(Il.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){je.lastIndex=this.pos;var a=je.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(ya),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(ya),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 Mi,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,ur|(n?0:Ps),!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(i_),this.enterScope(Ol);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(),tt.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 s_=[];$.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?Dl:0),this.checkLValPattern(t,e?Fl:Qt),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(ya),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"?ma:Qt,!1)};var ur=1,Ps=2,Vl=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&Ps&&this.unexpected(),t.generator=this.eat(g.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&ur&&(t.id=e&Vl&&this.type!==g.name?null:this.parseIdent(),t.id&&!(e&Ps)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?ma:Qt:Ll));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(fa(t.async,t.generator)),e&ur||(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&ur?"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"&&a_(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&&oi(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&&oi(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 oi(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&oi(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(g.eq)?(this.enterScope(wr|ki),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(bn|ki);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,Qt,!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];Hn(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function a_(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 oi(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,ur|Vl,!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),Hn(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=s_,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,Qt),this.finishNode(t,"ImportSpecifier")};$.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,Qt),this.finishNode(t,"ImportDefaultSpecifier")};$.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,Qt),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;Hn(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 e_.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 xt=Re.prototype;xt.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};xt.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};xt.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};xt.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")};xt.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()};xt.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};xt.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};xt.parseBindingListItem=function(t){return t};xt.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")};xt.checkLValSimple=function(t,e,n){e===void 0&&(e=ai);var r=e!==ai;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===Qt&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),n&&(Hn(n,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),n[t.name]=!0),e!==Bl&&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")}};xt.checkLValPattern=function(t,e,n){switch(e===void 0&&(e=ai),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)}};xt.checkLValInnerPattern=function(t,e,n){switch(e===void 0&&(e=ai),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 wt=function(t,e,n,r,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!n,this.override=r,this.generator=!!i},ve={b_stat:new wt("{",!1),b_expr:new wt("{",!0),b_tmpl:new wt("${",!1),p_stat:new wt("(",!1),p_expr:new wt("(",!0),q_tmpl:new wt("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new wt("function",!1),f_expr:new wt("function",!0),f_expr_gen:new wt("function",!0,!1,null,!0),f_gen:new wt("function",!1,!1,null,!0)},Kn=Re.prototype;Kn.initialContext=function(){return[ve.b_stat]};Kn.curContext=function(){return this.context[this.context.length-1]};Kn.braceIsBlock=function(t){var e=this.curContext();return e===ve.f_expr||e===ve.f_stat?!0:t===g.colon&&(e===ve.b_stat||e===ve.b_expr)?!e.isExpr:t===g._return||t===g.name&&this.exprAllowed?tt.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===ve.b_stat:t===g._var||t===g._const||t===g.name?!1:!this.exprAllowed};Kn.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};Kn.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};Kn.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===ve.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)?ve.b_stat:ve.b_expr),this.exprAllowed=!0};g.dollarBraceL.updateContext=function(){this.context.push(ve.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?ve.p_stat:ve.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()!==ve.p_stat)&&!(t===g._return&&tt.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===g.colon||t===g.braceL)&&this.curContext()===ve.b_stat)?this.context.push(ve.f_expr):this.context.push(ve.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()===ve.q_tmpl?this.context.pop():this.context.push(ve.q_tmpl),this.exprAllowed=!1};g.star.updateContext=function(t){if(t===g._function){var e=this.context.length-1;this.context[e]===ve.f_expr?this.context[e]=ve.f_expr_gen:this.context[e]=ve.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 G=Re.prototype;G.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}};G.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};G.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 Mi,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};G.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};G.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)};G.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};G.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")};G.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"&&Wl(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Ds(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 Wl(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&Wl(t.expression)}function Ds(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&Ds(t.expression)||t.type==="ParenthesizedExpression"&&Ds(t.expression)}G.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};G.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}};G.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(g.arrow)};G.parseSubscriptAsyncArrow=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!0,r)};G.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 Mi,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};G.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(ve.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(ve.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()}};G.parseExprAtomDefault=function(){this.unexpected()};G.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()};G.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")};G.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")};G.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")};G.parseParenExpression=function(){this.expect(g.parenL);var t=this.parseExpression();return this.expect(g.parenR),t};G.shouldParseArrow=function(t){return!this.canInsertSemicolon()};G.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 Mi,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};G.parseParenItem=function(t){return t};G.parseParenArrowList=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!1,r)};var o_=[];G.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=o_,this.finishNode(t,"NewExpression")};G.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")};G.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")};G.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)&&!tt.test(this.input.slice(this.lastTokEnd,this.start))};G.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")};G.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")};G.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")};G.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()};G.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")};G.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)};G.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(fa(e,r.generator)|ki|(n?Rl: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")};G.parseArrowExpression=function(t,e,n,r){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(fa(n,!1)|da),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")};G.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,Bl),t.body=this.parseBlock(!1,void 0,a&&!s),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=l}this.exitScope()};G.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};G.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,ma,e?null:n)}};G.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};G.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&Ai)&&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"))}};G.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};G.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};G.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};G.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")};G.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 li=Re.prototype;li.raise=function(t,e){var n=Tl(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};li.raiseRecoverable=li.raise;li.curPosition=function(){if(this.options.locations)return new _r(this.curLine,this.pos-this.lineStart)};var hn=Re.prototype,l_=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};hn.enterScope=function(t){this.scopeStack.push(new l_(t))};hn.exitScope=function(){this.scopeStack.pop()};hn.treatFunctionsAsVarInScope=function(t){return t.flags&_n||!this.inModule&&t.flags&gn};hn.declareName=function(t,e,n){var r=!1;if(e===Qt){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&gn&&delete this.undefinedExports[t]}else if(e===Fl){var s=this.currentScope();s.lexical.push(t)}else if(e===Ll){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&Dl&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&gn&&delete this.undefinedExports[t],l.flags&Ai)break}r&&this.raiseRecoverable(n,"Identifier \'"+t+"\' has already been declared")};hn.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};hn.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};hn.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(Ai|wr|bn))return e}};hn.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(Ai|wr|bn)&&!(e.flags&da))return e}};var Ti=function(t,e,n){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new Ii(t,n)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},Sr=Re.prototype;Sr.startNode=function(){return new Ti(this,this.start,this.startLoc)};Sr.startNodeAt=function(t,e){return new Ti(this,t,e)};function $l(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}Sr.finishNode=function(t,e){return $l.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};Sr.finishNodeAt=function(t,e,n,r){return $l.call(this,t,e,n,r)};Sr.copyNode=function(t){var e=new Ti(this,t.start,this.startLoc);for(var n in t)e[n]=t[n];return e};var c_="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",jl="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",Ul=jl+" Extended_Pictographic",zl=Ul,ql=zl+" EBase EComp EMod EPres ExtPict",Hl=ql,u_=Hl,h_={9:jl,10:Ul,11:zl,12:ql,13:Hl,14:u_},p_="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",d_={9:"",10:"",11:"",12:"",13:"",14:p_},wo="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",Kl="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",Yl=Kl+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",Gl=Yl+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",Xl=Gl+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",Zl=Xl+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",f_=Zl+" "+c_,m_={9:Kl,10:Yl,11:Gl,12:Xl,13:Zl,14:f_},Ql={};function y_(t){var e=Ql[t]={binary:nn(h_[t]+" "+wo),binaryOfStrings:nn(d_[t]),nonBinary:{General_Category:nn(wo),Script:nn(m_[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(Lr=0,es=[9,10,11,12,13,14];Lr<es.length;Lr+=1)So=es[Lr],y_(So);var So,Lr,es,W=Re.prototype,ci=function(t,e){this.parent=t,this.base=e||this};ci.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};ci.prototype.sibling=function(){return new ci(this.parent,this.base)};var Ut=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=Ql[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};Ut.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)};Ut.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};Ut.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};Ut.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};Ut.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};Ut.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};Ut.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};Ut.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};Ut.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 g_(t){for(var e in t)return!0;return!1}W.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&g_(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 ci(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&&x_(n);)e+=Xt(n),t.advance();return e};function x_(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 Jl(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Jl(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&&!Jl(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+=Xt(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=Xt(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),__(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function __(t){return jt(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),b_(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function b_(t){return ln(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&&!Pi(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 ec(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function ec(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)&&v_(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=n}return!1};function v_(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 tc=0,Zt=1,mt=2;W.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(w_(e))return t.lastIntValue=-1,t.advance(),Zt;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===mt&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return tc};function w_(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),Zt}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return tc};W.regexp_validateUnicodePropertyNameAndValue=function(t,e,n){Hn(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 Zt;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return mt;t.raise("Invalid property name")};W.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";nc(e=t.current());)t.lastStringValue+=Xt(e),t.advance();return t.lastStringValue!==""};function nc(t){return ec(t)||t===95}W.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";S_(e=t.current());)t.lastStringValue+=Xt(e),t.advance();return t.lastStringValue!==""};function S_(t){return nc(t)||Pi(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===mt&&t.raise("Negated character class may contain strings"),!0}return!1};W.regexp_classContents=function(t){return t.current()===93?Zt:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),Zt)};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||sc(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=Zt,n;if(!this.regexp_eatClassSetRange(t))if(n=this.regexp_eatClassSetOperand(t)){n===mt&&(e=mt);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(n=this.regexp_eatClassSetOperand(t))){n!==mt&&(e=Zt);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===mt&&(e=mt)}};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)?Zt: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===mt&&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)===mt&&(e=mt);return e};W.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?Zt:mt};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()&&E_(n)||C_(n)?!1:(t.advance(),t.lastIntValue=n,!0)};function E_(t){return t===33||t>=35&&t<=38||t>=42&&t<=44||t===46||t>=58&&t<=64||t===94||t===96||t===126}function C_(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 N_(e)?(t.lastIntValue=e,t.advance(),!0):!1};function N_(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 Pi(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;Pi(n=t.current());)t.lastIntValue=10*t.lastIntValue+(n-48),t.advance();return t.pos!==e};function Pi(t){return t>=48&&t<=57}W.regexp_eatHexDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;rc(n=t.current());)t.lastIntValue=16*t.lastIntValue+ic(n),t.advance();return t.pos!==e};function rc(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function ic(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 sc(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function sc(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(!rc(i))return t.pos=n,!1;t.lastIntValue=16*t.lastIntValue+ic(i),t.advance()}return!0};var ga=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Ii(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 ga(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 ga(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 jt(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=kl(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&&!qn(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&&Al.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||tt.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(),jt(e,!0)||e===92))return this.finishToken(g.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+Xt(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 \'"+Xt(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(tt.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 Ut(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 I_(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function ac(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=ac(this.input.slice(e,this.pos)),++this.pos):jt(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=ac(this.input.slice(e,this.pos));return++this.pos,jt(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")),jt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=I_(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)):(qn(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(n,this.pos++),this.finishToken(g.string,e)};var oc={};ee.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===oc)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};ee.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw oc;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(qn(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 Xt(this.readCodePoint());case 116:return" ";case 98:return"\\b";case 118:return"\\v";case 102:return"\\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),t){var 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 qn(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(ln(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?jt:ln)(a,r)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=Xt(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=ha[t]),this.finishToken(e,t)};var k_="8.16.0";Re.acorn={Parser:Re,version:k_,defaultOptions:Ts,Position:_r,SourceLocation:Ii,getLineInfo:Tl,Node:Ti,TokenType:ie,tokTypes:g,keywordTypes:ha,TokContext:wt,tokContexts:ve,isIdentifierChar:ln,isIdentifierStart:jt,Token:ga,isNewLine:qn,lineBreak:tt,lineBreakG:Zx,nonASCIIwhitespace:Al};function xa(t,e){return Re.parse(t,e)}var{stringify:A_}=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 Fr={"||":2,"??":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},It=17,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:It,ClassExpression:It,FunctionExpression:It,ObjectExpression:It,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function Ln(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 lc(t,e,n,r){let i=t.expressionsPrecedence[e.type];if(i===It)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?Fr[e.operator]<=Fr[n.operator]:Fr[e.operator]<Fr[n.operator]}function Br(t,e,n,r){let{generator:i}=t;lc(t,e,n,r)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function T_(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 qe(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("/*"),T_(t,a.value,n,r),t.write("*/"+r))}}function P_(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 ts(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 Eo,Co,No,Io,ko,Ao,_a={Program(t,e){let n=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:i}=e;i&&t.comments!=null&&qe(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&&qe(e,l.comments,n,r),e.write(n),this[l.type](l,e),e.write(r)}i&&t.trailingComments!=null&&qe(e,t.trailingComments,n,r)},BlockStatement:Ao=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&&qe(e,t.comments,s,r);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&qe(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),qe(e,t.comments,s,r),e.write(n));i&&t.trailingComments!=null&&qe(e,t.trailingComments,s,r),e.write("}"),e.indentLevel--},ClassBody:Ao,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===It||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&&qe(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&&qe(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"?ts(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:Eo=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:n}=t;n.type[0]==="V"?ts(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:Eo,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:Co=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),Ln(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:Co,VariableDeclaration(t,e){ts(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===It||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),Ln(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]):Ln(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:No=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:No,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),Br(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){Br(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:ko=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:ko,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&&qe(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&&qe(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&&qe(e,t.trailingComments,s,r),e.write(n+"}")}else i?t.comments!=null?(e.write(r),qe(e,t.comments,s,r),t.trailingComments!=null&&qe(e,t.trailingComments,s,r),e.write(n+"}")):t.trailingComments!=null?(e.write(r),qe(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){Ln(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:n,argument:r,argument:{type:i}}=t;e.write(n);let s=lc(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:Io=function(t,e){let n=t.operator==="in";n&&e.write("("),Br(e,t.left,t,!1),e.write(" "+t.operator+" "),Br(e,t.right,t,!0),n&&e.write(")")},LogicalExpression:Io,ConditionalExpression(t,e){let{test:n}=t,r=e.expressionsPrecedence[n.type];r===It||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===It||n<e.expressionsPrecedence.CallExpression||P_(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),Ln(e,t.arguments)},CallExpression(t,e){let n=e.expressionsPrecedence[t.callee.type];n===It||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("?."),Ln(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let n=e.expressionsPrecedence[t.object.type];n===It||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(A_(t.value),t)},RegExpLiteral(t,e){let{regex:n}=t;e.write(`/${n.pattern}/${n.flags}`,t)}},D_={},R_=_a,Rs=class{constructor(e){let n=e??D_;this.output="",n.output!=null?(this.output=n.output,this.write=this.writeToStream):this.output="",this.generator=n.generator!=null?n.generator:_a,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 ba(t,e){let n=new Rs(e);return n.generator[t.type](t,n),n.output}var O_=Object.defineProperty,L_=(t,e,n)=>e in t?O_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,se=(t,e,n)=>L_(t,typeof e!="symbol"?e+"":e,n),F_=new Set(["Infinity","NaN","undefined","null","true","false"]),B_=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 Os(t){if(!t||typeof t!="string")return;let e=t.trim(),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 Ls=class{constructor(){se(this,"scopes",[]),se(this,"scopeTypes",[]),se(this,"scopeCounts",new Map),se(this,"contextBoundVars",new Set),se(this,"arrayPatternElements",new Set),se(this,"rootParams",new Set),se(this,"localSeriesVars",new Set),se(this,"varKinds",new Map),se(this,"loopVars",new Set),se(this,"loopVarNames",new Map),se(this,"paramIdCounter",0),se(this,"cacheIdCounter",0),se(this,"tempVarCounter",0),se(this,"taCallIdCounter",0),se(this,"userCallIdCounter",0),se(this,"plotCallIdCounter",0),se(this,"alertCallIdCounter",0),se(this,"loopGuardCounter",0),se(this,"hoistingStack",[]),se(this,"suppressHoisting",!1),se(this,"reservedNames",new Set),se(this,"userFunctions",new Set),se(this,"userMethods",new Set),se(this,"regularUserFunctions",new Set),se(this,"udtTypeNames",new Map),se(this,"udtInstances",new Map),se(this,"functionReturnTypes",new Map),se(this,"functionReturnTupleTypes",new Map),se(this,"functionParamUdtTypes",new Map),se(this,"varStaticTypes",new Map),se(this,"methodReceiverTypes",new Map),se(this,"functionParamStaticTypes",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=Os(n);r&&this.varStaticTypes.set(e,r)}getVarStaticType(e){return this.varStaticTypes.get(e)}unsetVarStaticType(e){this.varStaticTypes.delete(e)}setMethodReceiverType(e,n){let r=Os(n);r&&this.methodReceiverTypes.set(e,r)}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 F_.has(e)||B_.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 yt(t,e,n,r,i){n||(n=T),(function s(a,o,l){var c=l||a.type;uc(n,c,a,o,s),e[c]&&e[c](a,o)})(t,r,i)}function cc(t,e,n,r,i){var s=[];n||(n=T),(function a(o,l,c){var u=c||o.type,p=o!==s[s.length-1];p&&s.push(o),uc(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?V_(n,r||void 0):r;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function V_(t,e){var n=Object.create(e||T);for(var r in t)n[r]=t[r];return n}function va(t,e,n){n(t,e)}function vn(t,e,n){}function uc(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 T={};T.Program=T.BlockStatement=T.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")}};T.Statement=va;T.EmptyStatement=vn;T.ExpressionStatement=T.ParenthesizedExpression=T.ChainExpression=function(t,e,n){return n(t.expression,e,"Expression")};T.IfStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Statement"),t.alternate&&n(t.alternate,e,"Statement")};T.LabeledStatement=function(t,e,n){return n(t.body,e,"Statement")};T.BreakStatement=T.ContinueStatement=vn;T.WithStatement=function(t,e,n){n(t.object,e,"Expression"),n(t.body,e,"Statement")};T.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)}};T.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")}};T.ReturnStatement=T.YieldExpression=T.AwaitExpression=function(t,e,n){t.argument&&n(t.argument,e,"Expression")};T.ThrowStatement=T.SpreadElement=function(t,e,n){return n(t.argument,e,"Expression")};T.TryStatement=function(t,e,n){n(t.block,e,"Statement"),t.handler&&n(t.handler,e),t.finalizer&&n(t.finalizer,e,"Statement")};T.CatchClause=function(t,e,n){t.param&&n(t.param,e,"Pattern"),n(t.body,e,"Statement")};T.WhileStatement=T.DoWhileStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.body,e,"Statement")};T.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")};T.ForInStatement=T.ForOfStatement=function(t,e,n){n(t.left,e,"ForInit"),n(t.right,e,"Expression"),n(t.body,e,"Statement")};T.ForInit=function(t,e,n){t.type==="VariableDeclaration"?n(t,e):n(t,e,"Expression")};T.DebuggerStatement=vn;T.FunctionDeclaration=function(t,e,n){return n(t,e,"Function")};T.VariableDeclaration=function(t,e,n){for(var r=0,i=t.declarations;r<i.length;r+=1){var s=i[r];n(s,e)}};T.VariableDeclarator=function(t,e,n){n(t.id,e,"Pattern"),t.init&&n(t.init,e,"Expression")};T.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")};T.Pattern=function(t,e,n){t.type==="Identifier"?n(t,e,"VariablePattern"):t.type==="MemberExpression"?n(t,e,"MemberPattern"):n(t,e)};T.VariablePattern=vn;T.MemberPattern=va;T.RestElement=function(t,e,n){return n(t.argument,e,"Pattern")};T.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")}};T.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")}};T.Expression=va;T.ThisExpression=T.Super=T.MetaProperty=vn;T.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")}};T.ObjectExpression=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];n(s,e)}};T.FunctionExpression=T.ArrowFunctionExpression=T.FunctionDeclaration;T.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")}};T.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")}};T.TemplateElement=vn;T.UnaryExpression=T.UpdateExpression=function(t,e,n){n(t.argument,e,"Expression")};T.BinaryExpression=T.LogicalExpression=function(t,e,n){n(t.left,e,"Expression"),n(t.right,e,"Expression")};T.AssignmentExpression=T.AssignmentPattern=function(t,e,n){n(t.left,e,"Pattern"),n(t.right,e,"Expression")};T.ConditionalExpression=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Expression"),n(t.alternate,e,"Expression")};T.NewExpression=T.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")}};T.MemberExpression=function(t,e,n){n(t.object,e,"Expression"),t.computed&&n(t.property,e,"Expression")};T.ExportNamedDeclaration=T.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)}};T.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)}};T.ImportAttribute=function(t,e,n){n(t.value,e,"Expression")};T.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)}};T.ImportExpression=function(t,e,n){n(t.source,e,"Expression"),t.options&&n(t.options,e,"Expression")};T.ImportSpecifier=T.ImportDefaultSpecifier=T.ImportNamespaceSpecifier=T.Identifier=T.PrivateIdentifier=T.Literal=vn;T.TaggedTemplateExpression=function(t,e,n){n(t.tag,e,"Expression"),n(t.quasi,e,"Expression")};T.ClassDeclaration=T.ClassExpression=function(t,e,n){return n(t,e,"Class")};T.Class=function(t,e,n){t.id&&n(t.id,e,"Pattern"),t.superClass&&n(t.superClass,e,"Expression"),n(t.body,e)};T.ClassBody=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e)}};T.MethodDefinition=T.PropertyDefinition=T.Property=function(t,e,n){t.computed&&n(t.key,e,"Expression"),t.value&&n(t.value,e,"Expression")};var be="$",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}}},cn=["ta","math","request","array","input","color","ticker","strategy"],kt=["hline","plot","fill","label","line","box","linefill","polyline","table","na","alert","time","time_close","dayofmonth","dayofweek","hour","minute","month","second","weekofyear","year"],W_=["request.security","request.security_lower_tf"],$_=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Mo=["plot","hline","fill","strategy.exit"],j_=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],U_=new Set([...cn,"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"]),To=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"]),hc=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],wa=[...cn,"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"],z_=["na","nz","plot","plotchar","color","hline","fill"];function q_(t){let e=null,n=be;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=hc,o=wa,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 H_(t){let e=null,n=be;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(hc),i=new Set(wa),s=new Set(z_),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"&&cn.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 K_(t){try{let e=xa(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 Y_(t){return t.async=!0,ba(t)}function G_(t){t=t.trim();let{isWrapped:e,isAsync:n,functionNode:r}=K_(t);return e&&r?n?t:Y_(r):`async (context) => {\n${t}\n}`}function X_(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 Z_(t,e){yt(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,yt(t,{FunctionDeclaration(r){if(!r.id?.name)return;let i=r.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=J_(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=>hr(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=>hr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),n=!0)}});yt(t,{VariableDeclaration(r){for(let i of r.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=hr(i.init,e);if(s){e.markVariableAsUdtInstance(i.id.name,s);continue}let a=Fs(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)}}}}),yt(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 Q_=new Set(["table","line","label","box","linefill","polyline","array","matrix","map"]);function Fs(t){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&Q_.has(t.callee.object.name)){let e=t.callee.property.name;if(e==="new"||e==="copy"||e==="from"||e.startsWith("new_"))return t.callee.object.name}if(t.type==="ConditionalExpression"){let e=Fs(t.consequent),n=Fs(t.alternate);if(e&&e===n)return e}}}function J_(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 hr(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=hr(t.consequent,e),r=hr(t.alternate,e);if(n&&n===r)return n}}}function e1(t,e){yt(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===be||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===be||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 t1(t,e,n=!1){t.params.forEach(r=>{r.type==="Identifier"&&n&&e.addContextBoundVar(r.name,n)})}function n1(t,e){let n;return cc(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=be),t1(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")&&yt(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 r1=Object.defineProperty,i1=(t,e,n)=>e in t?r1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,s1=(t,e,n)=>i1(t,typeof e!="symbol"?e+"":e,n),a1=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),o1=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function l1(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function c1(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 u1(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 Bs(t,e){return t!=="notint"&&e!=="notint"?"int":"notint"}var Vs=class{constructor(){s1(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,Bs(this.stack[r].get(e),n));return}this.stack[this.stack.length-1].set(e,Bs(n,n))}};function h1(t,e){let n=new Vs,r=u1(t);function i(a){if(!a||typeof a!="object")return"notint";switch(a.type){case"Literal":return typeof a.value=="number"&&l1(a)?"constint":"notint";case"Identifier":return a1.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 Bs(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=c1(a.callee);return o&&o1.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 ui={type:"Identifier",name:"undefined"};function pr(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 Ws(t,e){let n=De(t,e);return C.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=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||(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=Wt(t.property,e))}function Ke(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!==be){if(kt.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===be&&["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"&&cn.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===be&&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||Ie(t.object,n);let l=n.generateParamId(),c={type:"CallExpression",callee:C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("param")),arguments:[t.object,ui,pr(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"&&cn.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||(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===be||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"&&kt.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 dr(t,e){if(t.type==="Identifier"){if(kt.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 Wt(t,e,n=""){switch(t.type){case"BinaryExpression":return zr(t,e,n);case"LogicalExpression":return qr(t,e,n);case"MemberExpression":{let r=!t.computed&&t.object.type==="Identifier"&&kt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&kt.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?dr(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=dr(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 Hr(t,e,n);case"ConditionalExpression":{let r=Wt(t.test,e,n),i=Wt(t.consequent,e,n),s=Wt(t.alternate,e,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function zr(t,e,n){let r=Wt(t.left,e,n),i=Wt(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||Ie(a,o)},MemberExpression(a){Ee(a,"",e)}}),s}function qr(t,e,n){let r=Wt(t.left,e,n),i=Wt(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||Ie(a,o)}}),s}function ns(t,e,n){Pe(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(kt.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"?wn(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===be&&a.parent.callee.property.name==="get"||Ke(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);Ie(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,ui,pr(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 Hr(t,e,n){let r=Wt(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||Ie(s,a)},MemberExpression(s){Ee(s,"",e)}}),i}function tn(t,e,n){switch(t?.type){case"BinaryExpression":t=zr(t,n,e);break;case"LogicalExpression":t=qr(t,n,e);break;case"ConditionalExpression":return ns(t,n,e);case"UnaryExpression":t=Hr(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 Ws(c.name,n)}return c.type==="CallExpression"?(Ie(c,n),c):c.type==="BinaryExpression"?zr(c,n,e):c.type==="LogicalExpression"?qr(c,n,e):c.type==="ConditionalExpression"?ns(c,n,e):c.type==="UnaryExpression"?Hr(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")Ie(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)&&!kt.includes(m.name)&&!cn.includes(m.name)&&(f.object=Ws(m.name,n));break}f=f.object}}else t.object.type==="BinaryExpression"?t.object=zr(t.object,n,e):t.object.type==="LogicalExpression"?t.object=qr(t.object,n,e):t.object.type==="ConditionalExpression"?t.object=ns(t.object,n,e):t.object.type==="UnaryExpression"&&(t.object=Hr(t.object,n,e));let c=t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)?t.object:dr(t.object,n),u;t.property.type==="Identifier"&&!n.isContextBound(t.property.name)&&!n.isLoopVariable(t.property.name)?u=C.createGetCall(dr(t.property,n),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=Wt(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,pr(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"&&cn.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"?tn(t.object,e,n):t.object.type==="CallExpression"&&(t.object._transformed||Ie(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=tn(c.value,e,n)),c))),t.type==="Identifier"){if(kt.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,ui,pr(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"&&Ie(t,n);let s=C.createMemberExpression(C.createIdentifier(e),C.createIdentifier("param")),a=t.type==="Identifier"?dr(t,n):t,o=n.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,ui,pr(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 rr(t){if(!t)return!1;if(pc(t))return!0;if(t.type==="MemberExpression")return rr(t.object);if(t.type==="ChainExpression")return rr(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return rr(e.object);if(e?.type==="ChainExpression")return rr(e.expression)}return!1}function pc(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function $s(t,e,n){t&&(t.type==="Identifier"?(t.parent=e,Te(t,n)):t.type==="MemberExpression"?$s(t.object,t,n):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&$s(t.callee.object,t.callee,n),t._transformed||Ie(t,n)))}function Ie(t,e,n){if(t._transformed)return;t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(cn.includes(t.callee.name)||kt.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===be&&["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(tn(h,i,e))}),t.arguments=s;let a=t.callee.property.name,o=`${i}.${a}`;if(Mo.includes(i)||Mo.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=W_.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:tn(i,be,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=e.isUserMethod(i),l;if(a.name)l=e.getVariableUdtType(a.name)??e.getVarStaticType(a.name);else if(a.type==="MemberExpression"&&!a.computed&&a.property?.type==="Identifier"&&a.object?.name){let h=e.getVariableUdtType(a.object.name);if(h){let d=e.getUdtTypeFields(h)?.[a.property.name];l=Os(d)}}let c=e.getMethodReceiverType(i),u=!!l&&!!c&&l===c,p=!!a.name&&e.isUdtInstance(a.name);if(s&&o&&!e.isContextBound(i)&&(u||p)){let h=t.callee.object;t.callee.property;let d=t.arguments.map(S=>S._isParamCall?S:tn(S,be,e)),f=h;h.type==="Identifier"?f=tn(h,be,e):h.type==="CallExpression"?(Ie(h,e),f=tn(h,be,e)):h.type==="MemberExpression"&&(f=tn(h,be,e));let m=C.createMemberExpression(C.createContextIdentifier(),C.createIdentifier("call")),_=e.getNextUserCallId(),b=C.createIdentifier(`$M_${i}`);b._skipTransformation=!0;let v=[b,_,f,...d];t.callee=m,t.arguments=v,t._transformed=!0;return}t.callee.object.type==="Identifier"?Te(t.callee.object,e):$s(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"?wn(s,e):s.type==="Identifier"&&(s.parent&&s.parent.type==="CallExpression"&&s.parent.callee&&s.parent.callee.object&&s.parent.callee.object.name===be&&s.parent.callee.property.name==="get"||Ke(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||Ie(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=pc(i),a=i?.type==="MemberExpression"&&rr(i);if(s||a){let o=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:o},t.optional=!0}}}function Sa(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 hi(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(kt.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===be&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?wn(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!d&&!f&&Ke(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);Ie(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 dc(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"&&kt.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===be||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===be||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=be;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=be;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)?Ie(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===be&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(f||m||_)&&!b&&Ke(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}),Ie(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}}hi(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||(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 _,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}`;j_.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&&fc(h.test,d),f(h.consequent,d),h.alternate&&(d.pushScope("els"),f(h.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(h,d){dc(h,d)},Identifier(h,d){Te(h,d)},AssignmentExpression(h,d){hi(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 p1(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,Ke(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,Ke(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,Ke(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=Sa(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 d1(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,Ke(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),Ie(s,a),s.arguments)for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=Sa(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 fc(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){Ie(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===be&&i.callee.property?.name==="get"||Ke(n));let c=e.getCurrentScopeType()==="if";e.isContextBound(n.name)&&!e.isRootParam(n.name)&&c&&Ke(n)}})}function f1(t,e,n){t.test&&(e.pushScope("if"),fc(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 m1(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):Ws(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&&(Ke(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),Ie(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"&&Ke(t.argument);else if(t.argument.type==="MemberExpression"){if(t.argument.object.type==="Identifier"&&!e.isContextBound(t.argument.object.name)&&!e.isLoopVariable(t.argument.object.name)&&!(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||(wn(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&&(Ke(i),i._arrayAccessed=!0)},MemberExpression(i){Ee(i,"",e)},AssignmentExpression(i,s){hi(i,s)},CallExpression(i,s,a){(i.callee.type==="ArrowFunctionExpression"||i.callee.type==="FunctionExpression")&&a(i.callee,s),Ie(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 y1(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(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 g1(t){let e={...T,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;yt(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 yt(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,yt(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=[];yt(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=[];yt(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 x1={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},_1=new Set(["<","<=",">",">="]);function b1(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 v1(t){let e={...T,LineComment:()=>{}};cc(t,{BinaryExpression(n,r,i){let s=x1[n.operator];if(!s||_1.has(n.operator)&&b1(n,i))return;let a=C.createMathCompareCall(s,n.left,n.right);a._transformed=!0,Object.assign(n,a)}},e)}var w1={"+":"__union","-":"__minus"};function Po(t){return t?.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.object.name==="display"?!0:t?.type==="CallExpression"&&t._displaySetOp===!0}function S1(t){let e={...T,LineComment:()=>{}};yt(t,{BinaryExpression(n){let r=w1[n.operator];if(!r||!Po(n.left)&&!Po(n.right))return;let i=C.createMemberExpression(C.createIdentifier("display"),C.createIdentifier(r),!1),s=C.createCallExpression(i,[n.left,n.right]);s._displaySetOp=!0,Object.assign(n,s)}},e)}function E1(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),m1(a,o)},VariableDeclaration(a,o){dc(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)),Ie(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"&&Ke(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=Sa(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"&&Ke(a.right)):a.right&&l(a.right,o),a.body&&l(a.body,o)},MemberExpression(a,o,l){a.object&&(a.object.type==="CallExpression"||a.object.type==="MemberExpression")&&(a.object.parent=a,l(a.object,o)),a.object&&a.object.type==="Identifier"&&!o.isContextBound(a.object.name)&&(a.object.parent=a,l(a.object,o)),Ee(a,n,o)},AssignmentExpression(a,o,l){if(hi(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){y1(a,o,l)},ForStatement(a,o,l){p1(a,o,l)},WhileStatement(a,o,l){d1(a,o,l)},IfStatement(a,o,l){f1(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"},C1=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","import","export","method","extends","enum"]),N1=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],js=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}},I1=Object.defineProperty,k1=(t,e,n)=>e in t?I1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dt=(t,e,n)=>k1(t,typeof e!="symbol"?e+"":e,n),Us=class{constructor(e){Dt(this,"source"),Dt(this,"pos"),Dt(this,"line"),Dt(this,"column"),Dt(this,"tokens"),Dt(this,"indentStack"),Dt(this,"atLineStart"),Dt(this,"parenDepth"),Dt(this,"bracketDepth"),Dt(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();C1.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(N1.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 js(e,n,this.line,this.column,r!==null?r:this.getCurrentIndent(),i);this.tokens.push(s)}},A1=Object.defineProperty,M1=(t,e,n)=>e in t?A1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ot=(t,e,n)=>M1(t,typeof e!="symbol"?e+"":e,n),ce=class{constructor(e){this.type=e}},zs=class extends ce{constructor(e){super("Program"),this.body=e}},Je=class extends ce{constructor(e){super("ExpressionStatement"),this.expression=e}},Kt=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(Kt||{}),St=class extends ce{constructor(e,n="let"){super("VariableDeclaration"),this.declarations=e,this.kind=n}},ft=class extends ce{constructor(e,n,r=null){super("VariableDeclarator"),this.id=e,this.init=n,this.varType=r}},pi=class extends ce{constructor(e,n,r,i=null){super("FunctionDeclaration"),this.id=e,this.params=n,this.body=r,this.returnType=i}},qs=class extends ce{constructor(e,n){super("TypeDefinition"),this.name=e,this.fields=n}},Hs=class extends ce{constructor(e,n,r=null){super("IfStatement"),this.test=e,this.consequent=n,this.alternate=r,ot(this,"_line")}},di=class extends ce{constructor(e,n,r,i){super("ForStatement"),this.init=e,this.test=n,this.update=r,this.body=i,ot(this,"isForIn")}},Ks=class extends ce{constructor(e,n){super("WhileStatement"),this.test=e,this.body=n}},Lt=class extends ce{constructor(e){super("BlockStatement"),this.body=e}},fi=class extends ce{constructor(e){super("ReturnStatement"),this.argument=e}},Ne=class extends ce{constructor(e){super("Identifier"),this.name=e,ot(this,"varType"),ot(this,"returnType"),ot(this,"isMethod")}},Yt=class extends ce{constructor(e,n=null){super("Literal"),this.value=e,this.raw=n}},Et=class extends ce{constructor(e,n,r){super("BinaryExpression"),this.operator=e,this.left=n,this.right=r}},mi=class extends ce{constructor(e,n,r=!0){super("UnaryExpression"),this.operator=e,this.argument=n,this.prefix=r}},mn=class extends ce{constructor(e,n,r){super("AssignmentExpression"),this.operator=e,this.left=n,this.right=r}},yi=class extends ce{constructor(e,n,r=!1){super("UpdateExpression"),this.operator=e,this.argument=n,this.prefix=r}},Ys=class extends ce{constructor(e,n){super("CallExpression"),this.callee=e,this.args=n,ot(this,"arguments"),this.callee=e,this.arguments=n}},gi=class extends ce{constructor(e,n,r=!1){super("MemberExpression"),this.object=e,this.property=n,this.computed=r}},Ft=class extends ce{constructor(e,n,r){super("ConditionalExpression"),this.test=e,this.consequent=n,this.alternate=r,ot(this,"needsIIFE"),ot(this,"consequentStmts"),ot(this,"alternateStmts")}},Gs=class extends ce{constructor(e){super("ArrayExpression"),this.elements=e}},xi=class extends ce{constructor(e){super("ObjectExpression"),this.properties=e}},_i=class extends ce{constructor(e,n){super("Property"),this.key=e,this.value=n,ot(this,"kind"),ot(this,"method"),ot(this,"shorthand"),ot(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},bi=class extends ce{constructor(e){super("ArrayPattern"),this.elements=e}},vi=class extends ce{constructor(e,n){super("AssignmentPattern"),this.left=e,this.right=n}},Xs=class extends ce{constructor(e,n){super("SwitchExpression"),this.discriminant=e,this.cases=n}},Zs=class extends ce{constructor(e,n,r){super("SwitchCase"),this.test=e,this.consequent=n,this.statements=r,this.statements=r}},T1=Object.defineProperty,P1=(t,e,n)=>e in t?T1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Bn=(t,e,n)=>P1(t,typeof e!="symbol"?e+"":e,n),mc=class Qs{constructor(e){Bn(this,"tokens"),Bn(this,"pos"),Bn(this,"functionNames",new Set),Bn(this,"paramScopes",[]),Bn(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&&Qs.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}isLayoutToken(){return this.match(x.NEWLINE)||this.match(x.COMMENT)}skipNewlines(e=!1){for(;this.isLayoutToken();)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 zs(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 Je(new Ne(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 St([new ft(i,a)],Kt.LET):r=new Je(new mn(s===":="?"=":s,i,a))}else r=new Je(i)}else r=new Je(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 Lt(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 _i(new Ne(s.name),new Yt(s.title!==null?s.title:s.name))),i=new xi(r);return new St([new ft(new Ne(e),i)],Kt.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 qs(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 Ne(r);n&&(s.varType=n);let a=[new ft(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 St(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 Ne(n);i.varType=e;let s=[new ft(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 Ne(a);l.varType=e,s.push(new ft(l,o,e))}return new St(s,Kt.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 Ne(l);if(o&&(c.varType=o),this.match(x.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();r.push(new vi(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 Ne(n);return e&&(a.returnType=e),new pi(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 Ne(l);if(o&&(c.varType=o),this.match(x.OPERATOR,"=")){this.advance(),this.skipNewlines();let u=this.parseExpression();r.push(new vi(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 Ne(n);return e&&(a.returnType=e),a.isMethod=!0,new pi(a,r,s,e)}parseFunctionBody(){let e=[];if(!this.match(x.INDENT)){let n=this.parseExpression();return new Lt([new fi(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 Lt(e)}_addImplicitReturn(e){let n=e[e.length-1];n.type==="ExpressionStatement"?e[e.length-1]=new fi(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 Je(new Ne(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 St([new ft(s,o)],Kt.LET)):i.push(new Je(new mn(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 St([new ft(r,s)],Kt.LET)):n.push(new Je(new mn(i===":="?"=":i,r,s))),this.match(x.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(n.length>0)n.push(new Je(r));else return new Je(r);break}}else if(this.match(x.COMMA)){n.push(new Je(r)),this.advance(),this.skipNewlines();continue}else{if(n.length>0)n.push(new Je(r));else return new Je(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 Hs(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 Ne(this.expectIdentifierOrContextual().value)),this.match(x.COMMA)&&this.advance();this.expect(x.RBRACKET),e=new bi(r),n=!0}else{let r=this.expectIdentifierOrContextual().value;e=new Ne(r)}if(this.match(x.KEYWORD,"in")){this.advance();let r=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new St([new ft(e,r)],Kt.CONST),a=new di(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 St([new ft(e,r)],Kt.LET),l=new Et("<=",r,i),c=new Ft(l,new Et("<=",e,i),new Et(">=",e,i)),u;return s?u=new Ft(l,new mn("+=",e,s),new mn("-=",e,s)):u=new Ft(l,new yi("++",e),new yi("--",e)),new di(o,c,u,a)}}parseWhileStatement(){this.expect(x.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock();return new Ks(e,n)}parseBlock(){if(!this.match(x.INDENT)){let r=this.parseStatement();return new Lt(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 Lt(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 Ne(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 St([new ft(new bi(e),n)],Kt.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 Ft(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 Et("||",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 Et("&&",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 Et(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 Et(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 Et(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 Et(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 mi(e,this.parseUnary())}return this.match(x.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new mi("!",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 Ne("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 gi(e,new Ne(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 gi(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 _i(new Ne(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 xi(r)),new Ys(e,n)}parsePrimary(){let e=this.peek();if(this.match(x.NUMBER)){let n=this.advance();return new Yt(n.value,n.raw)}if(this.match(x.STRING)){let n=this.advance();return new Yt(n.value)}if(this.match(x.BOOLEAN)){let n=this.advance();return new Yt(n.value)}if(this.match(x.IDENTIFIER)||e.type===x.KEYWORD&&Qs.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 Ne(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 Gs(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 Ft(e,new Lt(n),a);return o.needsIIFE=!0,o.consequentStmts=n,o.alternateExpr=a,o}else return new Ft(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 Ft(e,new Lt(n),new Lt(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 Yt(null);return new Ft(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 Zs(r,s,i)),this.skipNewlines()}return this.advance(),new Xs(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 Yt(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 Yt(null)}};Bn(mc,"CONTEXTUAL_KEYWORDS",new Set(["type","method","enum"]));var D1=mc,R1=Object.defineProperty,O1=(t,e,n)=>e in t?R1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ht=(t,e,n)=>O1(t,typeof e!="symbol"?e+"":e,n),L1=new Set(wa),Js=class{constructor(e={}){Ht(this,"indent"),Ht(this,"indentStr"),Ht(this,"output"),Ht(this,"sourceCode"),Ht(this,"sourceLines"),Ht(this,"lastCommentedLine"),Ht(this,"includeSourceComments"),Ht(this,"paramRenameCounter"),Ht(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&&(U_.has(e)||To.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)?To.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&&L1.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(", ")}if(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 c=e.params[0],u=c?.type==="AssignmentPattern"?c.left?.varType:c?.varType;typeof u=="string"&&u.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${a}.__pineReceiverType__ = ${JSON.stringify(u)};\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`)):a&&typeof s=="string"&&s.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${JSON.stringify(`__pineTypedVar:${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 yc(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 Ea(t,e={}){let n=yc(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 Us(t).tokenize(),i=new D1(r).parse(),s={...e,sourceCode:t},a=new Js(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 F1=new Set(["security_lower_tf","security"]),gc=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:F1.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(gc.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 ea(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function Bt(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(Bt(r,e,n+1)),{...t,body:s}}case"IfStatement":return r===t.test?{...t,test:Bt(r,e,n+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:Bt(r,e,n+1),alternate:null}:r===t.alternate?{...t,alternate:Bt(r,e,n+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:Bt(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(Bt(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(Bt(r,e,n+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:Bt(r,e,n+1)}:t;default:return t}}function $1(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 j1(t,e,n){let r=t.body||[];for(let i=0;i<r.length;i++){let s=r[i];if(s!==n&&U1(s,e))return i}return-1}function U1(t,e){let n=!1,r=new WeakSet;function i(s){if(!(n||!s||typeof s!="object")&&!r.has(s)){if(r.add(s),$1(s)===e){n=!0;return}for(let a of Object.keys(s)){if(gc.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 z1(t,e){let n=-1;for(let h=1;h<e.length;h++)if(ea(e[h])){n=h;break}if(n<0)return null;let r=e[n];for(let h=n+1;h<e.length;h++)if(ea(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;let i=r.id.name,s=e.slice(n),a=Bt(r,s,0),o=j1(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 q1(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 = ${ba(n)}\n; return _r;`;return new Function("",r)()}function H1(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=>ea(p)),c=null;if(l)c=z1(r.body,a);else{let p=Bt(r.body,a,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;let u=q1(r,c);e[o]=u}return e}function K1(t){if(typeof t=="function")return{code:t.toString(),version:null};{let e=yc(t);if(e===null)return{code:t,version:null};if(e>=5){let n=Ea(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 Y1(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:n}=e,{code:r,version:i}=K1(t),s=r;s=G_(s);let a=n?s.split(`\n`):[],o=xa(s,{ecmaVersion:"latest",sourceType:"module",locations:n});X_(o),H_(o),q_(o);let l=new Ls;e1(o,l),Z_(o,l);let c=n1(o,l)||"";if(i!==null&&i<6&&h1(o),E1(o,l,c,e,a),v1(o),S1(o),g1(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=R_||_a||void 0,p=Object.assign({},u,{LineComment(m,_){_.write("//"+m.value)}}),h=ba(o,{generator:p,comments:n}),d=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:H1(o),f=new Function("",`var _r = ${h}\n; return _r;`)(this);return d&&Object.keys(d).length>0&&(f._ltfSlices=d),f}var Do={"":["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"]},G1={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 X1(t){if(typeof t!="string")return[];let e=Ea(t);if(!e.success||!e.ast)return[];let n=Z1(e.ast),r=Q1(e.ast),i=[],s=new Set;return Gt(e.ast,a=>{let o=J1(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 Z1(t){let e=new Map;return Gt(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 Q1(t){let e=new Map;return Gt(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 J1(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 Do))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"?eb(u,p,h):xc(Do[a],u,h);for(let _ of p)_.type!=="Property"||!_.key?.name||(h[_.key.name]=_.value);let d={};for(let _ of Object.keys(h))d[_]=Kr(h[_],e,n);let f=a===""?tb(d.defval):G1[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=nb(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 eb(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"];xc(r,t,n)}function xc(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 Kr(t,e,n,r=new Set){if(t!=null)switch(t.type){case"Literal":return t.value;case"Identifier":if(oa.has(t.name))return t.name;if(n?.has(t.name)&&!r.has(t.name)){r.add(t.name);let i=Kr(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=>Kr(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 ps(l,c,u,h)}}else if(s==="new"){let l=fl(a[0]),c=a[1];if(l&&typeof c=="number")return ps(l[0],l[1],l[2],o(1-c/100))}}return}case"ArrayExpression":return(t.elements??[]).map(i=>Kr(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 tb(t){return typeof t=="boolean"?"bool":typeof t=="number"?Number.isInteger(t)?"int":"float":typeof t=="string"?oa.has(t)?"source":t.startsWith("#")?"color":"string":null}function nb(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 Gt(t,e){if(!(!t||typeof t!="object")){if(e(t),Array.isArray(t.body))for(let n of t.body)Gt(n,e);else t.body&&Gt(t.body,e);if(Array.isArray(t.consequent))for(let n of t.consequent)Gt(n,e);else t.consequent&&Gt(t.consequent,e);if(t.alternate&&Gt(t.alternate,e),Array.isArray(t.declarations))for(let n of t.declarations)Gt(n,e)}}function _c(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 rb(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 rb(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 ${Fn(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${n}] "${r}" expects a number; got ${Fn(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${n}] "${r}" expects a boolean; got ${Fn(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 ${Fn(e)}`);break}if(t.options&&!t.options.some(i=>ib(i,e)))throw new RangeError(`[${n}] "${r}" value ${Fn(e)} is not one of: ${t.options.map(Fn).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 ib(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function Fn(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function sb(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}=_c(r,"Indicator.input",e,void 0,"input key");return{proxy:i,values:s,metaByKey:n}}var bc=[{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}],vc=[...bc.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"}],wc=[...bc.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 ab(t){return t==="strategy"?wc:vc}function ob(t){return typeof t=="string"?lb(t):typeof t=="function"?cb(t):{type:null,args:{}}}function lb(t){let e=Ea(t);if(!e.success||!e.ast)return{type:null,args:{}};let n=null;return wi(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:Ec(i.arguments??[],Sc(s.name))}))}),n??{type:null,args:{}}}function cb(t){let e;try{e=xa(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let n=null;return wi(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:Ec(r.arguments??[],Sc(i.name))}))}),n??{type:null,args:{}}}function Sc(t){return t==="strategy"?wc:vc}function Ec(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]=ta(s[a])}if(i)for(let a of r.properties??[])a.type!=="Property"||!a.key?.name||(n[a.key.name]=ta(a.value));return n}function ta(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(ta);default:return}}function wi(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)wi(i,e);else r&&typeof r=="object"&&typeof r.type=="string"&&wi(r,e)}}}function ub(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}=_c(i,"Indicator.prop",n,e);return{proxy:s,values:a,propByName:r}}var hb=Object.defineProperty,pb=(t,e,n)=>e in t?hb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,at=(t,e,n)=>pb(t,typeof e!="symbol"?e+"":e,n),xn=class t{constructor(e,n={}){at(this,"source"),at(this,"inputs"),at(this,"_prepared",null),at(this,"_inputMeta",null),at(this,"_inputValues",{}),at(this,"_explicitOverrides",new Set),at(this,"_inputProxy",null),at(this,"_propMeta",null),at(this,"_propValues",{}),at(this,"_propProxy",null),at(this,"_declarationType",null),at(this,"_sourcePropArgs",{}),at(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=Y1(this.source,{debug:!!e.debug,ln:e.ln}),r=db(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=X1(this.source);for(let n of this._inputMeta)n.type==="color"&&n.defval!==void 0&&(n.defval=rf(n.defval));let e=sb(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=ob(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=ab(e.type);let n=ub(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=n.values,this._propProxy=n.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function db(t){let e=t.toString();return $_.some(n=>{let r=n.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${r}\\\\b`).test(e)})}var fb=Object.defineProperty,mb=(t,e,n)=>e in t?fb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pe=(t,e,n)=>mb(t,typeof e!="symbol"?e+"":e,n),Ro={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 yb(t){return t?Ro[t]??Ro[t.toUpperCase()]??864e5:864e5}var un=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=yb(this.timeframe),N=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=N,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=xn.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=xn.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 zn({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=cg(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++})}ug(e.strategy,n.strategy)}_initializeContext(e,n={},r=!1){let i=new zn({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=yr(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo={...this._syminfo,tickerid:ys(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){eg(e),Hy(e),Xi(e,"open");let c=tg(e);c&&Xi(e,"extreme"),Jy(e,"intrabar"),c||Xi(e,"extreme"),ng(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&&rg(e)}},Oo={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},fr={"1S":1,"5S":5,"10S":10,"15S":15,"30S":30,1:60,3:180,5:300,15:900,30:1800,45:2700,60:3600,120:7200,180:10800,240:14400,D:86400,W:604800,M:2592e3};function mr(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 Vt(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 Lo(t,e,n,r,i=1){if(e==="24x7")return mr(t,r,i);let s=e.split("-")[1];if(!s||s.length!==4)return mr(t,r,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=Fo(t,n);if(r==="second"||r==="minute"||r==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[r],p=Vt(c,l,n);return Math.min(u,p)}if(r==="day")return Vt(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=Fo(h,n);return Vt(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 Vt(m,l,n)}return mr(t,r,i)}function Fo(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function gb(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 xb=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function _b(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;let n=fr[t];if(!n)return null;let r=xb.filter(i=>i!=="W"&&i!=="M"&&e.has(i)&&fr[i]<n&&n%fr[i]===0);return r.length===0?null:r[r.length-1]}function Cc(t,e){if(t==="W"||t==="M")return 1/0;let n=fr[t],r=fr[e];return!n||!r||r===0?1/0:n/r}function bb(t,e,n){if(t.length===0)return[];if(e==="W")return wb(t);if(e==="M")return Sb(t);let r=Cc(e,n);return vb(t,r)}function vb(t,e){if(t.length===0)return[];let n=[],r=[t[0]],i=Eb(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(Si(r)),r=[]),r.push(t[a])}return r.length>0&&n.push(Si(r)),n}function wb(t){let e=[],n=[],r="";for(let i of t){let s=Cb(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(Si)}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(Si)}function Si(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 Eb(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 Cb(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 Nb=Object.defineProperty,Ib=(t,e,n)=>e in t?Nb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Vr=(t,e,n)=>Ib(t,typeof e!="symbol"?e+"":e,n),Wr={"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 kb(t){if(Wr[t]!==void 0)return Wr[t];let e=t.toLowerCase();return Wr[e]!==void 0?Wr[e]:/^\\d+$/.test(t)?t:/^\\d+S$/i.test(t)?t.toUpperCase():t}var br=class{constructor(e){Vr(this,"_configured"),Vr(this,"_requiresApiKey"),Vr(this,"_providerName"),Vr(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){gb(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=sn(e);let a=kb(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:_b(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=bb(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=Cc(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)}},Ab=Object.defineProperty,Mb=(t,e,n)=>e in t?Ab(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ei=(t,e,n)=>Mb(t,typeof e!="symbol"?e+"":e,n),rs="https://api.binance.com/api/v3",Bo="https://api.binance.us/api/v3",$r={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"},na=class{constructor(e=300*1e3){Ei(this,"cache"),Ei(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)}},ra=class extends br{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Ei(this,"cacheManager"),Ei(this,"activeApiUrl",null),this.cacheManager=new na(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${rs}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=rs,this.activeApiUrl}catch{}try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Bo}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=Bo,this.activeApiUrl}catch{}return rs}async _fetchRawChunk(e,n,r,i,s){let a=$r[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=$r[n.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${n}`),[];let a=[],o=r,l=i,c=Oo[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(!$r[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=$r[e.toUpperCase()],a=Oo[s];if(a)return Math.ceil((i-r)/a)>1e3}return!1}async getSymbolInfo(e){e=sn(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}}},Tb=Object.defineProperty,Pb=(t,e,n)=>e in t?Tb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nr=(t,e,n)=>Pb(t,typeof e!="symbol"?e+"":e,n),Db="https://financialmodelingprep.com",Vo=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"]),Wo={"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"}},$o={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"},jo={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"},Rb={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}},ia=class extends br{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),nr(this,"_apiKey",null),nr(this,"_baseUrl",Db),nr(this,"_profileCache",new Map),nr(this,"_symbolInfoCache",new Map),nr(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=Wo[a]||Wo[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=Lo(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}=Rb[r]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let _=this._dateTimeStrToMs(m.date),b=Lo(_,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=sn(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":$o[i]||"America/New_York",a=r==="crypto"?"24x7":r==="forex"?"0000-0000":jo[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":$o[r]||"America/New_York";return{session:i?"24x7":jo[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)&&Vo.has(e.slice(0,3))&&Vo.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},Ob=Object.defineProperty,Lb=(t,e,n)=>e in t?Ob(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dn=(t,e,n)=>Lb(t,typeof e!="symbol"?e+"":e,n),Fb="https://data.alpaca.markets",Bb="https://paper-api.alpaca.markets/v2",Vb="https://api.alpaca.markets/v2",is=1e4,Uo={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"},$b={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},jb={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},sa=class extends br{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),dn(this,"_apiKey",null),dn(this,"_apiSecret",null),dn(this,"_dataUrl",Fb),dn(this,"_tradingUrl",Bb),dn(this,"_feed",null),dn(this,"_assetCache",new Map),dn(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||is,is);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,is))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=sn(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":$b[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():mr(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=Vt(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=Vt(o,p,i);l=Math.min(c,h)}else n==="week"?l=this._weeklyCloseFromCalendar(o,i):n==="month"?l=this._monthlyCloseFromCalendar(o,i):l=mr(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 Vt(u,p.close,n)}let a=r.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return Vt(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 Vt(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 Vt(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=jb[n[2]];if(i)return{periodType:i,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return Uo[e.toUpperCase()]||Uo[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]}},aa=class{async getMarketData(){return[]}},Ub=typeof process<"u"&&process.versions&&process.versions.node,Ci=null;if(Ub)try{Ci=new aa}catch{Ci=null}var FC={Binance:new ra,FMP:new ia,Alpaca:new sa,...Ci?{Mock:Ci}:{}};function U(t){return typeof t=="string"?t:void 0}function ue(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function Nc(t){if(typeof t=="boolean")return t;if(typeof t=="object"&&t!==null&&Array.isArray(t.data)){let e=t;return Nc(e.data[e.offset??0])}}function zb(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 Ca(t){let e=t??{},n=e.fullContext??e;return Object.keys({...n.indicator,...n.strategy?.config}).length>0}function Di(t){let e=t??{},n=e.fullContext??e,r={...n.indicator,...n.strategy?.config},i={title:U(r.title)??"Indicator",overlay:Nc(r.overlay)??!1,precision:ue(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)?zb(u.data):[],plot1:U(u.plot1)??U(p.plot1),plot2:U(u.plot2)??U(p.plot2)}}),o=n.strategy?qb(n.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function qb(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=ue(s.entry_price),o=ue(s.entry_time),l=ue(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:ue(s.exit_price),exit_time:ue(s.exit_time),exit_comment:U(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var Hb={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 Ic(t){return t==null||t===""?"line":Hb[t]??"line"}function Ri(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 ae(t,e){return Ri(t)?t.trim():e}var kc="#00000000";var Sn="#2962ff",Na="#38c0fd",At="#089981",zt="#f23645",En="#787b86";var Ia="#ff9800",Cn="#5b9cf6",ka="#ff5d00",Aa="#0ecb81",Ma="#f6465d";var Kb=new Map;function D(t,e){Kb.set(t,e)}function Yb(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=Yb;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=Na;function Gb(){return{lineColor:R,lineWidth:2,lineStyle:"solid"}}function Li(t=""){return{value:t,size:"normal",hAlign:"left",vAlign:"top"}}var Uc=class zc{constructor(e){this.locked=!1,this.visible=!0,this.zIndex=0,this.id=e.id??`dw-${zc.seq+=1}`,this.paneId=e.paneId,this.anchors=(e.anchors??[]).map(n=>({time:n.time,price:n.price})),this.style=e.style?{...e.style}:Gb(),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=Li()),Xb(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){}};Uc.seq=0;var fe=Uc;function Xb(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 Yn=[{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:Yn,group:"line"}],rt=[{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"}],Pa=[{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:Pa,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 Da(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 Jt(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 Nr(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 Ge(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 Zb=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]}}},Qb=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]}}},Jb=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]=Ge(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]}}},Ra=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]}}},ev=class extends Ra{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]=Ge(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}},tv=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]}}},nv=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]}}},rv=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]}}},iv=class extends Ra{constructor(){super(...arguments),this.type="infoline"}},sv=class extends Ra{constructor(){super(...arguments),this.type="trendangle"}},av=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&&Jt(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]}}},ov={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Oa=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=ov[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&&Jt(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}},lv=class extends Oa{constructor(t){super(t),this.type="text",this.text||(this.text={...Li(),size:"large"})}schema(){return{fields:[...re],textIsContent:!0}}},cv=class extends Oa{constructor(t){super(t),this.type="note",this.text||(this.text=Li("Note"))}defaultLabel(){return"Note"}schema(){return{fields:[...te,...rt,...re],textIsContent:!0}}},uv=class extends Oa{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,...rt,...re.filter(t=>t.path!=="text.value")]}}},hv={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Fi=class extends fe{constructor(t){super(t),this.text||(this.text=Li(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=hv[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&&Jt(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,...rt,...re],textIsContent:!0}}},pv=class extends Fi{constructor(){super(...arguments),this.type="callout"}},dv=class extends Fi{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,...rt,...re.filter(t=>t.path!=="text.value")]}}},fv=class extends Fi{constructor(){super(...arguments),this.type="comment"}defaultLabel(){return"Comment"}},mv=class extends Fi{constructor(){super(...arguments),this.type="signpost"}defaultLabel(){return"Signpost"}},Mt=class extends fe{hitTest(t,e,n,r){let i=this.geometry(n);return i?this.style.fillColor&&i.fill&&Nr(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}}},yv=class extends Mt{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,...rt,...re]}}},gv=class extends Mt{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,...rt,...re]}}},xv=class extends Mt{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,...rt,...re]}}},_v=2;function Ac(){return{midColor:En,midStyle:"solid",upperColor:At,upperStyle:"solid",lowerColor:zt,lowerStyle:"solid",upperFill:`${At}26`,lowerFill:`${zt}26`,showR2:!0}}function bv(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:_v*p,r2:Math.max(0,Math.min(1,d*d)),n:e}}var vv=class extends fe{constructor(t){super(t),this.type="regressionchannel",this.cachedRange=null,this.reg||(this.reg=Ac())}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?bv(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 Nr(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={...Ac(),...t}}},Mc=`${Cn}00`;function Tc(){return{midColor:Cn,midStyle:"solid",multiplier:1,upperColor:Mc,upperStyle:"solid",lowerColor:Mc,lowerStyle:"solid",bandFill:`${Cn}33`}}function wv(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=Tc())}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=wv(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?Nr(t,e,this.bandPolygon(i))?!0:Ta(t,e,i.mid,r)||Ta(t,e,i.upper,r)||Ta(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={...Tc(),...t}}};function Ta(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 Ev=`${At}66`,Cv=`${zt}66`,Nv=`${At}BF`,Iv=`${zt}BF`;function Pc(){return{rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:Ev,downColor:Cv,vaUpColor:Nv,vaDownColor:Iv,showVah:!0,vahColor:En,vahStyle:"solid",showVal:!0,valColor:En,valStyle:"solid",showPoc:!0,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:!1,developingPocColor:Sn,developingPocStyle:"dotted",showDevelopingVa:!1,developingVaColor:Sn,developingVaStyle:"dotted"}}function kv(t,e){return t<0?0:t>=e?e-1:t}function qc(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 Hc(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(kv(Math.floor((l-e)/n),s));for(let l of o)t[l][a]+=i}function Kc(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 Av(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)Hc(o,r,a,d);let l=Kc(o);if(!l)return null;let{poc:c,maxTotal:u}=l,{vaFrom:p,vaTo:h}=qc(o,c,n);return{rows:o,rowH:a,min:r,maxTotal:u,poc:c,vaFrom:p,vaTo:h}}function Mv(t,e,n,r){let i=Av(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){Hc(l,s,a,h);let d=Kc(l);if(!d)continue;let{poc:f}=d,{vaFrom:m,vaTo:_}=qc(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 Tv=class extends fe{constructor(t){super(t),this.type="fixedrangevp",this.cachedRange=null,this.frvp||(this.frvp=Pc())}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=Mv(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 N=t.yOf(i.min+w*i.rowH,this.paneId);if(N==null)return null;f.push(N)}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 N=[];for(let E of w){let A=m(E.price);A!=null&&N.push([t.xOf(E.time),A])}return N};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(Nr(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:Yn,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:Yn,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:Yn,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:Yn,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:Yn,group:"line"}]}}writeProps(){return{...this.frvp}}readProps(t){this.frvp={...Pc(),...t}}},Pv=class extends Mt{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:[Ge(i[0],i[1],l,c,"right",h,d),Ge(s[0],s[1],s[0]+u,s[1]+p,"right",h,d),Ge(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]}}},Yc=class extends Mt{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:[Ge(o[0],o[1],c,u,"right",d,f),Ge(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Ge(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]}}},Dv=class extends Yc{constructor(){super(...arguments),this.type="schiffpitchfork"}medianStart(t,e){return{time:t.time,price:(t.price+e.price)/2}}},Rv=class extends Yc{constructor(){super(...arguments),this.type="modifiedschiffpitchfork"}medianStart(t,e){return{time:(t.time+e.time)/2,price:(t.price+e.price)/2}}},Ov=class extends Mt{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:[Ge(c,u,c+p,u+h,"right",d,f),Ge(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Ge(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]}}},Lv=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]}}},Dc=48,Fv=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<=Dc;n+=1){let r=n/Dc*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:Da(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,...rt,...re]}}},Bv=class extends Mt{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,...rt,...re]}}},Vv=512,La=class extends Mt{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 La{constructor(){super(...arguments),this.type="polyline"}},Gc=class extends La{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}}},$v=class extends Gc{constructor(){super(...arguments),this.type="freehand"}},jv=[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Width",kind:"number",min:4,max:60,step:1,group:"line"}],Uv=class extends Gc{constructor(){super(...arguments),this.type="highlighter"}schema(){return{fields:jv}}},zv=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,...rt,...re]}}},qv=class extends Mt{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")})),...rt,...re]}}},Hv=class extends La{constructor(){super(...arguments),this.type="path"}},Rc=40,Kv=class extends Mt{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;_<=Rc;_+=1){let b=_/Rc*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")})),...rt,...re]}}},Oc=40,Yv=class extends Mt{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<=Oc;a+=1){let o=a/Oc,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,...rt,...re]}}},Gv={head:11,headW:9,stemW:3.5,len:22},Xc=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}=Gv,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&&Nr(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]}}},Xv=class extends Xc{constructor(){super(...arguments),this.type="arrowmarkup"}dir(){return"up"}},Zv=class extends Xc{constructor(){super(...arguments),this.type="arrowmarkdown"}dir(){return"down"}},Qv=["\\u2605","\\u2606","\\u25CF","\\u25C6","\\u25B2","\\u25BC","\\u27A4","\\u2691","\\u271A","\\u2715","\\u2764","\\u2666"],Jv=["small","normal","large","huge"],Lc={small:16,normal:22,large:32,huge:44},Zc=class extends fe{constructor(t){super(t),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal")}sizePx(){return Lc[this.size]??Lc.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:Qv.map(t=>({value:t,label:t})),group:"line"},{path:"size",label:"Size",kind:"select",options:Jv.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)}},ew=class extends Zc{constructor(){super(...arguments),this.type="flagmark"}defaultGlyph(){return"\\u2691"}},tw=class extends Zc{constructor(){super(...arguments),this.type="iconstamp"}defaultGlyph(){return"\\u2605"}},Fc=t=>t==="small"||t==="normal"||t==="large"||t==="huge";function nw(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 Tt=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(nw).filter(n=>n!=null);e.length&&(this.levels=e)}Fc(t.numbersSize)&&(this.numbersSize=t.numbersSize),Fc(t.labelsSize)&&(this.labelsSize=t.labelsSize)}},Qc=class extends Tt{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)}}},Gn=En,Nn=zt,In=Ia,Oi="#4caf50",Cr=At,kn=Cn,Bi="#9c27b0",rw="#e91e63",Jc="#26a69a",iw="#ab47bc",sw="#ef5350",aw="#ffb74d",ow="#38c0fd",eu="#b2b5be",Er=[ow,kn,Cr,Oi,In,Nn,rw,Bi,Gn,Jc,iw,sw];function tu(t){return Er[(t%Er.length+Er.length)%Er.length]}var lw=[[0,Gn],[.125,Nn],[.236,Nn],[.25,Nn],[.382,In],[.5,Oi],[.618,Cr],[.75,kn],[.786,kn],[1,Gn],[1.272,kn],[1.382,In],[1.618,Nn],[2,Gn],[2.382,In],[2.618,In],[3,Gn],[4.236,Oi],[6.854,Cr],[11.09,kn]];function cw(t,e=0){return lw.find(([n])=>n===t)?.[1]??tu(e)}function it(t){return t.map((e,n)=>{let r=typeof e=="number"?{ratio:e}:e;return{ratio:r.ratio,color:r.color??cw(r.ratio,n),enabled:r.enabled!==!1,...r.label?{label:r.label}:{}}})}function uw(t,e=t){return Array.from({length:t},(n,r)=>({ratio:r+1,color:tu(r),enabled:r<e,label:String(r+1)}))}var hw=it([0,.236,.382,.5,.618,.786,1]),pw=class extends Qc{constructor(){super(...arguments),this.type="fibretracement"}defaultLevels(){return hw}},dw=it([0,.382,.618,1,1.272,1.618,{ratio:2.618,color:Bi}]),fw=class extends Qc{constructor(){super(...arguments),this.type="fibextension"}defaultLevels(){return dw}},mw=it([0,.382,.5,.618,1,1.618,{ratio:2.618,color:Bi}]),yw=class extends Tt{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 mw}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)}}},gw=it([.236,.382,.5,.618,.786,1]),xw=class extends Tt{constructor(){super(...arguments),this.type="fibfan"}defaultLevels(){return gw}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]=Ge(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)}}},_w=[0,1,2,3,5,8,13,21,34].map(t=>({ratio:t,color:R,enabled:!0})),bw=class extends Tt{constructor(){super(...arguments),this.type="fibtimezones"}defaultLevels(){return _w}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}},vw=it([0,.236,.382,.5,.618,.786,1,1.618,2.618]),ww=class extends Tt{constructor(){super(...arguments),this.type="fibchannel"}defaultLevels(){return vw}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=it([0,.236,.382,.5,.618,.786,1]),Ew=class extends Tt{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,_=Ge(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=Ge(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)}}},Cw=it([0,.382,{ratio:.5,enabled:!1},.618,1,1.382,1.618,2,2.382,2.618,3]),Nw=class extends Tt{constructor(){super(...arguments),this.type="trendfibtime"}defaultLevels(){return Cw}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 Iw(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 Fa=class extends Tt{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(Iw(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)}}},kw=it([.236,.382,.5,.618,.786,1,1.618,2.618]),Aw=class extends Fa{constructor(){super(...arguments),this.type="fibcircles"}defaultLevels(){return kw}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}}},Mw=it([.236,.382,.5,.618,.786,1,1.618,2.618]),Tw=class extends Fa{constructor(){super(...arguments),this.type="fibarcs"}defaultLevels(){return Mw}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]]:[]}},Pw=it([.236,.382,.5,.618,.786,1]),Dw=class extends Fa{constructor(){super(...arguments),this.type="fibwedge"}defaultLevels(){return Pw}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}},Rw=1.6180339887,Bc=Math.log(Rw)/(Math.PI/2),Ow=Math.PI/64,Lw=Math.PI,Fw=.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(Fw/o)/Bc,-8*Math.PI*2),u=[];for(let p=c;p<=Lw;p+=Ow){let h=o*Math.exp(Bc*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&&Da(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=it([{ratio:.125,color:Nn,label:"1/8"},{ratio:.25,color:In,label:"1/4"},{ratio:.333,color:aw,label:"1/3"},{ratio:.5,color:Oi,label:"1/2"},{ratio:1,color:eu,label:"1/1"},{ratio:2,color:Cr,label:"2/1"},{ratio:3,color:kn,label:"3/1"},{ratio:4,color:Jc,label:"4/1"},{ratio:8,color:Bi,label:"8/1"}]),Ww=class extends Tt{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]=Ge(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)}}},$w=it([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),jw=class extends Tt{constructor(){super(...arguments),this.type="gannbox"}defaultLevels(){return $w}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??Gn;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&&Jt(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)}}},Uw=it([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),zw=[{label:"3x1",x:3,y:1,color:Nn},{label:"2x1",x:2,y:1,color:In},{label:"1x1",x:1,y:1,color:eu},{label:"1x2",x:1,y:2,color:Cr},{label:"1x3",x:1,y:3,color:kn}];var qw=class extends Tt{constructor(){super(...arguments),this.type="gannsquare"}defaultLevels(){return Uw}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 zw){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&&Jt(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 Hw=24,Kw=.75;function Yw(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 Gw(t){let e=[];for(let n=0;n<t;n+=1)Yw(n,t)&&e.push(n);return e}var Xw=class extends fe{constructor(t){super(t),this.type="dedekind",this.maxCurvature===void 0&&(this.maxCurvature=Hw)}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<Kw)continue;let v=Gw(m);if(v.length===0)continue;let S=Math.floor(c)-1,w=Math.ceil(u)+1;for(let N=S;N<=w;N+=1)for(let E of v){let A=E/m+N;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&&Jt(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 Vi=6,Zw=2;function nu(t=Vi){return[...uw(Er.length,t)]}function Qw(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 Wi={path:"showRatios",label:"Show ratios",kind:"boolean",group:"behavior"},$i=class extends fe{constructor(t){super(t),this.waveCount===void 0&&(this.waveCount=Vi),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(N=>N.enabled&&N.ratio>0).slice().sort((N,E)=>N.ratio-E.ratio);if(d.length===0)return null;let f=Math.max(1,this.machNumber()),m=[];for(let N of d){let E=N.ratio*c;m.push({cx:o+f*(E-c)*u,cy:l+f*(E-c)*p,r:E,color:N.color,ratio:N.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 N=-p,E=u;w.push([_-N*S,b-E*S,_+N*S,b+E*S])}else{let N=Math.asin(1/f),E=Math.cos(N),A=Math.sin(N),F=(B,O,K)=>[B*E-O*K*A,B*K*A+O*E],[I,j]=F(u,p,1),[P,q]=F(u,p,-1);w.push([_,b,_+I*S,b+j*S]),w.push([_,b,_+P*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"},Wi,...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(Qw).filter(n=>n!=null);e.length&&(this.levels=e)}}},Jw=class extends $i{constructor(){super(...arguments),this.type="sonic"}defaultLevels(){return nu(Vi)}machNumber(){return 1}},eS=class extends $i{constructor(t){super(t),this.type="supersonic",this.mach===void 0&&(this.mach=Zw)}defaultLevels(){return nu(Vi)}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"},Wi,...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)))}},ru=it([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),tS=2,nS=class extends $i{constructor(){super(...arguments),this.type="goldensonic"}shouldSyncWaveCount(){return!1}defaultLevels(){return ru}machNumber(){return 1}schema(){return{fields:[...te,Wi,...re]}}},rS=class extends $i{constructor(t){super(t),this.type="goldensupersonic",this.mach===void 0&&(this.mach=tS)}shouldSyncWaveCount(){return!1}defaultLevels(){return ru}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"},Wi,...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)))}},Xn=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&&Da(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?rt:[]]}}},iS=class extends Xn{constructor(){super(...arguments),this.type="xabcd"}vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}},sS=class extends Xn{constructor(){super(...arguments),this.type="abcd"}vertexLabels(){return["A","B","C","D"]}legRatios(){return!0}},aS=class extends Xn{constructor(){super(...arguments),this.type="elliottimpulse"}vertexLabels(){return["1","2","3","4","5"]}},oS=class extends Xn{constructor(){super(...arguments),this.type="elliottcorrection"}vertexLabels(){return["A","B","C"]}},lS=class extends Xn{constructor(){super(...arguments),this.type="headshoulders"}vertexLabels(){return["","LS","","H","","RS",""]}necklineIndices(){return[2,4]}},Zn=class extends Xn{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)}},cS=class extends Zn{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}}}},uS=class extends Zn{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}}}},hS=class extends Zn{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}}}},pS=class extends Zn{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}}}},dS=class extends Zn{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}}}},fS={min:1.272,max:1.414},mS={min:.74,max:.83},yS=class extends Zn{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(),fS)&&this.inBand(this.cdOverXc(),mS)}};function Vc(t){return`${t>=0?"+":""}${t.toFixed(2)}`}function gS(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 xS=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`${Vc(n)} (${Vc(r)}%)`}timeLabel(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return"";let r=gS(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&&Jt(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:Pa,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)}},_S=class extends xS{constructor(){super(...arguments),this.type="datepricerange"}},bS=[{value:"long",label:"Long"},{value:"short",label:"Short"}],qt=class _t extends fe{constructor(e){super(e),this.type="position",this.riskPercent===void 0&&(this.riskPercent=_t.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=_t.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=_t.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=_t.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)>=_t.MIN_DRAG_PX?(o=a,l=r+Math.max(Math.abs(e.xOf(s.time)-r),_t.MIN_WIDTH_PX)):(o=i-_t.DEFAULT_RISK_PX*_t.DEFAULT_RR,l=r+_t.DEFAULT_WIDTH_PX);let c=i-(o-i)/_t.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)/_t.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 $${wS(this.dollarLoss())} \\xB7 Size ${SS(this.positionSize())}`}targetLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Wc(e.target)}`:"";return`Target +${this.rewardPct().toFixed(2)}%${n}`}stopLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Wc(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 $c(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 Jt(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:bS,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:Pa,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)}};qt.DEFAULT_RR=2;qt.MIN_DRAG_PX=6;qt.DEFAULT_RISK_PX=64;qt.DEFAULT_WIDTH_PX=150;qt.MIN_WIDTH_PX=48;qt.DEFAULT_RISK_PERCENT=1;qt.DEFAULT_ACCOUNT_BALANCE=1e4;qt.DEFAULT_PROFIT_COLOR=Aa;qt.DEFAULT_LOSS_COLOR=Ma;var vS=qt;function wS(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 Wc(t){return Number.isFinite(t)?Math.abs(t)>=1?t.toFixed(2):t.toPrecision(4).replace(/\\.?0+$/,""):"0"}function $c(t){return Math.round(t*1e8)/1e8}var ES=[{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 jc(){return{timeframe:"auto",upColor:"",downColor:""}}var CS=class extends fe{constructor(t){super(t),this.type="magnifier",this.chipRect=null,this.magnifier||(this.magnifier=jc())}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?Jt(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:ES,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={...jc(),...t}}},NS=new Map;function L(t){NS.set(t.type,t)}var IS=k(\'<line x1="4" y1="19" x2="20" y2="5"/>\'),kS=k(\'<line x1="3" y1="12" x2="21" y2="12"/>\');L({type:"trendline",group:"lines",label:"Trend Line",icon:IS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Zb(t)});L({type:"hline",group:"lines",label:"Horizontal Line",icon:kS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"dashed"},create:t=>new Qb(t)});var AS=k(\'<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>\'),MS=k(\'<rect x="4" y="6" width="16" height="12" rx="1"/>\'),TS=k(\'<path d="M5 6h14M12 6v13"/>\');L({type:"ray",group:"lines",label:"Ray",icon:AS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Jb(t)});var PS=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"/>\'),DS=k(\'<line x1="12" y1="3" x2="12" y2="21"/>\'),RS=k(\'<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>\'),OS=k(\'<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>\'),LS=k(\'<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>\'),FS=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:PS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new ev(t)});L({type:"vline",group:"lines",label:"Vertical Line",icon:DS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new tv(t)});L({type:"hray",group:"lines",label:"Horizontal Ray",icon:RS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new nv(t)});L({type:"crossline",group:"lines",label:"Cross Line",icon:OS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new rv(t)});L({type:"infoline",group:"lines",label:"Info Line",icon:LS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new iv(t)});L({type:"trendangle",group:"lines",label:"Trend Angle",icon:FS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new sv(t)});L({type:"box",group:"shapes",label:"Rectangle",icon:MS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}26`},create:t=>new av(t)});L({type:"text",group:"annotations",label:"Text",icon:TS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new lv(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 pv(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"/>\'),$S=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"/>\'),jS=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"/>\'),US=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 cv(t)});L({type:"pricenote",group:"annotations",label:"Price Note",icon:WS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new dv(t)});L({type:"comment",group:"annotations",label:"Comment",icon:$S,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new fv(t)});L({type:"pricelabel",group:"annotations",label:"Price Label",icon:jS,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new uv(t)});L({type:"signpost",group:"annotations",label:"Signpost",icon:US,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid",fillColor:`${R}d9`},create:t=>new mv(t)});var zS=k(\'<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>\'),qS=k(\'<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>\'),HS=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:zS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new yv(t)});L({type:"disjointchannel",group:"channels",label:"Disjoint Channel",icon:qS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new gv(t)});var KS=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:KS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new xv(t)});var YS=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:YS,defaultStyle:{lineColor:En,lineWidth:1,lineStyle:"solid"},create:t=>new vv(t)});L({type:"pitchfork",group:"pitchforks",label:"Pitchfork",icon:HS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Pv(t)});var GS=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"/>\'),XS=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"/>\'),ZS=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:GS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Dv(t)});L({type:"modifiedschiffpitchfork",group:"pitchforks",label:"Modified Schiff Pitchfork",icon:XS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Rv(t)});L({type:"insidepitchfork",group:"pitchforks",label:"Inside Pitchfork",icon:ZS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Ov(t)});var QS=k(\'<path d="M7 7h10v10"/><path d="M7 17 17 7"/>\'),JS=k(\'<ellipse cx="12" cy="12" rx="9" ry="6"/>\'),eE=k(\'<path d="M12 4 20 19 4 19Z"/>\');L({type:"arrow",group:"shapes",label:"Arrow",icon:QS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",arrowRight:!0},create:t=>new Lv(t)});L({type:"ellipse",group:"shapes",label:"Ellipse",icon:JS,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new Fv(t)});L({type:"triangle",group:"shapes",label:"Triangle",icon:eE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new Bv(t)});var tE=k(\'<polyline points="3 17 9 10 13 14 21 5"/>\'),nE=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"/>\'),rE=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:tE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Wv(t)});L({type:"freehand",group:"shapes",label:"Brush",icon:nE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new $v(t)});L({type:"highlighter",group:"shapes",label:"Highlighter",icon:rE,defaultStyle:{lineColor:`${ka}59`,lineWidth:14,lineStyle:"solid"},create:t=>new Uv(t)});var iE=k(\'<circle cx="12" cy="12" r="8"/>\'),sE=k(\'<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>\'),aE=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"/>\'),oE=k(\'<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>\'),lE=k(\'<path d="M4 18Q12 1 20 14"/>\'),cE=k(\'<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>\'),uE=k(\'<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>\');L({type:"circle",group:"shapes",label:"Circle",icon:iE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}1a`},create:t=>new zv(t)});L({type:"rotatedrect",group:"shapes",label:"Rotated Rectangle",icon:sE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}26`},create:t=>new qv(t)});L({type:"path",group:"shapes",label:"Path",icon:aE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Hv(t)});L({type:"arc",group:"shapes",label:"Arc",icon:oE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid",fillColor:`${R}26`},create:t=>new Kv(t)});L({type:"curve",group:"shapes",label:"Curve",icon:lE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Yv(t)});L({type:"arrowmarkup",group:"shapes",label:"Arrow Mark Up",icon:cE,defaultStyle:{lineColor:At,lineWidth:1,lineStyle:"solid"},create:t=>new Xv(t)});L({type:"arrowmarkdown",group:"shapes",label:"Arrow Mark Down",icon:uE,defaultStyle:{lineColor:zt,lineWidth:1,lineStyle:"solid"},create:t=>new Zv(t)});var hE=k(\'<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>\'),pE=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:hE,defaultStyle:{lineColor:Sn,lineWidth:1,lineStyle:"solid"},create:t=>new ew(t)});L({type:"iconstamp",group:"stamps",label:"Icon",icon:pE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new tw(t)});var dE=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"/>\'),fE=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:dE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new pw(t)});L({type:"fibextension",group:"fibonacci",label:"Fib Extension",icon:fE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new fw(t)});var mE=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:mE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new yw(t)});var yE=k(\'<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>\'),gE=k(\'<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>\');L({type:"fibfan",group:"fibonacci",label:"Fib Fan",icon:yE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new xw(t)});L({type:"fibtimezones",group:"fibonacci",label:"Fib Time Zones",icon:gE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"dashed"},create:t=>new bw(t)});var xE=k(\'<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>\'),_E=k(\'<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>\'),bE=k(\'<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>\');L({type:"fibchannel",group:"fibonacci",label:"Fib Channel",icon:xE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new ww(t)});L({type:"fibspeedfan",group:"fibonacci",label:"Fib Speed Resistance Fan",icon:_E,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Ew(t)});L({type:"trendfibtime",group:"fibonacci",label:"Trend-Based Fib Time",icon:bE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"dashed"},create:t=>new Nw(t)});var vE=k(\'<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>\'),wE=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"/>\'),EE=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:vE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Aw(t)});L({type:"fibarcs",group:"fibonacci",label:"Fib Speed Resistance Arcs",icon:wE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Tw(t)});L({type:"fibwedge",group:"fibonacci",label:"Fib Wedge",icon:SE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Dw(t)});L({type:"fibspiral",group:"fibonacci",label:"Fib Spiral",icon:EE,defaultStyle:{lineColor:R,lineWidth:2,lineStyle:"solid"},create:t=>new Bw(t)});var CE=k(\'<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>\'),NE=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:CE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Ww(t)});L({type:"gannbox",group:"fibonacci",label:"Gann Box",icon:NE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new jw(t)});var IE=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:IE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new qw(t)});var kE=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:kE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Xw(t)});var AE=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"/>\'),ME=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:AE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new Jw(t)});L({type:"supersonic",group:"geometry",label:"Supersonic",icon:ME,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new eS(t)});var TE=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"/>\'),PE=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:TE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new nS(t)});L({type:"goldensupersonic",group:"geometry",label:"Golden Supersonic",icon:PE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new rS(t)});var DE=k(\'<path d="M3 18 7 8 11 14 15 6 20 16"/>\'),RE=k(\'<path d="M4 17 9 7 14 15 20 5"/>\'),OE=k(\'<path d="M3 19 8 9 12 13 17 5 21 9"/>\'),LE=k(\'<path d="M4 7 11 16 20 9"/>\'),FE=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:DE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new iS(t)});L({type:"abcd",group:"patterns",label:"ABCD Pattern",icon:RE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new sS(t)});L({type:"elliottimpulse",group:"patterns",label:"Elliott Impulse Wave (1-5)",icon:OE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new aS(t)});L({type:"elliottcorrection",group:"patterns",label:"Elliott Correction Wave (ABC)",icon:LE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new oS(t)});L({type:"headshoulders",group:"patterns",label:"Head & Shoulders",icon:FE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"},create:t=>new lS(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"/>\'),Qn={group:"patterns",icon:BE,defaultStyle:{lineColor:R,lineWidth:1,lineStyle:"solid"}};L({type:"gartley",label:"Gartley",...Qn,create:t=>new cS(t)});L({type:"bat",label:"Bat",...Qn,create:t=>new uS(t)});L({type:"butterfly",label:"Butterfly",...Qn,create:t=>new hS(t)});L({type:"crab",label:"Crab",...Qn,create:t=>new pS(t)});L({type:"shark",label:"Shark",...Qn,create:t=>new dS(t)});L({type:"cypher",label:"Cypher",...Qn,create:t=>new yS(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 _S(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 vS(t)});var $E=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:$E,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 CS(t)});var jE=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:jE,defaultStyle:{lineColor:Cn,lineWidth:2,lineStyle:"solid"},create:t=>new Sv(t)});var UE=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:UE,defaultStyle:{lineColor:At,lineWidth:1,lineStyle:"solid"},create:t=>new Tv(t)});function Ba(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var zE=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var iu=["indicators","screenshot"],YC=new Set(iu),GC=new Set(zE);var su=280;var XC=`\n.vela-panel[hidden] { display: none !important; }\n.vela-panel {\n position: relative;\n width: var(--vela-panel-w, ${su}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 ji=class{constructor(){ro(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),Ba({instanceId:e,kind:n,title:r,ordinal:s})}};function Jn(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 Ui(t){let e=(U(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function ou(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 Wa(t){let e=(U(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function lu(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=ae(t);return e?{color:e,invisible:!1}:{invisible:!0}}return{invisible:!0}}function Va(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}=lu(t.color);return{id:e,paneId:"unrouted",xloc:Ui(t.xloc),x1:n,y1:r,x2:i,y2:s,extend:ou(t.extend),color:c,invisible:u,width:Math.max(1,xe(t.width)??1),style:Wa(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function cu(t,e,n){let r=[];for(let i of Jn(t)){if(i._deleted===!0)continue;let s=Va(i,n.next(e,"line",String(i.id??r.length)));s&&r.push(s)}return r}function uu(t,e,n){let r=[];for(let i of Jn(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=Va(s,`${o}:a`),c=Va(a,`${o}:b`);!l||!c||r.push({id:o,paneId:"unrouted",line1:l,line2:c,color:ae(i.color),overlay:i.force_overlay===!0})}return r}function hu(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function qE(t){if(typeof t=="number"&&Number.isFinite(t))return hu(t);let e=(U(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function $a(t){let e=(U(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function pu(t){let e=(U(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function ja(t){return(U(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function du(t,e,n){let r=[];for(let i of Jn(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:Ui(i.xloc),left:s,top:a,right:o,bottom:l,extend:ou(i.extend),bgColor:ae(i.bgcolor),borderColor:ae(i.border_color),borderWidth:Math.max(0,xe(i.border_width)??1),borderStyle:Wa(i.border_style),text:u&&u.length>0?u:void 0,textColor:ae(i.text_color),textSize:qE(i.text_size),hAlign:$a(i.text_halign),vAlign:pu(i.text_valign),wrap:(U(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:ja(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return r}var HE=["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 KE(t){let e=(U(t)??"").toLowerCase().replace(/^style_/,"");return HE.includes(e)?e:"label_down"}function YE(t){let e=(U(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function fu(t){if(typeof t=="number"&&Number.isFinite(t))return hu(t);let e=(U(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function mu(t,e,n){let r=[];for(let i of Jn(t)){if(i._deleted===!0)continue;let s=xe(i.x),a=YE(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}=lu(i.color);r.push({id:n.next(e,"label",String(i.id??r.length)),paneId:"unrouted",xloc:Ui(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:KE(i.style),color:u,noFill:p,textColor:ae(i.textcolor),size:fu(i.size),textAlign:$a(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:ja(i.text_font_family),overlay:i.force_overlay===!0})}return r}function yu(t,e,n){let r=[];for(let i of Jn(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=Ui(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:ae(i.line_color),fillColor:ae(i.fill_color),lineWidth:Math.max(1,xe(i.line_width)??1),lineStyle:Wa(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 GE=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function XE(t){let e=(U(t)??"").toLowerCase();return GE.includes(e)?e:"top_right"}function ZE(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:fu(t)}function au(t){let e=xe(t);return e!==void 0&&e>0?e:void 0}function QE(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:ae(e.text_color),bgColor:ae(e.bgcolor),hAlign:$a(e.text_halign),vAlign:pu(e.text_valign),textSize:ZE(e.text_size),fontFamily:ja(e.text_font_family),tooltip:r&&r.length>0?r:void 0,bold:i.includes("bold"),italic:i.includes("italic"),width:au(e.width),height:au(e.height),merged:e._merged===!0}}function JE(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 gu(t,e,n){let r=[];for(let i of Jn(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(l=>(Array.isArray(l)?l:[]).map(c=>QE(c))),o=JE(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:XE(i.position),columns:Math.max(0,Math.round(xe(i.columns)??0)),rows:Math.max(0,Math.round(xe(i.rows)??0)),bgColor:ae(i.bgcolor),frameColor:ae(i.frame_color),frameWidth:Math.max(0,xe(i.frame_width)??0),borderColor:ae(i.border_color),borderWidth:Math.max(0,xe(i.border_width)??0),cells:a,merges:o,overlay:i.force_overlay===!0})}return r}var _u=Sn;function bu(t,e){let n=new ji,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 N=Ic(w.style),E=w.title??w.key;switch(N){case"skip":break;case"barcolor":{if(!Ir(w.options.display))break;let A=kr(w.data.length,ue(w.options.show_last));for(let F=A;F<w.data.length;F+=1){let I=w.data[F],j=ae(I.options?.color);j&&f.push({time:I.time,color:j})}break}case"fill":Ir(w.options.display)&&b.push(w);break;case"hline":{let A=hC(w,E,e,n);A&&o.push(A);break}case"background":Ir(w.options.display)&&a.push(...pC(w,E,e,n));break;case"drawing_line":l.push(...cu(w,e,n));break;case"drawing_box":c.push(...du(w,e,n));break;case"label":u.push(...mu(w,e,n));break;case"drawing_polyline":p.push(...yu(w,e,n));break;case"linefill":h.push(...uu(w,e,n));break;case"table":d.push(...gu(w,e,n));break;case"markers":Ir(w.options.display)&&u.push(...dC(w,e,n));break;default:{let A=n.next(e,N,E);m.set(w.key,A),w.options.force_overlay===!0&&_.add(w.key),i.push(tC(N,w,A,E));let F=sC(w,E,e,n);F&&o.push(F)}}}for(let w of b){let N=w.plot1?m.get(w.plot1):void 0,E=w.plot2?m.get(w.plot2):void 0;if(!N||!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:N,toSeriesId:E,...uC(w),...A?{overlay:!0}:{}})}let v=t.trades?eC(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 eC(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 tC(t,e,n,r){let i=ue(e.options.show_last),s=e.options.force_overlay===!0?{overlay:!0}:{},a=vu(e.options.display);if(t==="candle"||t==="bar"){let m={id:n,title:r,paneId:"unrouted",kind:t,bars:cC(e,kr(e.data.length,i)),visible:a.pane,display:a,...s},_=aC(e);return _&&(m.barColors=_),m}let o=t,l=ae(Su(e)),c={...a,pane:a.pane&&!!l},u=ue(e.options.linewidth)??1,p=o==="line"||o==="step"||o==="area",h=lC(iC(oC(e),i,p),ue(e.options.offset)),d={color:l??_u,width:u,lineStyle:Eu(e.options.linestyle)??"solid"},f=ue(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 xu={pane:!0,priceScale:!0,legend:!0,dataWindow:!0},nC={pane:"pane",data_window:"dataWindow",status_line:"legend",price_scale:"priceScale"},rC=["all","none","pane","data_window","status_line","price_scale"];function vu(t){if(typeof t!="string")return{...xu};let e={pane:!1,priceScale:!1,legend:!1,dataWindow:!1};for(let n=0;n<t.length;){let r=rC.find(i=>t.startsWith(i,n));if(!r||r==="all")return{...xu};r!=="none"&&(e[nC[r]]=!0),n+=r.length}return e}function Ir(t){return vu(t).pane}function kr(t,e){return e===void 0||e<=0?0:Math.max(0,t-Math.floor(e))}function iC(t,e,n){let r=kr(t.length,e);return n&&(r-=1),r<=0?t:t.map((i,s)=>s<r?{...i,value:null}:i)}function sC(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:ae(s.options?.color)??ae(Su(t)),lineStyle:"dotted",width:ue(t.options.linewidth),title:e}}return null}function aC(t){let e=!1,n=t.data.map(r=>{let i=r.options??{},s=ae(i.color),a=ae(i.wickcolor),o=ae(i.bordercolor);return!s&&!a&&!o?null:(e=!0,{color:s,wickColor:a,borderColor:o})});return e?n:void 0}function oC(t){let e=t.data.some(n=>Ri(n.options?.color));return t.data.map(n=>{let r=typeof n.value=="number"&&Number.isFinite(n.value)?n.value:null,i=ae(n.options?.color);return i?{time:n.time,value:r,color:i}:e?{time:n.time,value:r,color:kc}:{time:n.time,value:r}})}function wu(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 lC(t,e){if(!e)return t;let n=e*wu(t);return n?t.map(r=>({...r,time:r.time+n})):t}function cC(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 Su(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 uC(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=ue(o.top_value),c=ue(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=>ae(s.options?.color)??null),r=new Set(n.filter(s=>s!==null)),i=n.some(s=>s===null);return r.size===0?{color:ae(t.options.color)}:r.size===1&&!i?{color:[...r][0]}:{colors:n}}function hC(t,e,n,r){if(!Ir(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:ae(t.options.color),lineStyle:Eu(t.options.linestyle)??"dashed",title:e,width:ue(t.options.linewidth)}}function Eu(t){let e=U(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="solid"||e==="dashed"||e==="dotted"?e:void 0}function pC(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=kr(a.length,ue(t.options.show_last));for(;l<a.length;){let c=a[l],u=ae(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&&ae(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 dC(t,e,n){let r=ue(t.options.offset),i=r?r*wu(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?fC(t):null,l=t.options.force_overlay===!0?{overlay:!0}:{},c=[],u=kr(t.data.length,ue(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&&!Ri(_))continue;let b=U(m.text)??U(t.options.text),v=b&&b.trim().length>0?b:void 0,S=a?f&&d>0?At:zt:void 0,w=ae(m.color)??ae(t.options.color)??S??_u,N=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:yC(U(m.location)??U(t.options.location)),text:N!==void 0?v!==void 0?`${N}\n${v}`:N:v,style:N!==void 0?"none":gC(U(m.shape)??U(t.options.shape)),color:w,textColor:ae(m.textcolor)??ae(t.options.textcolor)??(N!==void 0?w:void 0),size:o!==null&&f?mC(Math.abs(d),o):xC(U(m.size)??U(t.options.size)),textAlign:"center",fontFamily:"default",...l})}return c}function fC(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:ue(t.options.minheight)??5,maxH:ue(t.options.maxheight)??100}}function mC(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 yC(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function gC(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 xC(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function _C(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 bC(t){return t==="int"||t==="float"||t==="price"||t==="time"}var Cu={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 vC(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return Cu[e]??t}function wC(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?Cu[e[1].toLowerCase()]:void 0}function SC(t){return(t.type==="string"||t.type==null)&&wC(t.defval)!==void 0}function EC(t,e){if(e==="bool")return!!t;if(bC(e))return typeof t=="number"?t:Number(t)||0;let n=typeof t=="string"?t:t==null?"":String(t);return e==="color"?vC(n):n}function Nu(t){return t.map((e,n)=>{let r=SC(e)?"color":_C(e.type);return{key:e.varId??e.title??`input${n}`,title:e.title??e.varId??`Input ${n+1}`,type:r,defval:EC(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 CC(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";default:return"string"}}function Ua(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 NC(t){let e=t.replace(/_/g," ");return e.charAt(0).toUpperCase()+e.slice(1)}function Iu(t,e){let n=t.getPropsMeta(),r=t.prop;return n.filter(i=>i.mutable&&i.name).map(i=>{let s=i.name,a=CC(i.type),o=Ua(i.defval,a),l=Ua(r[s]??i.defval,a),c=e?.[s],u=l!==o?l:c!==void 0?Ua(c,a):o;return{key:s,title:NC(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 ku(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 Au=!1;function za(){if(Au)return;Au=!0;let t=zn.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 Mu=["plotshape","plotchar","plotarrow"],Tu=!1;function qa(){if(Tu)return;Tu=!0;let t=zn.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!==void 0||!Mu.some(a=>r.includes(a)))return;let s={idx:void 0,n:0,len:0};for(let a of Mu){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 IC(t,e,n){if(n==="none")return[];if(n==="strategy"&&t.getDeclarationType()!=="strategy")return[];let r=Iu(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 Lu(t,e,n,r="all"){let i=xn.from(t),s=Nu(i.getInputsMeta()),a=IC(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 Ka(t,e,n,r={}){let i=JSON.stringify([n,r]);if(t.lastKey!==i||!t.lastInd){let s=new xn(e,n);ku(s,r),t.lastInd=s,t.lastKey=i}return t.lastInd}async function Fu(t){let{ind:e,bars:n,market:r,visibleRange:i,prepared:s,instanceId:a,inputs:o,props:l,fetchSeries:c}=t;za(),qa();let u=Ya(n,r.timeframe,r.symbolInfo),p={getMarketData:(m,_,b,v,S)=>Vu(m,_,r)?Promise.resolve(u):Wu(c,m,_,b,v,S,qi(r,m)),getSymbolInfo:async m=>qi(r,m)},h=new un(p,Ga(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:Ca(d)?Bu(d,a,s,o,l??{},n[0]?.time):null,alerts:(d.alerts??[]).map(ju),warnings:(d.warnings??[]).map(Uu),reactsToViewport:f,ctx:d}}function Bu(t,e,n,r,i,s){let{model:a}=bu(Di(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={...Ou(n.inputs),...r},n.props&&(a.props=n.props,a.propValues={...Ou(n.props),...i}),s!=null&&(a.anchorTime=s),a}function Pu(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 Ha=(t,e)=>e.start<=e.end?t>=e.start&&t<e.end:t>=e.start||t<e.end,zi=new Map;function Du(t,e){let n=`${e}:${Math.floor(t/36e5)}`,r=zi.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}zi.size>1e5&&zi.clear(),zi.set(n,r)}return Number.isNaN(r)?null:((Math.floor(t/6e4)+r)%1440+1440)%1440}function kC(t){return t==null?null:/^\\d+$/.test(t)?Number(t):/^1?D$/i.test(t)?1440:null}function AC(t,e,n){let r=typeof n=="object"&&n!=null?n:null,i=kC(e),s=Pu(r?.session),a=typeof r?.timezone=="string"?r.timezone:null;if(i==null||s==null||a==null||t.length===0)return null;let o=Pu(r?.session_extended),l=s;if(o)for(let c of t){let u=Du(c.time,a);if(u!=null&&!Ha(u,s)&&Ha(u,o)){l=o;break}}return c=>{let u=Du(c,a);if(u==null||!Ha(u,l))return null;let p=(l.end-u+1440)%1440||1440;return c+Math.min(i,p)*6e4}}function Ya(t,e,n){let r=AC(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 Ga(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function Vu(t,e,n){return(t==null||t===Ga(n))&&(e==null||e===n.timeframe)}async function Wu(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 Ya(o,n,a)}function MC(t,e,n){let r="",i=!1;return{markDirty:()=>{i=!0},getMarketData:async(s,a,o,l,c)=>{let u=e();if(!Vu(s,a,u))return Wu(n,s,a,o,l,c,qi(u,s));let p=Ya(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=>qi(e(),s)}}function $u(t){let e=t.bars();za(),qa();let n=Ka(t.cache,t.token.source,t.inputs,t.props??{}),r=e[0]?.time,i=Math.max(1,e.length),s=MC(t.bars,t.market,t.fetchSeries),a=new un(s,Ga(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,!!Ca(u)))try{t.onModel(Bu(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?.(ju(u))),o.on("warning",u=>t.onWarning?.(Uu(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 qi(t,e){let n=e&&e.split(";")[0];return n&&n!==t.symbol?Ru({symbol:n,timeframe:t.timeframe}):Ru(t)}function Ru(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 Ou(t){let e={};for(let n of t)e[n.key]=n.defval;return e}function ju(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 Uu(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var ut=t=>ue(t)??0;function zu(t){if(t==null||typeof t!="object")return;let e=t;return{position:ut(e.position_size),avgPrice:ut(e.position_avg_price),equity:ut(e.equity),openPnl:ut(e.openprofit),netPnl:ut(e.netprofit),grossProfit:ut(e.grossprofit),grossLoss:ut(e.grossloss),wins:ut(e.wintrades),losses:ut(e.losstrades),even:ut(e.eventrades),maxDrawdown:ut(e.max_drawdown),maxRunup:ut(e.max_runup),initialCapital:ut(e.initial_capital)}}function qu(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=ue(i.entry_price),a=ue(i.entry_time),o=ue(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=ue(i.exit_price),c=ue(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"})}return n}function Hu(t){try{return structuredClone(t)}catch{return}}function TC(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return Hu(e?e[e.length-1]:t)}function PC(t){return t.replace(/^glb\\d+_/,"")}function Xa(t,e){if(t)for(let[n,r]of Object.entries(t)){if(n.startsWith("_"))continue;let i=TC(r);i!==void 0&&(e[PC(n)]=i)}}function Ku(t,e,n){let r=t??{},i=r.fullContext??r,s=h=>!n||n.includes(h),a=s("meta")||s("plots")?Di(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:Hu(d.value)??null})));let l={};s("variables")&&(Xa(i.const,l),Xa(i.var,l),Xa(i.let,l));let c=s("strategy")?zu(i.strategy):void 0,u=s("trades")&&i.strategy?qu(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 Yu=self,Be=t=>Yu.postMessage(t),pn=new Map,Qa=new Map,DC=0,Gu=(t,e,n)=>new Promise((r,i)=>{let s=++DC;Qa.set(s,{resolve:r,reject:i}),Be({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:n})});function Hi(t){t.chain=t.chain.then(()=>OC(t))}function RC(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 Za(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=$u({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,props:t.props,bars:()=>t.bars,market:()=>t.market,fetchSeries:Gu,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 OC(t){if(!t.stopped)try{let e=t.prepared.token,n=await Fu({ind:Ka(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:Gu});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)})}}Yu.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{Be({kind:"prepared",reqId:e.reqId,prepared:Lu(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(pn.set(n.id,n),n.mode==="live"){n.deferred||Za(n);return}n.deferred?Be({kind:"done",sessionId:n.id}):Hi(n);return}case"update":{let n=pn.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||Za(n);return}n.deferred?Be({kind:"done",sessionId:n.id}):Hi(n);return}case"setVisibleRange":{let n=pn.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}):Hi(n);return}case"notifyBars":{let n=pn.get(e.sessionId);if(!n||n.mode==="live")return;n.bars=e.bars,n.deferred=!1,Hi(n);return}case"bars":{let n=pn.get(e.sessionId);if(!n||n.mode!=="live")return;if(e.restart){n.bars=e.bars,n.deferred=!1,Za(n);return}for(let r of e.bars)RC(n,r);return}case"getContext":{let n=pn.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:Ku(r,i,e.select)});return}case"stop":{let n=pn.get(e.sessionId);n&&(n.stopped=!0,n.stream?.stop()),pn.delete(e.sessionId);return}case"fetchSeriesResult":{let n=Qa.get(e.reqId);if(!n)return;Qa.delete(e.reqId),e.error?n.reject(new Error(e.error)):n.resolve(e.bars??[]);return}}});})();\n';
|
|
1728
|
+
var worker_default = '"use strict";(()=>{var op=Object.defineProperty;var lp=(t,e,n)=>e in t?op(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var cl=(t,e,n)=>lp(t,typeof e!="symbol"?e+"":e,n);function cp(t){return e=>new X(e.array.map(n=>Math.abs(n)),e.type,t)}function up(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 hp(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 pp(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 dp(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 fp(t){return e=>{e.array.length=0}}function mp(t){return(e,n)=>(e.array.push(...n.array),e)}function yp(t){return e=>new X([...e.array],e.type,t)}function gp(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]),x=Number(s[f]);!isNaN(m)&&m!==null&&m!==void 0&&!isNaN(x)&&x!==null&&x!==void 0&&(a+=m,o+=x,l++,c.push(f))}if(l===0)return NaN;let u=a/l,p=o/l,h=0;for(let f of c){let m=Number(i[f]),x=Number(s[f]);h+=(m-u)*(x-p)}let d=r?l:l-1;return d<=0?NaN:t.precision(h/d)}}function _p(t){return e=>e.array.every(n=>!isNaN(n)&&n)}function xp(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 Qt(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 Ur(t,e){if(t===void 0||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 bp(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(!Ur(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 vp(t){return e=>e.array.length>0?e.array[0]:t.NA}var wp=Object.defineProperty,Sp=(t,e,n)=>e in t?wp(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ep=(t,e,n)=>Sp(t,typeof e!="symbol"?e+"":e,n),Te=class extends Error{constructor(e,n){super(e),Ep(this,"method"),this.name="PineRuntimeError",this.method=n}};function Cp(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new Te(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.get");return e.array[r]}}function Np(t){return(e,n)=>e.array.includes(n)}function Ip(t){return(e,n)=>typeof n=="number"&&n!==n?e.array.findIndex(r=>typeof r=="number"&&r!==r):e.array.indexOf(n)}function kp(t){return(e,n,r)=>{if(!Ur(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 Te(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.insert");e.array.splice(i,0,r)}}function Ap(t){return(e,n=",")=>e.array.join(n)}function Mp(t){return e=>e.array.length>0?e.array[e.array.length-1]:t.NA}function Tp(t){return(e,n)=>e.array.lastIndexOf(n)}function Pp(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 Dp(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 Rp(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 Op(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 Lp(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 Fp(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 Bp(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 Vp(t){return e=>e.array.pop()}function $p(t){return(e,n)=>{if(!Ur(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 Wp(t){return e=>t.precision(t.pine.array.max(e)-t.pine.array.min(e))}function jp(t){return(e,n)=>{let r=n<0?e.array.length+n:n;if(r<0||r>=e.array.length)throw new Te(`Index ${n} is out of bounds, array size is ${e.array.length}.`,"array.remove");return e.array.splice(r,1)[0]}}function Up(t){return e=>{e.array.reverse()}}function qp(t){return(e,n,r)=>{if(!Ur(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 Te(`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 zp(t){return e=>e.array.shift()}function Hp(t){return e=>e.array.length}function Kp(t){return(e,n,r)=>{let i=r!==void 0?r:void 0;return new X(e.array.slice(n,i),e.type,t)}}function Yp(t){return e=>e.array.some(n=>!isNaN(n)&&n)}var Tn=(t=>(t[t.ascending=1]="ascending",t[t.descending=0]="descending",t))(Tn||{}),Wa=(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))(Wa||{}),ja=(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))(ja||{}),Ua=(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))(Ua||{}),gi=["pane","data_window","status_line","price_scale"],Gp=[...gi,"all","none"];function _i(t){let e=new Set;if(typeof t!="string")return e;for(let n=0;n<t.length;){let r=Gp.find(i=>t.startsWith(i,n));if(!r)break;if(r==="all")return new Set(gi);r!=="none"&&e.add(r),n+=r.length}return e}function lc(t){let e=gi.filter(n=>t.has(n));return e.length===gi.length?"all":e.length===0?"none":e.join("")}function cc(t,e){return lc(new Set([..._i(t),..._i(e)]))}function uc(t,e){let n=_i(t);for(let r of _i(e))n.delete(r);return lc(n)}var qa=(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))(qa||{}),za=(t=>(t.abovebar="AboveBar",t.belowbar="BelowBar",t.absolute="Absolute",t.bottom="Bottom",t.top="Top",t))(za||{}),Ha=(t=>(t.auto="auto",t.tiny="tiny",t.small="small",t.normal="normal",t.large="large",t.huge="huge",t))(Ha||{}),Ka=(t=>(t.inherit="inherit",t.mintick="mintick",t.percent="percent",t.price="price",t.volume="volume",t))(Ka||{}),hc=(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))(hc||{}),Ya=(t=>(t.gaps_on="gaps_on",t.gaps_off="gaps_off",t.lookahead_on="lookahead_on",t.lookahead_off="lookahead_off",t))(Ya||{}),Ga=(t=>(t.bar_index="bi",t.bar_time="bt",t))(Ga||{}),Xa=(t=>(t.price="pr",t.abovebar="ab",t.belowbar="bl",t))(Xa||{}),Za=(t=>(t.left="l",t.right="r",t.both="b",t.none="n",t))(Za||{}),Qa=(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))(Qa||{}),Ja=(t=>(t.family_default="default",t.family_monospace="monospace",t))(Ja||{}),eo=(t=>(t.none="none",t.splits="splits",t.dividends="dividends",t))(eo||{}),to=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(to||{}),no=(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))(no||{}),ro=(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))(ro||{}),io=(t=>(t.denominator="splits_denominator",t.numerator="splits_numerator",t))(io||{}),so=(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))(so||{}),ao=(t=>(t.left="left",t.none="none",t.right="right",t))(ao||{}),oo=(t=>(t.inherit="inherit",t.off="off",t.on="on",t))(oo||{}),pc={order:Tn,currency:Wa,dayofweek:ja,display:{...Ua,__union:cc,__minus:uc},shape:qa,location:za,size:Ha,format:Ka,barmerge:Ya,xloc:Ga,yloc:Xa,extend:Za,text:Qa,font:Ja,adjustment:eo,backadjustment:to,earnings:no,dividends:ro,splits:io,position:so,scale:ao,settlement_as_close:oo},Xp=Object.freeze({__proto__:null,order:Tn,currency:Wa,dayofweek:ja,display:Ua,displayUnion:cc,displayMinus:uc,shape:qa,location:za,size:Ha,format:Ka,plot:hc,barmerge:Ya,xloc:Ga,yloc:Xa,extend:Za,text:Qa,font:Ja,adjustment:eo,backadjustment:to,earnings:no,dividends:ro,splits:io,position:so,scale:ao,settlement_as_close:oo,default:pc});function Zp(t){return(e,n=Tn.ascending)=>{e.array.sort((r,i)=>{let s=isNaN(r)?1/0:r,a=isNaN(i)?1/0:i;return n===Tn.ascending?s-a:a-s})}}function Qp(t){return(e,n=Tn.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===Tn.ascending?a-o:o-a}),new X(r,G.int,t)}}function Jp(t){return e=>{let n=t.array.avg(e),r=t.array.stdev(e);return isNaN(r)?new X(e.array.map(()=>NaN),G.int,t):r===0?new X(e.array.map(()=>1),G.int,t):new X(e.array.map(i=>(i-n)/r),G.int,t)}}function ed(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 td(t){return e=>t.precision(e.array.reduce((n,r)=>{let i=Number(r);return isNaN(i)?n:n+i},0))}function nd(t){return(e,n)=>{if(!Ur(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 rd(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 id=Object.defineProperty,sd=(t,e,n)=>e in t?id(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J=(t,e,n)=>sd(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||{}),X=class{constructor(e,n,r){this.array=e,this.type=n,this.context=r,J(this,"_abs"),J(this,"_avg"),J(this,"_binary_search"),J(this,"_binary_search_leftmost"),J(this,"_binary_search_rightmost"),J(this,"_clear"),J(this,"_concat"),J(this,"_copy"),J(this,"_covariance"),J(this,"_every"),J(this,"_fill"),J(this,"_first"),J(this,"_get"),J(this,"_includes"),J(this,"_indexof"),J(this,"_insert"),J(this,"_join"),J(this,"_last"),J(this,"_lastindexof"),J(this,"_max"),J(this,"_median"),J(this,"_min"),J(this,"_mode"),J(this,"_percentile_linear_interpolation"),J(this,"_percentile_nearest_rank"),J(this,"_percentrank"),J(this,"_pop"),J(this,"_push"),J(this,"_range"),J(this,"_remove"),J(this,"_reverse"),J(this,"_set"),J(this,"_shift"),J(this,"_size"),J(this,"_slice"),J(this,"_some"),J(this,"_sort"),J(this,"_sort_indices"),J(this,"_standardize"),J(this,"_stdev"),J(this,"_sum"),J(this,"_unshift"),J(this,"_variance"),this._abs=cp(this.context),this._avg=up(this.context),this._binary_search=hp(this.context),this._binary_search_leftmost=pp(this.context),this._binary_search_rightmost=dp(this.context),this._clear=fp(this.context),this._concat=mp(this.context),this._copy=yp(this.context),this._covariance=gp(this.context),this._every=_p(this.context),this._fill=bp(this.context),this._first=vp(this.context),this._get=Cp(this.context),this._includes=Np(this.context),this._indexof=Ip(this.context),this._insert=kp(this.context),this._join=Ap(this.context),this._last=Mp(this.context),this._lastindexof=Tp(this.context),this._max=Pp(this.context),this._median=Dp(this.context),this._min=Rp(this.context),this._mode=Op(this.context),this._percentile_linear_interpolation=Lp(this.context),this._percentile_nearest_rank=Fp(this.context),this._percentrank=Bp(this.context),this._pop=Vp(this.context),this._push=$p(this.context),this._range=Wp(this.context),this._remove=jp(this.context),this._reverse=Up(this.context),this._set=qp(this.context),this._shift=zp(this.context),this._size=Hp(this.context),this._slice=Kp(this.context),this._some=Yp(this.context),this._sort=Zp(this.context),this._sort_indices=Qp(this.context),this._standardize=Jp(this.context),this._stdev=ed(this.context),this._sum=td(this.context),this._unshift=nd(this.context),this._variance=rd(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 ad(t){return(...e)=>new X([...e],xp(e),t)}function od(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 X(i,G.any,t)}return new X(Array(r).fill(t.precision(n||0)),Qt(n||0),t)}}function ld(t){return(e=0,n=!1)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.bool,t)}}function cd(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.box,t)}}function ud(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.color,t)}}function hd(t){return(e=0,n=NaN)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(t.precision(n)),G.float,t)}}function pd(t){return(e=0,n=0)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(t.precision(n)),G.int,t)}}function dd(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.label,t)}}function fd(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.line,t)}}function md(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.linefill,t)}}function yd(t){return(e=0,n="")=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(Array(r).fill(n),G.string,t)}}function gd(t){return(e=0,n=null)=>{let r=typeof e=="number"&&e>0&&!isNaN(e)?Math.floor(e):0;return new X(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){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 _d(t){return(e,n=0)=>y.from(e).get(n)}var Fs=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=ad(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=od(e),this.new_bool=ld(e),this.new_box=cd(e),this.new_color=ud(e),this.new_float=hd(e),this.new_int=pd(e),this.new_label=dd(e),this.new_line=fd(e),this.new_linefill=md(e),this.new_string=yd(e),this.new_table=gd(e),this.param=_d(),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 xd(t){return e=>{e.map.clear()}}function bd(t){return(e,n)=>e.map.has(n)}function vd(t){return e=>{let n=new xi(t);return n.map=new Map(e.map),n}}function wd(t){return(e,n)=>{let r=e.map.get(n);return r===void 0?NaN:r}}function Sd(t){return e=>{let n=Array.from(e.map.keys()),r=Qt(n[0]);return new X(n,r,t)}}function Ed(t){return(e,n,r)=>{let i=e.map.get(n);return e.map.set(n,r),i===void 0?NaN:i}}function Cd(t){return(e,n)=>{for(let[r,i]of n.map)e.map.set(r,i)}}function Nd(t){return(e,n)=>{let r=e.map.get(n);return e.map.delete(n)?r:NaN}}function Id(t){return e=>e.map.size}function kd(t){return e=>{let n=Array.from(e.map.values()),r=Qt(n[0]);return new X(n,r,t)}}var Ad=Object.defineProperty,Md=(t,e,n)=>e in t?Ad(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Et=(t,e,n)=>Md(t,typeof e!="symbol"?e+"":e,n),xi=class{constructor(e){this.context=e,Et(this,"map"),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=xd(this.context),this._contains=bd(this.context),this._copy=vd(this.context),this._get=wd(this.context),this._keys=Sd(this.context),this._put=Ed(this.context),this._put_all=Cd(this.context),this._remove=Nd(this.context),this._size=Id(this.context),this._values=kd(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 Td(t){return()=>new xi(t)}function Pd(t){return(e,n=0)=>y.from(e).get(n)}var Bs=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=Td(e),this.param=Pd(),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 Dd(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r&&(r instanceof X?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 Rd(t){return(e,n,r)=>{let i=e.matrix.length,s=[];if(r)if(r instanceof X)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 Od(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 Ld(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n<0||n>=i)throw new Te(`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=Qt(s[0]);return new X(s,a,t)}}function Fd(t){return e=>e.matrix.length===0?0:e.matrix[0].length}function Bd(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 Vd(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0,i=new ue(n,r,NaN,t);return i.matrix=e.matrix.map(s=>[...s]),i}}function $d(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 Wd(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;return n!==r?NaN:$d(e.matrix)}}function jd(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new ue(0,0,NaN,t);let i=e.matrix[0].length,s=new ue(r,i,NaN,t);if(n instanceof ue)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 Ud(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 qd(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r){let a=Qt(e.matrix[0][0]);return new X([],a,t)}let i=Ud(e.matrix),s=Qt(i[0]);return new X(i,s,t)}}function zd(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new ue(0,0,NaN,t);let i=new ue(n,r,0,t);for(let s=0;s<n;s++)i.matrix[s][s]=1;return i}}function Hd(t){return e=>{let n=e.matrix.length;return n===0?0:n*e.matrix[0].length}}function Kd(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 Yd(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 Te(`Row index ${n} is out of bounds, matrix has ${i} rows.`,"matrix.get");if(r<0||r>=s)throw new Te(`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 ui(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 Gd(t){return e=>{let n=e.matrix.length,r=n>0?e.matrix[0].length:0;if(n!==r)return new ue(n,r,NaN,t);let i=ui(e.matrix),s=new ue(n,r,NaN,t);return s.matrix=i,s}}function Xd(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 Zd(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 Qd(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 Jd(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 ef(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 tf(t){return e=>{let n=e.matrix.length;if(n===0)return!1;let r=e.matrix[0].length;return n===r}}function nf(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 rf(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 sf(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 af(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 of(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 ue(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 lf(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 cf(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 uf(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 hf(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 pf(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(n instanceof ue){let s=n.matrix.length,a=s>0?n.matrix[0].length:0;if(i!==s)return new ue(0,0,NaN,t);let o=new ue(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 X||Array.isArray(n.array||n)){let s=n.array||n;if(i!==s.length)return new X([],"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 X(a,"float",t)}else{let s=n,a=new ue(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 df(t){return e=>{let n=e.matrix.length;if(n===0)return new ue(0,0,NaN,t);let r=e.matrix[0].length;if(n===r){let u=ui(e.matrix),p=new ue(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 x=0;x<h;x++){m[x]=new Array(f).fill(0);for(let b=0;b<d;b++){let v=u[x][b];if(v!==0)for(let E=0;E<f;E++)m[x][E]+=v*p[b][E]}}return m},a=e.matrix,o=i(a),l;if(n>r){let u=s(o,a),p=ui(u);l=s(p,o)}else{let u=s(a,o),p=ui(u);l=s(o,p)}let c=new ue(r,n,NaN,t);return c.matrix=l,c}}function ff(t){return(e,n)=>{let r=e.matrix.length,i=r>0?e.matrix[0].length:0;if(r!==i)return new ue(0,0,NaN,t);let s=new ue(r,i,0,t);for(let l=0;l<r;l++)s.matrix[l][l]=1;let a=new ue(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 ue(r,i,NaN,t);for(;o>0;){if(o%2===1){let c=new ue(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 ue(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 mf(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 yf(t){return(e,n)=>{let r=e.matrix.length;if(r===0){let a=Qt(e.matrix[0][0]);return new X([],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=Qt(i[0]);return new X(i,s,t)}}function gf(t){return(e,n)=>{let r=e.matrix.splice(n,1),i=Qt(r[0][0]);return new X(r[0]||[],i,t)}}function _f(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 xf(t){return e=>{e.matrix.reverse();for(let n of e.matrix)n.reverse()}}function bf(t){return(e,n)=>{let r=e.matrix.length;if(n<0||n>=r)throw new Te(`Row index ${n} is out of bounds, matrix has ${r} rows.`,"matrix.row");let i=Qt(e.matrix[n][0]);return new X([...e.matrix[n]],i,t)}}function vf(t){return e=>e.matrix.length}function wf(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 Te(`Row index ${n} is out of bounds, matrix has ${s} rows.`,"matrix.set");if(r<0||r>=a)throw new Te(`Column index ${r} is out of bounds, matrix has ${a} columns.`,"matrix.set");e.matrix[n][r]=i}}function Sf(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 Ef(t){return(e,n,r,i,s)=>{let a=r-n,o=s-i,l=new ue(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 Cf(t){return(e,n)=>{let r=e.matrix.length;if(r===0)return new ue(0,0,NaN,t);let i=e.matrix[0].length,s=new ue(r,i,NaN,t);if(n instanceof ue)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 Nf(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 If(t){return(e,n,r)=>{let i=e.matrix[n];e.matrix[n]=e.matrix[r],e.matrix[r]=i}}function kf(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 Af(t){return e=>{let n=e.matrix.length;if(n===0)return new ue(0,0,NaN,t);let r=e.matrix[0].length,i=new ue(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 Mf=Object.defineProperty,Tf=(t,e,n)=>e in t?Mf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,K=(t,e,n)=>Tf(t,typeof e!="symbol"?e+"":e,n),ue=class{constructor(e=0,n=0,r=NaN,i){if(this.context=i,K(this,"matrix"),K(this,"_add_col"),K(this,"_add_row"),K(this,"_avg"),K(this,"_col"),K(this,"_columns"),K(this,"_concat"),K(this,"_copy"),K(this,"_det"),K(this,"_diff"),K(this,"_eigenvalues"),K(this,"_eigenvectors"),K(this,"_elements_count"),K(this,"_fill"),K(this,"_get"),K(this,"_inv"),K(this,"_is_antidiagonal"),K(this,"_is_antisymmetric"),K(this,"_is_binary"),K(this,"_is_diagonal"),K(this,"_is_identity"),K(this,"_is_square"),K(this,"_is_stochastic"),K(this,"_is_symmetric"),K(this,"_is_triangular"),K(this,"_is_zero"),K(this,"_kron"),K(this,"_max"),K(this,"_median"),K(this,"_min"),K(this,"_mode"),K(this,"_mult"),K(this,"_pinv"),K(this,"_pow"),K(this,"_rank"),K(this,"_remove_col"),K(this,"_remove_row"),K(this,"_reshape"),K(this,"_reverse"),K(this,"_row"),K(this,"_rows"),K(this,"_set"),K(this,"_sort"),K(this,"_submatrix"),K(this,"_sum"),K(this,"_swap_columns"),K(this,"_swap_rows"),K(this,"_trace"),K(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=Dd(this.context),this._add_row=Rd(this.context),this._avg=Od(this.context),this._col=Ld(this.context),this._columns=Fd(this.context),this._concat=Bd(this.context),this._copy=Vd(this.context),this._det=Wd(this.context),this._diff=jd(this.context),this._eigenvalues=qd(this.context),this._eigenvectors=zd(this.context),this._elements_count=Hd(this.context),this._fill=Kd(this.context),this._get=Yd(this.context),this._inv=Gd(this.context),this._is_antidiagonal=Xd(this.context),this._is_antisymmetric=Zd(this.context),this._is_binary=Qd(this.context),this._is_diagonal=Jd(this.context),this._is_identity=ef(this.context),this._is_square=tf(this.context),this._is_stochastic=nf(this.context),this._is_symmetric=rf(this.context),this._is_triangular=sf(this.context),this._is_zero=af(this.context),this._kron=of(this.context),this._max=lf(this.context),this._median=cf(this.context),this._min=uf(this.context),this._mode=hf(this.context),this._mult=pf(this.context),this._pinv=df(this.context),this._pow=ff(this.context),this._rank=mf(this.context),this._remove_col=yf(this.context),this._remove_row=gf(this.context),this._reshape=_f(this.context),this._reverse=xf(this.context),this._row=bf(this.context),this._rows=vf(this.context),this._set=wf(this.context),this._sort=Sf(this.context),this._submatrix=Ef(this.context),this._sum=Cf(this.context),this._swap_columns=Nf(this.context),this._swap_rows=If(this.context),this._trace=kf(this.context),this._transpose=Af(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 Ct(t){return(e,n,r)=>new ue(e,n,r,t)}function Pf(t){return(e,n=0)=>y.from(e).get(n)}var Vs=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=Ct(e),this.param=Pf(),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=Ct(e),this.new_int=Ct(e),this.new_string=Ct(e),this.new_bool=Ct(e),this.new_color=Ct(e),this.new_line=Ct(e),this.new_label=Ct(e),this.new_box=Ct(e),this.new_linefill=Ct(e),this.new_table=Ct(e)}},Df=Object.defineProperty,Rf=(t,e,n)=>e in t?Df(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Of=(t,e,n)=>Rf(t,typeof e!="symbol"?e+"":e,n),$s=class{constructor(e){this.context=e,Of(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}},Lf=Object.defineProperty,Ff=(t,e,n)=>e in t?Lf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ws=(t,e,n)=>Ff(t,typeof e!="symbol"?e+"":e,n),Ge=class t{constructor(e,n,r){ws(this,"time"),ws(this,"index"),ws(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 Bf(t){return typeof t=="object"&&t&&(t.title!==void 0||t._plotKey!==void 0)&&t.data!==void 0&&t.options!==void 0}var ul={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 Ge,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 Ge)&&!Bf(t)};function Tt(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(ul.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=ul[n[p]];typeof d=="function"&&d(l)?i[p]=l:a[u]=!1}}}return{...i,...s,...r}}var Vf=/^(\\d{2})(\\d{2})-(\\d{2})(\\d{2})$/;function $f(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(Vf);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 Wf(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 jf=Object.defineProperty,Uf=(t,e,n)=>e in t?jf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,tr=(t,e,n)=>Uf(t,typeof e!="symbol"?e+"":e,n);function Ws(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 js(t,e){let n=qf(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 qf(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 vn(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 zf(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 Hf=[["timeframe"],["timeframe","bars_back"],["timeframe","session","bars_back"],["timeframe","session","bars_back","timeframe_bars_back"],["timeframe","session","timezone","bars_back","timeframe_bars_back"]],Kf={timeframe:"string",session:"string",timezone:"string",bars_back:"number",timeframe_bars_back:"number"},bi=class{constructor(e,n="openTime"){tr(this,"context"),tr(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,Hf,Kf),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=Ws(s),u=Ws(l),p;if(!c||c===u?p=o:p=js(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=$f(n);if(!i)throw new Te(`Invalid session specification: "${n}"`,"time");let s=vn(e,r),a=s.hour*60+s.minute;return Wf(i,a,s.dayOfWeek)}},Yf=[[],["time"],["time","timezone"]],Gf={time:"number",timezone:"string"},Ut=class{constructor(e,n){tr(this,"context"),tr(this,"extractor"),tr(this,"_cache",[]),tr(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(vn(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=e.map(o=>o instanceof y?o.get(0):o);if(n.length===0)return this.__value.get(0);let r=ye(n,Yf,Gf),i=r.time;if(i===void 0||isNaN(i))return NaN;let s=r.timezone||this.context.pine?.syminfo?.timezone||"UTC",a=vn(i,s);return this.extractor(a)}},un={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=>zf(t.year,t.month,t.day),year:t=>t.year},Xf=Object.defineProperty,Zf=(t,e,n)=>e in t?Xf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hl=(t,e,n)=>Zf(t,typeof e!="symbol"?e+"":e,n),Us=class{constructor(e){this.context=e,hl(this,"regular","regular"),hl(this,"extended","extended")}get _timezone(){return this.context.pine?.syminfo?.timezone||"UTC"}_dayKey(e){let n=vn(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}},Qf=Object.defineProperty,Jf=(t,e,n)=>e in t?Qf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,em=(t,e,n)=>Jf(t,typeof e!="symbol"?e+"":e,n),_n=class t{constructor(e,n,r){this._definition=e,this.context=n,em(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 dc=Object.defineProperty,tm=Object.getOwnPropertyDescriptor,nm=(t,e,n)=>e in t?dc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fc=(t,e,n,r)=>{for(var i=r>1?void 0:r?tm(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&&dc(e,n,i),i},rr=(t,e,n)=>nm(t,typeof e!="symbol"?e+"":e,n),rm=[["dateString"],["year","month","day","hour","minute","second"],["timezone","year","month","day","hour","minute","second"]],im={dateString:"string",timezone:"string",year:"number",month:"number",day:"number",hour:"number",minute:"number",second:"number"},sm=["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"],am={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 om(t){return ye(t,sm,am)}var rt=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}},Kn={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"},vi=class{constructor(e){this.context=e,rr(this,"_firedKeys",new Set),rr(this,"_fallbackCounter",0),rr(this,"_fallbackLastExecTick",-1)}get freq_all(){return Kn.freq_all}get freq_once_per_bar(){return Kn.freq_once_per_bar}get freq_once_per_bar_close(){return Kn.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):Kn.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===Kn.freq_once_per_bar){if(this._firedKeys.has(c))return;this._firedKeys.add(c)}else if(s===Kn.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})}};fc([M],vi.prototype,"any",1);var wi=class{constructor(e){this.context=e,rr(this,"_acCounter",0),rr(this,"_acLastExecTick",-1),rr(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=om(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,rm,im);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=E=>parseInt(c.find(w=>w.type===E)?.value||"0",10),p=u("year"),h=u("month"),d=u("day"),f=u("hour");f===24&&(f=0);let m=u("minute"),x=u("second"),b=new Date(Date.UTC(p,h-1,d,f,m,x));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 _n)){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 _n(a,this.context,i)},copy:function(s){return new _n(s.__def__,this.context,i)},_fieldDefaults:r,_definitionKeys:n};return i}};fc([M],wi.prototype,"alertcondition",1);function An(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 lm(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 Ae={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 Xi(t){if(typeof t!="string")return null;let e=t.trim(),n=e.startsWith("color.")?e.slice(6):e;return Object.prototype.hasOwnProperty.call(Ae,n)&&(e=Ae[n]),An(e)}function qs(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 cm(t){let e=Xi(t);return e?qs(e[0],e[1],e[2],e[3]):t}function $t(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 zs=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=$t(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=Ae[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=$t(e),n=$t(n),r=$t(r),i=$t(i),s=$t(s),e==null||typeof e=="number"&&isNaN(e))return NaN;if(n==null||typeof n=="number"&&isNaN(n))return NaN;if(r==null||typeof r=="number"&&isNaN(r))return NaN;if(i==null||typeof i=="number"&&isNaN(i))return NaN;if(s==null||typeof s=="number"&&isNaN(s))return NaN;let a=0;r!==n&&(a=(e-n)/(r-n)),a=Math.max(0,Math.min(1,a));let o=An(typeof i=="string"?i:"#000000")||[0,0,0,1],l=An(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 lm(c,u,p,h)}r(e){if(e=$t(e),!e||typeof e!="string")return NaN;let n=An(e);return n?n[0]:NaN}g(e){if(e=$t(e),!e||typeof e!="string")return NaN;let n=An(e);return n?n[1]:NaN}b(e){if(e=$t(e),!e||typeof e!="string")return NaN;let n=An(e);return n?n[2]:NaN}t(e){if(e=$t(e),!e||typeof e!="string")return NaN;let n=An(e);return n?Math.round(100-n[3]*100):NaN}aqua(){return Ae.aqua}black(){return Ae.black}blue(){return Ae.blue}fuchsia(){return Ae.fuchsia}gray(){return Ae.gray}green(){return Ae.green}lime(){return Ae.lime}maroon(){return Ae.maroon}navy(){return Ae.navy}olive(){return Ae.olive}orange(){return Ae.orange}purple(){return Ae.purple}red(){return Ae.red}silver(){return Ae.silver}teal(){return Ae.teal}white(){return Ae.white}yellow(){return Ae.yellow}},Zi=new Set(["open","high","low","close","hl2","hlc3","ohlc4","hlcc4","volume"]);function mc(t,e){if(!Zi.has(e))return;let n=t?.data?.[e];if(n!=null)return y.from(n).get(0)}var um=[["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"]],hm={defval:"primitive",title:"string",tooltip:"string",inline:"string",group:"string",display:"string",confirm:"boolean",options:"array",minval:"number",maxval:"number",step:"number"},pm=t=>!!t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,"__varId")||Object.prototype.hasOwnProperty.call(t,"__inputId"));function st(t){let e,n;for(;t.length&&pm(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=ye(t,um,hm);return e!==void 0&&(r.__varId=e),n!==void 0&&(r.__inputId=n),r}function at(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 dm(t){return(...e)=>{let n=st(e),r=at(t,n);if(typeof r=="string"&&typeof n.defval=="number"){let i=mc(t,r);if(i!==void 0)return i}return r}}function fm(t){return(...e)=>{let n=st(e);return at(t,n)}}function mm(t){return(...e)=>{let n=st(e);return at(t,n)}}function ym(t){return(...e)=>{let n=st(e);return at(t,n)}}function gm(t){return(...e)=>{let n=st(e);return at(t,n)}}function _m(t){return(...e)=>{let n=st(e);return at(t,n)}}function xm(t){return(e,n=0)=>y.from(e).get(n)}function bm(t){return(...e)=>{let n=st(e);return at(t,n)}}function vm(t){return(...e)=>{let n=st(e);return at(t,n)}}function wm(t){return(...e)=>{let n=st(e),r=at(t,n);if(typeof r=="string"){let i=mc(t,r);return i!==void 0?i:n.defval}return r}}function Sm(t){return(...e)=>{let n=st(e);return at(t,n)}}function Em(t){return(...e)=>{let n=st(e);return at(t,n)}}function Cm(t){return(...e)=>{let n=st(e);return at(t,n)}}function Nm(t){return(...e)=>{let n=st(e);return at(t,n)}}function Im(t){return(...e)=>{let n=st(e);return at(t,n)}}var km=Object.defineProperty,Am=(t,e,n)=>e in t?km(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ze=(t,e,n)=>Am(t,typeof e!="symbol"?e+"":e,n),Mm={any:dm,bool:fm,color:mm,enum:ym,float:gm,int:_m,param:xm,price:bm,session:vm,source:wm,string:Sm,symbol:Em,text_area:Cm,time:Nm,timeframe:Im},Hs=class{constructor(e){this.context=e,ze(this,"any"),ze(this,"bool"),ze(this,"color"),ze(this,"enum"),ze(this,"float"),ze(this,"int"),ze(this,"param"),ze(this,"price"),ze(this,"session"),ze(this,"source"),ze(this,"string"),ze(this,"symbol"),ze(this,"text_area"),ze(this,"time"),ze(this,"timeframe"),Object.entries(Mm).forEach(([n,r])=>{this[n]=r(e)})}};function Tm(t){return e=>Math.abs(y.from(e).get(0))}function Pm(t){return e=>Math.acos(y.from(e).get(0))}function Dm(t){return e=>Math.asin(y.from(e).get(0))}function Rm(t){return e=>Math.atan(y.from(e).get(0))}function Om(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return n.reduce((r,i)=>r+i,0)/n.length}}function Lm(t){return e=>Math.ceil(y.from(e).get(0))}function Fm(t){return e=>Math.cos(y.from(e).get(0))}function Bm(t){return()=>Math.E}function Vm(t){return e=>Math.exp(y.from(e).get(0))}function $m(t){return e=>Math.floor(y.from(e).get(0))}function Wm(t){return e=>Math.log(y.from(e).get(0))}function jm(t){return e=>Math.log(y.from(e).get(0))}function Um(t){return e=>Math.log10(y.from(e).get(0))}function qm(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.max(...n)}}function zm(t){return(...e)=>{let n=e.map(r=>y.from(r).get(0));return Math.min(...n)}}function Hm(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 Km(t){return()=>1.618033988749895}function Ym(t){return()=>Math.PI}function Gm(t){return(e,n)=>Math.pow(y.from(e).get(0),y.from(n).get(0))}function Xm(t){return()=>Math.random()}var pl=t=>Number.isNaN(t)?NaN:Math.sign(t)*Math.round(Math.abs(t));function Zm(t){return(e,n)=>{let r=y.from(e).get(0),i=n==null?0:y.from(n).get(0);if(!i)return pl(r);let s=10**i;return pl(r*s)/s}}function Qm(t){return e=>t.precision(Math.round(y.from(e).get(0)/t.pine.syminfo.mintick)*t.pine.syminfo.mintick)}function Jm(t){return()=>.6180339887498948}function ey(t){return e=>Math.sign(y.from(e).get(0))}function ty(t){return e=>Math.sin(y.from(e).get(0))}function ny(t){return e=>Math.sqrt(y.from(e).get(0))}function ry(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 iy(t){return e=>Math.tan(y.from(e).get(0))}function sy(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(180/Math.PI)}}function ay(t){return e=>{let n=y.from(e).get(0);return n==null||Number.isNaN(n)?NaN:n*(Math.PI/180)}}function oy(t){return(e,n)=>e&&n}function ly(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 cy(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 uy(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 hy(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 py(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 dy(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 fy(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 my(t){return(e,n)=>e||n}var yy=Object.defineProperty,gy=(t,e,n)=>e in t?yy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e,n)=>gy(t,typeof e!="symbol"?e+"":e,n),_y={abs:Tm,acos:Pm,asin:Dm,atan:Rm,avg:Om,ceil:Lm,cos:Fm,e:Bm,exp:Vm,floor:$m,ln:Wm,log:jm,log10:Um,max:qm,min:zm,param:Hm,phi:Km,pi:Ym,pow:Gm,random:Xm,round:Zm,round_to_mintick:Qm,rphi:Jm,sign:ey,sin:ty,sqrt:ny,sum:ry,tan:iy,todegrees:sy,toradians:ay,__and:oy,__eq:ly,__ge:cy,__gt:uy,__idiv:hy,__le:py,__lt:dy,__neq:fy,__or:my},Ks=class{constructor(e){this.context=e,ee(this,"_cache",{}),ee(this,"abs"),ee(this,"acos"),ee(this,"asin"),ee(this,"atan"),ee(this,"avg"),ee(this,"ceil"),ee(this,"cos"),ee(this,"e"),ee(this,"exp"),ee(this,"floor"),ee(this,"ln"),ee(this,"log"),ee(this,"log10"),ee(this,"max"),ee(this,"min"),ee(this,"param"),ee(this,"phi"),ee(this,"pi"),ee(this,"pow"),ee(this,"random"),ee(this,"round"),ee(this,"round_to_mintick"),ee(this,"rphi"),ee(this,"sign"),ee(this,"sin"),ee(this,"sqrt"),ee(this,"sum"),ee(this,"tan"),ee(this,"todegrees"),ee(this,"toradians"),ee(this,"__and"),ee(this,"__eq"),ee(this,"__ge"),ee(this,"__gt"),ee(this,"__idiv"),ee(this,"__le"),ee(this,"__lt"),ee(this,"__neq"),ee(this,"__or"),Object.entries(_y).forEach(([n,r])=>{this[n]=r(e)})}};function xy(t){return t!=null&&!Array.isArray(t)&&typeof t.getFootprintData=="function"}var by=Object.defineProperty,vy=(t,e,n)=>e in t?by(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hn=(t,e,n)=>vy(t,typeof e!="symbol"?e+"":e,n),Si=class{constructor(e){hn(this,"downPrice"),hn(this,"upPrice"),hn(this,"buyVolume"),hn(this,"sellVolume"),hn(this,"totalVolume"),hn(this,"deltaVolume"),hn(this,"buyImbalance"),hn(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 rt?NaN:t instanceof y?t.get(0):typeof t=="function"?t():t}var wy=Object.defineProperty,Sy=(t,e,n)=>e in t?wy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nt=(t,e,n)=>Sy(t,typeof e!="symbol"?e+"":e,n),_r=1e-10,Ey=.01,Cy=2e3;function Ny(t){return Math.floor(t+1e-6)}function yc(t,e){return Math.floor(t/e)}function dl(t,e,n){return yc(Math.round(t/e),n)}var Ei=class t{constructor(e,n,r,i,s,a,o){Nt(this,"rowList"),Nt(this,"buyVolume"),Nt(this,"sellVolume"),Nt(this,"totalVolume"),Nt(this,"deltaVolume"),Nt(this,"pocIndex"),Nt(this,"vahIndex"),Nt(this,"valIndex"),Nt(this,"_rowSize"),Nt(this,"_firstRowIndex"),Nt(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=I=>e.precision(I),{ticksPerRow:a,mintick:o}=r,l=a*o,c=new Map,u=new Map,p=1/0,h=-1/0;for(let I of n){if(!I||!Number.isFinite(I.price))continue;let U=Number.isFinite(I.buyVolume)?I.buyVolume:0,Y=Number.isFinite(I.sellVolume)?I.sellVolume:0,ae=dl(I.price,o,a);c.set(ae,(c.get(ae)??0)+U),u.set(ae,(u.get(ae)??0)+Y),ae<p&&(p=ae),ae>h&&(h=ae)}if(!Number.isFinite(p))return null;i&&Number.isFinite(i.low)&&Number.isFinite(i.high)&&i.low<=i.high&&(p=Math.min(p,dl(i.low,o,a)),h=Math.max(h,p,yc(Math.round(i.high/o)-1,a)));let d=h-p+1;if(d>Cy)return null;let f=new Array(d),m=new Array(d),x=new Array(d),b=0,v=0;for(let I=0;I<d;I++){let U=c.get(p+I)??0,Y=u.get(p+I)??0;f[I]=U,m[I]=Y,x[I]=U+Y,b+=U,v+=Y}let E=x[0];for(let I=1;I<d;I++)x[I]>E&&(E=x[I]);let w=(d-1)/2,S=-1;for(let I=0;I<d;I++)x[I]+_r<E||(S<0||Math.abs(I-w)<Math.abs(S-w)-_r)&&(S=I);let C=b+v,k=Number.isNaN(r.vaPercent)?0:r.vaPercent,B=C>0?C*k/100+Ey:0,P=S,V=S,A=x[S];for(;P>0||V<d-1;){let I=V<d-1,U=P>0,Y=I?x[V+1]:-1/0,ae=U?x[P-1]:-1/0,te;U?I?Math.abs(Y-ae)<=_r?te=V+1-S<=S-(P-1):te=Y>ae:te=!1:te=!0;let ke=te?Y:ae;if(A+ke>B)break;A+=ke,te?V++:P--}let H=Math.max(r.imbalancePercent/100,1),F=new Array(d);for(let I=0;I<d;I++){let U=f[I],Y=m[I],ae=I>0&&U>0&&U+_r>=H*m[I-1],te=I<d-1&&Y>0&&Y+_r>=H*f[I+1],ke=s((p+I)*l),In=s((p+I+1)*l);F[I]=new Si({downPrice:ke,upPrice:In,buyVolume:s(U),sellVolume:s(Y),totalVolume:s(U+Y),delta:s(U-Y),buyImbalance:ae,sellImbalance:te})}return new t(e,F,l,p,{buy:s(b),sell:s(v),total:s(C),delta:s(b-v)},S,{lo:P,hi:V})}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 X([...this.rowList],G.any,this._context)}get_row_by_price(e){let n=lo(e);if(typeof n!="number"||!Number.isFinite(n))return NaN;let r=Ny(n/this._rowSize)-this._firstRowIndex;return r<0||r>=this.rowList.length?NaN:this.rowList[r]}},Iy=[["ticks_per_row"],["ticks_per_row","va_percent"],["ticks_per_row","va_percent","imbalance_percent"]],ky={ticks_per_row:"series",va_percent:"series",imbalance_percent:"series"},Ay=70,My=300;function gc(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"?t[0]:t}function Ss(t){let e=gc(t);return e instanceof y?e.get(0):typeof e=="number"?e:NaN}function Ty(t){return t.cache.__footprint||(t.cache.__footprint={bars:new Map,built:new Map,requestKey:null,loadedVersion:-1,warned:!1}),t.cache.__footprint}function Es(t,e){if(e<0)throw new Te(`Invalid value of the \'${t}\' argument (${e}) in the \'request.footprint\' function. It must be >= 0.`,"request.footprint")}function Ys(t,e,n){e.warned||(e.warned=!0,t.warn(n,"request.footprint"))}async function fl(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){Ys(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 Py(t){return async(...e)=>{let n=ye(e.map(gc),Iy,ky),r=Math.trunc(Ss(n.ticks_per_row)),i=n.va_percent===void 0?Ay:Ss(n.va_percent),s=n.imbalance_percent===void 0?My:Ss(n.imbalance_percent),a=Ty(t),o=`${r}|${i}|${s}`;if(a.requestKey===null)a.requestKey=o;else if(a.requestKey!==o)throw new Te("The script executes too many `request.footprint()` function calls.","request.footprint");if(Es("ticks_per_row",r),Es("va_percent",i),Es("imbalance_percent",s),!(r>0))return NaN;if(!xy(t.source))return Ys(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 Ys(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 fl(t,a,void 0):t.dataVersion>a.loadedVersion&&await fl(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,Ei.build(t,u.levels??[],{ticksPerRow:r,mintick:l,vaPercent:Math.min(i,100),imbalancePercent:s},p))}return a.built.get(c)??NaN}}function Dy(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 Ry=new Set(["heikinashi","standard"]);function Fr(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 Ry.has(n)?{symbol:t.slice(0,e),modifier:n}:{symbol:t,modifier:null}}function xn(t){return Fr(t).symbol}function Gs(t,e){return`${xn(t)};${e}`}var sr=["1","3","5","15","30","45","60","120","180","240","D","W","M"],Jr={"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 Ci(t){if(sr.includes(t))return t;if(Jr[t])return Jr[t];let e=t.toLowerCase();if(Jr[e])return Jr[e];let n=t.toUpperCase();return sr.includes(n)?n:t}function ml(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 yl(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 gl=[["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"]],Oy={symbol:"series",timeframe:"series",expression:"any",gaps:"series",lookahead:"series",ignore_invalid_symbol:"series",currency:"series",calc_bars_count:"series"};function co(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function Ly(t,e){return t.map(n=>co(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Yn(t){return co(t)?t[0]:t}function Fy(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(co(r))return r[1]}function Xs(t){return t==null||typeof t!="object"?t:"__value"in t?t.__value:t instanceof y?t.get(0):Array.isArray(t)?t.map(Xs):t}function By(t){return async(...e)=>{let n=[],r=Ly(e,n),i=ye(r,gl,Oy),s=Yn(i.symbol),a=Yn(i.timeframe),o=Yn(i.expression),l=Yn(i.gaps),c=Yn(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"?Fr(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,x=a instanceof y?a.get(0):a,b=x===""?t.timeframe:typeof x=="string"?x:String(x??""),v=o,E=Fy("expression",gl,n,i.expression),w=l,S=c,C=w===!0||w==="gaps_on",k=S===!0||S==="lookahead_on",B=(()=>{let We=Yn(i.calc_bars_count);return typeof We=="number"&&We>0?We:void 0})();if(t.isSecondaryContext){let We=Xs(v);return Array.isArray(We)?[We]:We}let P=sr.indexOf(Ci(t.timeframe)),V=sr.indexOf(Ci(b));if(P==-1||V==-1)throw new Error("Invalid timeframe");let A=typeof m=="string"?Fr(m):{symbol:m,modifier:null},H=A.modifier==="standard"?null:A.modifier,F=!m||m===""||A.symbol===h.symbol&&H===d;if(P===V&&F){let We=Xs(v);return Array.isArray(We)?[We]:We}let I=P>V,U=y.from(t.data.openTime).get(0),Y=y.from(t.data.closeTime).get(0),ae=t.idx===t.length-1&&Y>Date.now(),te=`${m}_${b}_${E}`,ke=`${te}_prevIdx`;if(t.cache[te]){let We=t.cache[te];t.dataVersion>We.dataVersion&&(await We.pineTS.updateTail(We.context),We.dataVersion=t.dataVersion);let gr=We.context,Qr=I?yl(U,Y,gr.data.openTime.data,gr.data.closeTime.data,k,t.eDate,C):ml(U,Y,gr.data.openTime.data,gr.data.closeTime.data,k,ae);if(Qr==-1)return NaN;let Hn=gr.params[E][Qr];if(!I&&C){let ll=t.cache[ke];return ll!==void 0&&ll===Qr?NaN:(t.cache[ke]=Qr,Array.isArray(Hn)?[Hn]:Hn)}return Array.isArray(Hn)?[Hn]:Hn}let In=1e3*60*60*24*30,sl=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),ip=B?void 0:sl?sl-In:void 0,sp=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),Zr=new Sn(t.source,m,b,B,ip,sp);Zr.markAsSecondary();let al=typeof E=="string"?E:"",ap=al.match(/p\\d+$/)?.[0]??al,ol=t._ltfTruncatedBodies?.[ap],zn=ol?await Zr.runPretranspiled(ol):await Zr.run(t.pineTSCode);t.cache[te]={pineTS:Zr,context:zn,dataVersion:t.dataVersion};let bs=I?yl(U,Y,zn.data.openTime.data,zn.data.closeTime.data,k,t.eDate,C):ml(U,Y,zn.data.openTime.data,zn.data.closeTime.data,k,ae);if(bs==-1)return NaN;let vs=zn.params[E][bs];return!I&&C?(t.cache[ke]=bs,NaN):Array.isArray(vs)?[vs]:vs}}var _l=[["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"]],Vy={symbol:"series",timeframe:"series",expression:"any",ignore_invalid_symbol:"series",currency:"series",ignore_invalid_timeframe:"series",calc_bars_count:"series"};function uo(t){return Array.isArray(t)&&t.length===2&&typeof t[1]=="string"}function $y(t,e){return t.map(n=>uo(n)?(e.push(n[1]),n[0]):(e.push(void 0),n))}function Gn(t){return uo(t)?t[0]:t}function Wy(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(uo(r))return r[1]}function Xn(t){return typeof t=="number"?G.float:typeof t=="boolean"?G.bool:typeof t=="string"?G.string:G.any}var _c={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 Zs(t,e){if(!(t instanceof y))return null;let n=e?.data;if(!n)return null;for(let r of Object.keys(_c))if(t===n[r])return r;return null}function jy(t,e){if(t instanceof y&&(t=t.get(0)),!(t instanceof _n))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=Zs(a,e);if(o===null)return null;i.push(o)}return{kind:"udt",builtinNames:i,fieldNames:r,udt:n}}function Uy(t,e){if(t===void 0)return null;if(Array.isArray(t)){let r=[];for(let i of t){let s=Zs(i,e);if(s===null)return null;r.push(s)}return r.length>0?{kind:"tuple",builtinNames:r}:null}let n=Zs(t,e);return n!==null?{kind:"series",builtinNames:[n]}:jy(t,e)}async function xl(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 Sn(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=>_c[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(x=>{let b={};for(let v=0;v<f.length;v++)b[f[v]]=h[v](x);return new _n(b,t,m)})}return{data:{openTime:{data:c},closeTime:{data:u}},params:{[s]:d}}}function qy(t){return async(...e)=>{let n=[],r=$y(e,n),i=ye(r,_l,Vy),s=Gn(i.symbol),a=Gn(i.timeframe),o=Gn(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=Wy("expression",_l,n,i.expression);Gn(i.ignore_invalid_symbol);let m=Gn(i.ignore_invalid_timeframe),x=(()=>{let I=Gn(i.calc_bars_count);return typeof I=="number"&&I>0?I:void 0})();if(t.isSecondaryContext)return Array.isArray(d)?[d.map(I=>new X([I],Xn(I),t))]:new X([d],Xn(d),t);let b=sr.indexOf(Ci(t.timeframe)),v=sr.indexOf(Ci(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(I=>new X([I],Xn(I),t))]:new X([d],Xn(d),t);let E=`${u}_${h}_${f}_lower`,w=t._requestParamSources?.[f],S=Uy(w,t);if(!t.cache[E])if(S!==null){let I=await xl(t,u,h,x,S,f);t.cache[E]={pineTS:null,context:I,dataVersion:t.dataVersion,_fastPath:!0,_fastPathArgs:{builtinExpr:S}}}else{let I=t.sDate||(t.marketData?.length>0?t.marketData[0].openTime:void 0),U=(t.marketData?.length>0?t.marketData[t.marketData.length-1].closeTime:0)||t.eDate||Date.now(),Y=new Sn(t.source,u,h,x,I,U);Y.markAsSecondary();let ae=typeof f=="string"?f:"",te=ae.match(/p\\d+$/)?.[0]??ae,ke=t._ltfTruncatedBodies?.[te],In;ke?In=await Y.runPretranspiled(ke):In=await Y.run(t.pineTSCode),t.cache[E]={pineTS:Y,context:In,dataVersion:t.dataVersion}}let C=t.cache[E];if(t.dataVersion>C.dataVersion)if(C._fastPath){let I=await xl(t,u,h,x,C._fastPathArgs.builtinExpr,f);C.context=I,C.dataVersion=t.dataVersion}else await C.pineTS.updateTail(C.context),C.dataVersion=t.dataVersion;let k=C.context,B=y.from(t.data.openTime).get(0),P=y.from(t.data.closeTime).get(0),V=k.data.openTime.data,A=k.data.closeTime.data,H=k.params[f];if(!H)return Array.isArray(d)?[d.map(()=>new X([],G.float,t))]:new X([],G.float,t);let F=[];for(let I=0;I<V.length;I++){let U=V[I];if(!(A[I]<=B)){if(U>=P)break;U>=B&&U<P&&F.push(H[I])}}if(F.length>0&&Array.isArray(F[0])){let I=F[0].length,U=[];for(let Y=0;Y<I;Y++){let ae=F.map(ke=>ke[Y]),te=ae.length>0?Xn(ae[0]):G.float;U.push(new X(ae,te,t))}return[U]}else{let I=F.length>0?Xn(F[0]):G.float;return new X(F,I,t)}}}var zy=Object.defineProperty,Hy=(t,e,n)=>e in t?zy(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xr=(t,e,n)=>Hy(t,typeof e!="symbol"?e+"":e,n),Ky={footprint:Py,param:Dy,security:By,security_lower_tf:qy},Qs=class{constructor(e){this.context=e,xr(this,"_cache",{}),xr(this,"footprint"),xr(this,"param"),xr(this,"security"),xr(this,"security_lower_tf"),Object.entries(Ky).forEach(([n,r])=>{this[n]=r(e)})}};function Yy(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 Gy(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),x=a/l,b=[],v=0;for(let E=0;E<a;E++){let w=Math.exp(-Math.pow(E-m,2)/(2*x*x));b.push(w),v+=w}for(let E=0;E<b.length;E++)b[E]/=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 Xy(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,x=Math.abs(a-c),b=Math.abs(o-c);u=Math.max(m,x,b)}else u=a-o;let p=s.prevInitCount,h=s.prevInitSum,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 Zy(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 Qy(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,x=h-a*f;return[[t.precision(h),t.precision(m),t.precision(x)]]}}function Jy(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 E=v.get(u.length);if(isNaN(E))break;u.push(E),p+=E}}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 E=u[v]-h;d+=E*E}let f=d/s,m=Math.sqrt(f),x=a*m;if(h===0)return t.precision(0);let b=2*x/h*100;return t.precision(b)}}function eg(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 x=m.get(l.length);if(isNaN(x))break;l.push(x),c+=x}}if(a.currentWindow=l,a.currentSum=c,a.currentCallCount=u,l.length<i)return NaN;let 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 tg(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 ng(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(),E=d.pop();f-=v,m-=E}a.currentGainsWindow=h,a.currentLossesWindow=d,a.currentGainsSum=f,a.currentLossesSum=m;let x=f+m;if(x===0)return t.precision(0);let b=100*(f-m)/x;return t.precision(b)}}function rg(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 ig(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 E=a.get(v),w=o.get(v);isNaN(E)||isNaN(w)||(l+=E,c+=w,u+=E*w,p+=E*E,h+=w*w,d++)}if(d<2)return NaN;let f=d*u-l*c,m=d*p-l*l,x=d*h-c*c;if(m<=0||x<=0)return t.precision(0);let b=f/Math.sqrt(m*x);return t.precision(b)}}function sg(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 ag(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 og(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 lg(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 cg(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 ug(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,x=h-c,b=m>x&&m>0?m:0,v=x>m&&x>0?x:0,E=o.prevInitCount,w=o.prevTrInitSum,S=o.prevPlusInitSum,C=o.prevMinusInitSum,k=o.prevSmoothedTR,B=o.prevSmoothedPlus,P=o.prevSmoothedMinus;if(E++,E<=i)w+=f,S+=b,C+=v,E===i&&(k=w/i,B=S/i,P=C/i);else{let te=1/i;k=te*f+(1-te)*k,B=te*b+(1-te)*B,P=te*v+(1-te)*P}if(o.currentInitCount=E,o.currentTrInitSum=w,o.currentPlusInitSum=S,o.currentMinusInitSum=C,o.currentSmoothedTR=k,o.currentSmoothedPlus=B,o.currentSmoothedMinus=P,E<i)return[[NaN,NaN,NaN]];let V=k===0?0:100*B/k,A=k===0?0:100*P/k,H=V+A,F=H===0?0:100*Math.abs(V-A)/H,I=o.prevAdxInitCount,U=o.prevDxInitSum,Y=o.prevADX,ae=NaN;if(I++,I<=s)U+=F,I===s&&(Y=U/s,ae=Y);else{let te=1/s;Y=te*F+(1-te)*Y,ae=Y}return o.currentAdxInitCount=I,o.currentDxInitSum=U,o.currentADX=Y,[[t.precision(V),t.precision(A),t.precision(ae)]]}}function hg(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 pg(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 dg(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 fg(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);if(c===void 0||isNaN(c))break;(isNaN(o)||c>=a)&&(a=c,o=-l)}return isNaN(o)?0:o}}function mg(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 x=[...m.prevWindow];if(x.unshift(h),x.length<a)return m.currentWindow=x,NaN;for(;x.length>a;)x.pop();m.currentWindow=x;let b=0,v=0;for(let w=0;w<a;w++){let S=a-w;b+=x[w]*S,v+=S}let E=b/v;return t.precision(E)}}function yg(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 gg(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,S,C,k)=>{if(isNaN(C))return Object.assign(S,w),S.prevEma!==null?S.prevEma:NaN;let B=w.initCount,P=w.initSum,V=w.prevEma;if(B<k){if(P+=C,B++,S.initSum=P,S.initCount=B,S.prevEma=V,B===k){let F=P/k;return S.prevEma=F,F}return NaN}let A=2/(k+1),H=C*A+V*(1-A);return S.prevEma=H,S.initSum=P,S.initCount=B,H},x=m(f.basisState,f.currentBasisState,h,a),b=m(f.rangeState,f.currentRangeState,c,a);if(isNaN(x)||isNaN(b))return[[NaN,NaN,NaN]];let v=x+b*o,E=x-b*o;return[[t.precision(x),t.precision(v),t.precision(E)]]}}function _g(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=(E,w,S,C)=>{if(isNaN(S))return Object.assign(w,E),w.prevEma!==null?w.prevEma:NaN;let k=E.initCount,B=E.initSum,P=E.prevEma;if(k<C){if(B+=S,k++,w.initSum=B,w.initCount=k,w.prevEma=P,k===C){let H=B/C;return w.prevEma=H,H}return NaN}let V=2/(C+1),A=S*V+P*(1-V);return w.prevEma=A,w.initSum=B,w.initCount=k,A},h,d=t.get(t.data.high,0),f=t.get(t.data.low,0);if(l){let E=t.get(t.data.close,1);isNaN(E)?h=NaN:h=Math.max(d-f,Math.abs(d-E),Math.abs(f-E))}else h=d-f;let m=y.from(e).get(0),x=p(u.basisState,u.currentBasisState,m,a),b=p(u.rangeState,u.currentRangeState,h,a);if(isNaN(x)||isNaN(b))return NaN;if(x===0)return t.precision(0);let v=2*b*o/x;return t.precision(v)}}function xg(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,x=s;for(let w=0;w<s;w++){let S=s-1-w,C=u[w];h+=S,d+=C,f+=S*C,m+=S*S}let b=x*m-h*h;if(b===0)return NaN;let v=(x*f-h*d)/b,E=(d-v*h)/x+v*(s-1-a);return t.precision(E)}}function bg(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 vg(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);if(c===void 0||isNaN(c))break;(isNaN(o)||c<=a)&&(a=c,o=-l)}return isNaN(o)?0:o}}function wg(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 x=NaN;isNaN(m)||(x=t.pine.ta.ema(m,l,h));let b=NaN;return!isNaN(m)&&!isNaN(x)&&(b=m-x),[[t.precision(m),t.precision(x),t.precision(b)]]}}function Sg(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 Eg(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 Cg(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,x=a.prevLowerSum;if(d.unshift(p),f.unshift(h),m+=p,x+=h,d.length<i)return a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,NaN;if(d.length>i){let v=d.pop(),E=f.pop();m-=v,x-=E}if(a.currentUpperWindow=d,a.currentLowerWindow=f,a.currentUpperSum=m,a.currentLowerSum=x,x===0)return t.precision(100);if(m===0)return t.precision(0);let b=100-100/(1+m/x);return t.precision(b)}}function Ng(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 Ig(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 kg(t){return(e,n,r)=>{let i=y.from(n).get(0);return t.pine.ta.change(e,i,r)}}function Ag(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 Mg(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 Tg(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 Pg(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 Dg(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 Rg(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 Og(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 Lg(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=Og(o,s,a),c=t.idx;return t.precision(l[c])}}function Fg(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 Bg(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=Fg(o,s,a),c=t.idx;return t.precision(l[c])}}function Vg(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 $g(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 Wg(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 jg(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 Ug(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 qg(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 zg(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,E)=>v+E,0)/i,u=h.reduce((v,E)=>v+E,0)/i,a.currentAvgGain=c,a.currentAvgLoss=u;let b=u===0?100:100-100/(1+c/u);return t.precision(b)}return NaN}c=(c*(i-1)+f)/i,u=(u*(i-1)+m)/i,a.currentAvgGain=c,a.currentAvgLoss=u,a.currentPrevValue=o;let x=u===0?100:100-100/(1+c/u);return t.precision(x)}}function Hg(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),x=t.get(t.data.low,0),b=t.get(t.data.close,0),v=t.get(t.data.close,1),E=t.get(t.data.high,1),w=t.get(t.data.low,1),S=t.get(t.data.high,2),C=t.get(t.data.low,2);if(isNaN(m)||isNaN(x)||isNaN(b))return c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,NaN;let k=!1;return f===1&&(b>v?(d=!0,p=m,u=w):(d=!1,p=x,u=E),k=!0,h=s),f>=1&&(u=u+h*(p-u),d?u>x&&(k=!0,d=!1,u=Math.max(m,p),p=x,h=s):u<m&&(k=!0,d=!0,u=Math.min(x,p),p=m,h=s),k||(d?m>p&&(p=m,h=Math.min(h+a,o)):x<p&&(p=x,h=Math.min(h+a,o))),d?(u=Math.min(u,w),f>1&&(u=Math.min(u,C))):(u=Math.max(u,E),f>1&&(u=Math.max(u,S)))),f++,c.currentResult=u,c.currentMaxMin=p,c.currentAcceleration=h,c.currentIsBelow=d,c.currentBarIndex=f,f<=1?NaN:t.precision(u)}}function Kg(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 x=a.prevWindow[a.prevWindow.length-1];x==null||Number.isNaN(x)?d=!1:m-=x}d&&(p=m)}if(!d){p=0;let m=!1;for(let x of l){if(x==null||Number.isNaN(x)){m=!0;break}p+=x}m&&(p=NaN)}if(a.currentWindow=l,a.currentSum=p,a.currentCallCount=c,l.length<i)return NaN;let f=p/i;return t.precision(f)}}function Yg(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,x=Math.sqrt(f/m);return t.precision(x)}}function Gg(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 x=f-m;if(x===0)return NaN;let b=100*(c-m)/x;return t.precision(b)}}function Xg(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,x=o.prevAtrValue;f++,f<=s?(m+=d,f===s&&(x=m/s)):x=(x*(s-1)+d)/s;let b=x;if(o.currentAtrCount=f,o.currentTrSum=m,o.currentAtrValue=x,isNaN(b))return[[NaN,NaN]];let v=p+i*b,E=p-i*b,w=isNaN(o.prevLowerBand)?0:o.prevLowerBand,S=isNaN(o.prevUpperBand)?0:o.prevUpperBand;isNaN(o.prevLowerBand)||E>w||h<w||(E=w),isNaN(o.prevUpperBand)||v<S||h>S||(v=S);let C,k,B=o.prevSuperTrend;return f===s?C=1:B===o.prevUpperBand?C=u>v?-1:1:C=u<E?1:-1,k=C===-1?E:v,o.currentLowerBand=E,o.currentUpperBand=v,o.currentSuperTrend=k,o.currentDirection=C,[[t.precision(k),C]]}}function Zg(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 Qg(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 Jg(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),x=l.prevEma1PcCount,b=l.prevEma1PcSum,v=l.prevEma1PcValue;x++,x<=a?(b+=u,x===a&&(v=b/a)):v=u*h+v*(1-h);let E=l.prevEma1AbsCount,w=l.prevEma1AbsSum,S=l.prevEma1AbsValue;if(E++,E<=a?(w+=p,E===a&&(S=w/a)):S=p*f+S*(1-f),isNaN(v)||isNaN(S))return l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=E,l.currentEma1AbsSum=w,l.currentEma1AbsValue=S,NaN;let C=l.prevEma2PcCount,k=l.prevEma2PcSum,B=l.prevEma2PcValue;C++,C<=s?(k+=v,C===s&&(B=k/s)):B=v*d+B*(1-d);let P=l.prevEma2AbsCount,V=l.prevEma2AbsSum,A=l.prevEma2AbsValue;if(P++,P<=s?(V+=S,P===s&&(A=V/s)):A=S*m+A*(1-m),l.currentEma1PcCount=x,l.currentEma1PcSum=b,l.currentEma1PcValue=v,l.currentEma1AbsCount=E,l.currentEma1AbsSum=w,l.currentEma1AbsValue=S,l.currentEma2PcCount=C,l.currentEma2PcSum=k,l.currentEma2PcValue=B,l.currentEma2AbsCount=P,l.currentEma2AbsSum=V,l.currentEma2AbsValue=A,isNaN(B)||isNaN(A))return NaN;if(A===0)return t.precision(0);let H=B/A;return t.precision(H)}}function e0(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 t0(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 n0(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=vn(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 r0(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 i0(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 s0(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 a0(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 o0(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 l0=Object.defineProperty,c0=(t,e,n)=>e in t?l0(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e,n)=>c0(t,typeof e!="symbol"?e+"":e,n),u0={accdist:Yy,alma:Gy,atr:Xy,barssince:Zy,bb:Qy,bbw:Jy,cci:eg,change:tg,cmo:ng,cog:rg,correlation:ig,cross:sg,crossover:ag,crossunder:og,cum:lg,dev:cg,dmi:ug,ema:hg,falling:pg,highest:dg,highestbars:fg,hma:mg,iii:yg,kc:gg,kcw:_g,linreg:xg,lowest:bg,lowestbars:vg,macd:wg,max:Sg,median:Eg,mfi:Cg,min:Ng,mode:Ig,mom:kg,nvi:Ag,obv:Mg,param:Tg,percentile_linear_interpolation:Pg,percentile_nearest_rank:Dg,percentrank:Rg,pivothigh:Lg,pivotlow:Bg,pvi:Vg,pvt:$g,range:Wg,rising:jg,rma:Ug,roc:qg,rsi:zg,sar:Hg,sma:Kg,stdev:Yg,stoch:Gg,supertrend:Xg,swma:Zg,tr:Qg,tsi:Jg,valuewhen:e0,variance:t0,vwap:n0,vwma:r0,wad:i0,wma:s0,wpr:a0,wvad:o0},Js=class{constructor(e){this.context=e,$(this,"accdist"),$(this,"alma"),$(this,"atr"),$(this,"barssince"),$(this,"bb"),$(this,"bbw"),$(this,"cci"),$(this,"change"),$(this,"cmo"),$(this,"cog"),$(this,"correlation"),$(this,"cross"),$(this,"crossover"),$(this,"crossunder"),$(this,"cum"),$(this,"dev"),$(this,"dmi"),$(this,"ema"),$(this,"falling"),$(this,"highest"),$(this,"highestbars"),$(this,"hma"),$(this,"iii"),$(this,"kc"),$(this,"kcw"),$(this,"linreg"),$(this,"lowest"),$(this,"lowestbars"),$(this,"macd"),$(this,"max"),$(this,"median"),$(this,"mfi"),$(this,"min"),$(this,"mode"),$(this,"mom"),$(this,"nvi"),$(this,"obv"),$(this,"param"),$(this,"percentile_linear_interpolation"),$(this,"percentile_nearest_rank"),$(this,"percentrank"),$(this,"pivothigh"),$(this,"pivotlow"),$(this,"pvi"),$(this,"pvt"),$(this,"range"),$(this,"rising"),$(this,"rma"),$(this,"roc"),$(this,"rsi"),$(this,"sar"),$(this,"sma"),$(this,"stdev"),$(this,"stoch"),$(this,"supertrend"),$(this,"swma"),$(this,"tr"),$(this,"tsi"),$(this,"valuewhen"),$(this,"variance"),$(this,"vwap"),$(this,"vwma"),$(this,"wad"),$(this,"wma"),$(this,"wpr"),$(this,"wvad"),Object.entries(u0).forEach(([n,r])=>{this[n]=r(e)})}};function h0(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 Sr(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 Ni(t,e,n,r){return Math.abs(t)*e*r*n/100}function p0(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of Qi(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 d0(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+=Ni(s.size,e,a,r)}return i}function ho(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 f0(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,x=Math.max(0,f-h);m>(c.max_drawdown??0)&&(c.max_drawdown=m),x>(c.max_runup??0)&&(c.max_runup=x)}Ii(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=bn(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=bn(c.direction);(h===1&&i>=c.stop||h===-1&&s<=c.stop)&&(u=!0,p=c.stop)}break}if(u){if(y0(e,c)){c.status="cancelled";continue}let h=bn(c.direction);p=ea(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),x=m!==0&&m!==h,b=x?Math.max(0,c.qty-Math.abs(f)):c.qty;if(b>0){let v=t.pine?.syminfo?.pointvalue??1,E=0;m===h&&(E=d0(t,r));let w=e.equity-E;if(Ni(b,p,d,v)>w){let S=Math.min(Math.abs(f),c.qty);x&&S>0?(Mn(t,S,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}}}_0(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"),Ii(t,a),A0(t)}function bn(t){return typeof t=="number"?t:t==="long"?1:t==="short"?-1:0}function xc(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 ea(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 bc(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 m0(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 y0(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 g0(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 ei(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=xc(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),x=y.from(t.data.low).get(0),b=t.pine?.syminfo?.mintick??.01,v=n===1?x:m,E=n===1?m:x;for(let P of l.pending_orders){if((P.category??"entry")!=="exit"||P.from_entry&&P.from_entry!==e)continue;let V;P.stop!==void 0?V=P.stop:P.loss!==void 0&&(V=n===1?i-P.loss*b:i+P.loss*b);let A;P.limit!==void 0?A=P.limit:P.profit!==void 0&&(A=n===1?i+P.profit*b:i-P.profit*b),n===1?(V!==void 0&&V>v&&(v=V),A!==void 0&&A<E&&(E=A)):(V!==void 0&&V<v&&(v=V),A!==void 0&&A>E&&(E=A))}let w=t.pine?.syminfo?.pointvalue??1,S=n===1?(i-v)*r*w:(v-i)*r*w,C=n===1?(E-i)*r*w:(i-E)*r*w;f.max_drawdown=Math.max(0,S)+d,f.max_runup=Math.max(0,C-d);let k=l.position_size,B=k+f.size;if(k===0)l.position_size=B,l.position_avg_price=i,l.position_entry_name=e;else if(Math.sign(k)===Math.sign(B)){let P=Math.abs(k)*l.position_avg_price+r*i,V=Math.abs(B);l.position_avg_price=P/V,l.position_size=B}bc(l)}function _0(t,e,n,r){let i=t.strategy,s=bn(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(Mn(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?(ei(t,e.id,s,p,n,r,e.comment,!0),ei(t,e.id,s,c-p,n,r,e.comment,!0)):ei(t,e.id,s,c,n,r,e.comment,!0)}}else ei(t,e.id,s,e.qty,n,r,e.comment)}function x0(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 Mn(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=b=>{let v=s.config.commission_type??"percent",E=i?.isImplicitReversal&&v==="cash_per_order",w=xc(t,s,b,n),S=E?w/2:w,C=x0(s,h,b);for(let k of C){let B=S*(k.qty/b),P=(m===1?n-k.entry_price:k.entry_price-n)*k.qty*a,V={id:`trade_${s.opentrades.length+s.closedtrades.length+l.length}`,entry_id:h.entry_id,entry_comment:k.entry_comment,entry_price:k.entry_price,_bracket_entry:h._bracket_entry,entry_bar_index:k.entry_bar_index,entry_time:k.entry_time,size:m*k.qty,commission:k.commission+B,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:P-k.commission-B};i?.triggerKind==="loss"&&(V.max_runup=0),i?.triggerKind==="profit"&&(V.max_drawdown=k.commission),s.netprofit+=P-B,s.grossloss-=k.commission,V.profit>0?(s.grossprofit+=V.profit,s.wintrades++,s.wintrades_total_profit+=V.profit):V.profit<0?(s.grossloss+=Math.abs(V.profit),s.losstrades++,s.losstrades_total_loss+=Math.abs(V.profit)):s.eventrades++,s.closedtrades.push(V)}};if(f>=d-1e-9)h.status="closed",h.exit_price=n,h.exit_bar_index=t.idx,h.exit_time=r,x(d),o-=f;else{x(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}}g0(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,bc(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 Qi(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 Qi(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 Ii(t,e){let n=t.strategy,r=t.pine?.syminfo?.pointvalue??1,i=0;for(let s of Qi(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 b0(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 Qi(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 bl(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],Mn(t,Math.min(n,f),r,i,s);return}if(!e||e===""){Mn(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],Mn(t,p,r,i,s)}function v0(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(A=>!c.from_entry||A.entry_id===c.from_entry);if(c._intended_trade_ids){let A=new Set(c._intended_trade_ids);u=u.filter(H=>A.has(H.id))}if(u.length===0){e==="intrabar"&&(c.status="cancelled");continue}let p=u.reduce((A,H)=>A+Math.abs(H.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 A=c.immediately?a:r;A=ea(t,-h,A);let H=p;c.qty&&c.qty>0?H=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(H=p*(c.qty_percent/100)),bl(t,c.from_entry,H,A,o,{exitId:c.id,exitComment:c.comment}),c.status="filled",c.fill_price=A,c.fill_bar=t.idx,c.fill_time=o;continue}let d=0;for(let A of u)d+=Math.abs(A.size)*A.entry_price;let f=d/p,m=h===1,x=c.limit,b=c.stop;c._isPersistent||(b!==void 0&&((m?b<f:b>f)||(b=void 0)),x!==void 0&&((m?x>f:x<f)||(x=void 0))),c._attachedAtReversal&&!c._isPersistent&&(c.limit!==void 0&&(x=void 0),c.stop!==void 0&&(b=void 0));let v=!1;if(e==="intrabar"&&!c.trail_armed&&(c.trail_price!==void 0||c.trail_points!==void 0)){let A;c.trail_price!==void 0?A=c.trail_price:c.trail_points!==void 0&&(A=m?f+c.trail_points*l:f-c.trail_points*l),A!==void 0&&(m?i>=A:s<=A)&&(c.trail_armed=!0,c.trail_peak=m?i:s,v=!0)}let E=Math.abs(i-r)<=Math.abs(r-s),w=m?E:!E,S=[],C=[],k=n._mc_exit_lock,B=k&&k.bar===t.idx;for(let A of u){if(B&&A.id!==k.tradeId)continue;let H=A._bracket_entry??A.entry_price,F=Math.abs(A.size),I=x;I===void 0&&c.profit!==void 0&&(I=m?H+c.profit*l:H-c.profit*l);let U=b;U===void 0&&c.loss!==void 0&&(U=m?H-c.loss*l:H+c.loss*l);let Y=I!==void 0&&(e==="open"?m?r>=I:r<=I:m?i>=I:s<=I),ae=U!==void 0&&(e==="open"?m?r<=U:r>=U:m?s<=U:i>=U),te=null;if(Y&&ae?te=w?"profit":"loss":Y?te="profit":ae&&(te="loss"),te==="loss"){let ke=m?r<=U:r>=U;!m&&ke&&A.entry_bar_index===t.idx?Y&&(te="profit"):C.push({qty:F,price:ke?r:U,kind:"loss",tradeId:A.id})}if(te==="profit"){let ke=m?r>=I:r<=I;S.push({qty:F,price:ke?r:I,kind:"profit",tradeId:A.id})}}S.sort((A,H)=>m?A.price-H.price:H.price-A.price),C.sort((A,H)=>m?H.price-A.price:A.price-H.price);let P=null;if(e==="intrabar"&&!B&&c.trail_armed&&c.trail_offset!==void 0){let A=()=>{m?c.trail_peak=Math.max(c.trail_peak??-1/0,i):c.trail_peak=Math.min(c.trail_peak??1/0,s)},H=()=>m?c.trail_peak-c.trail_offset*l:c.trail_peak+c.trail_offset*l,F=I=>{P={qty:1/0,price:I,kind:"trailing"}};if(v){let I=H();w?(m?s<=I:i>=I)&&F(I):(m?a<=I:a>=I)&&F(I)}else if(w){A();let I=H();(m?s<=I:i>=I)&&F(I)}else{let I=H();if(m?s<=I:i>=I)F(I);else{A();let U=H();(m?a<=U:a>=U)&&F(U)}}}let V=w?[...S,...C,...P?[P]:[]]:[...C,...P?[P]:[],...S];if(V.length>0){let A=p;c.qty&&c.qty>0?A=Math.min(c.qty,p):c.qty_percent&&c.qty_percent>0&&(A=p*(c.qty_percent/100));let H=()=>n.opentrades.filter(U=>!c.from_entry||U.entry_id===c.from_entry).reduce((U,Y)=>U+Math.abs(Y.size),0),F=NaN,I=!1;for(let U of V){if(A<=1e-9)break;let Y=H();if(Y<=1e-9)break;let ae=Math.min(U.qty===1/0?Y:U.qty,A,Y),te=ea(t,-h,U.price),ke=U.kind==="profit"?c.comment_profit??c.comment:U.kind==="loss"?c.comment_loss??c.comment:c.comment_trailing??c.comment;bl(t,c.from_entry,ae,te,o,{triggerKind:U.kind,exitId:c.id,exitComment:ke},U.tradeId),A-=ae,F=te,I=!0}I&&(H()<=1e-9||A<=1e-9)&&(c.status="filled",c.fill_price=F,c.fill_bar=t.idx,c.fill_time=o)}}n.pending_orders=n.pending_orders.filter(c=>c.status==="pending"),Ii(t,a)}function w0(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)&&(Mn(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&&bn(r.direction)===n.dir&&(r.status="cancelled");e.pending_orders=e.pending_orders.filter(r=>r.status==="pending")}}function S0(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 Cs(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=p0(t,p),f=Ni(h,p,i,u);if(d<f){let m=f-d,x=i/100,b=m/(p*u*x),v=Math.min(h,4*b),E=[...n.opentrades],w=E[0],S=Math.abs(w.size),C=w.entry_price;if(Mn(t,v,p,c,{exitId:"Margin call",exitComment:"Margin call"}),e==="extreme"&&v>=S-1e-9&&Math.abs(n.position_size)>1e-9){let B=Ni(S,p,i,u),P=S*(p-C)*r*u,V=m-B+P;if(V>0){let A=y.from(t.data.close).get(0),H=(I=>Math.trunc(I*1e6)/1e6)(V/(p*u*x)),F=Math.min(Math.abs(n.position_size),4*H);F>1e-9&&(n._pending_close_mc={qty:F,price:A,time:c,dir:r})}}let k=E.find(B=>B.status==="open");n._mc_exit_lock={bar:t.idx,tradeId:k?.id??null}}}function E0(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);Ii(t,i),b0(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 C0(t){let e=t?.strategy;if(!e)return;e.cagr=I0(t),k0(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 N0=1440*60*1e3;function I0(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)/N0;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 k0(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 A0(t){t.strategy}function M0(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 Er(t){if(Array.isArray(t))return t.map(Er);if(t instanceof Map){let e=new Map;return t.forEach((n,r)=>e.set(r,Er(n))),e}if(t!==null&&typeof t=="object"){let e={};for(let n of Object.keys(t))e[n]=Er(t[n]);return e}return t}function T0(t){if(!t)return null;let e={};for(let n of Object.keys(t))n==="config"||n==="closedtrades"||(e[n]=Er(t[n]));return{fields:e,closedtradesLength:t.closedtrades.length}}function P0(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]=Er(e.fields[n])}}function D0(t){return(...e)=>{let n=h0(e);return t.strategy?t.strategy.config={...t.strategy.config,...n,...t._propOverrides??{}}:M0(t,n),t.strategy.config}}var R0=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],O0={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 L0(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.order() called before strategy() declaration");let n=ye(e,R0,O0),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=bn(s),d=y.from(t.data.close).get(0),f=ho(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 x=y.from(t.data.openTime).get(0),b={id:i,direction:h,qty:f,type:m,limit:o,stop:l,bar:t.idx,time:x,status:"pending",oca_name:c,oca_type:u,comment:p};return t.strategy.pending_orders.push(b),b}}function F0(t){return(e,n)=>y.from(e).get(n||0)}function B0(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",x=f?.commission_value??0;if(!x)return 0;let b=Math.abs(h.size);switch(m){case"percent":return b*d*s*(x/100);case"cash_per_contract":return b*x;case"cash_per_order":return x;default:return 0}},o=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 V0(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 $0(t){return()=>t.strategy?.netprofit??0}function W0(t){return()=>t.strategy?.position_size??0}function j0(t){return()=>{let e=t.strategy;return!e||e.position_size===0?NaN:e.position_avg_price}}function U0(t){return()=>t.strategy?.equity??t.strategy?.config?.initial_capital??1e4}function q0(t){return()=>"long"}function z0(t){return()=>"short"}function H0(t){return()=>"cash"}function K0(t){return()=>"percent_of_equity"}function Y0(t){return()=>"fixed"}function G0(t){return()=>t.strategy?.openprofit??0}function X0(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.openprofit/e.initial_capital}}function Z0(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.netprofit/e.initial_capital}}function Q0(t){return()=>t.strategy?.grossprofit??0}function J0(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossprofit/e.initial_capital}}function e_(t){return()=>t.strategy?.grossloss??0}function t_(t){return()=>{let e=t.strategy;return!e||!e.initial_capital?0:100*e.grossloss/e.initial_capital}}function n_(t){return()=>t.strategy?.wintrades??0}function r_(t){return()=>t.strategy?.losstrades??0}function i_(t){return()=>t.strategy?.eventrades??0}function s_(t){return()=>{let e=t.strategy;return!e||!e.closedtrades||e.closedtrades.length===0?NaN:e.netprofit/e.closedtrades.length}}function a_(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 o_(t){return()=>{let e=t.strategy;return!e||e.wintrades===0?NaN:e.wintrades_total_profit/e.wintrades}}function l_(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 c_(t){return()=>{let e=t.strategy;return!e||e.losstrades===0?NaN:e.losstrades_total_loss/e.losstrades}}function u_(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 h_(t){return()=>t.strategy?.max_drawdown??0}function p_(t){return()=>{let e=t.strategy;return e?e.max_drawdown_percent_value??0:0}}function d_(t){return()=>t.strategy?.max_runup??0}function f_(t){return()=>{let e=t.strategy;return e?e.max_runup_percent_value??0:0}}function m_(t){return()=>t.strategy?.max_contracts_held_all??0}function y_(t){return()=>t.strategy?.max_contracts_held_long??0}function g_(t){return()=>t.strategy?.max_contracts_held_short??0}function __(t){return()=>t.strategy?.position_entry_name??""}function x_(t){return()=>t.strategy?.initial_capital??0}function b_(t){return()=>t.strategy?.account_currency??"USD"}function v_(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 w_=[["id","direction","qty","limit","stop","oca_name","oca_type","comment","alert_message","disable_alert"]],S_={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 E_(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.entry() called before strategy() declaration");let n=ye(e,w_,S_),r=P=>P==null||typeof P=="string"||typeof P=="number"||typeof P=="boolean"?P:typeof P=="function"?P():P instanceof y?P.get(0):Array.isArray(P)?P[P.length-1]:typeof P=="object"&&P.get!==void 0?P.get(0):P,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=bn(s),d=t.strategy,f=d.position_size;for(let P of d.pending_orders)P.bar===t.idx&&P.category==="entry"&&P.type==="market"&&(f+=bn(P.direction)*P.qty);if(Math.sign(f)===h&&f!==0&&m0(d,h))return;let m=y.from(t.data.close).get(0),x=ho(t,a,h,m),b=f!==0&&Math.sign(f)!==h,v=b?Math.abs(f)+x:x,E="market";o!==void 0&&l!==void 0?E="stop-limit":o!==void 0?E="limit":l!==void 0&&(E="stop");let w=t.pine?.syminfo?.mintick??0,S=o!==void 0?Sr(o,m,w):void 0,C=l!==void 0?Sr(l,m,w):void 0,k=y.from(t.data.openTime).get(0),B={id:i,direction:h,qty:v,type:E,limit:S,stop:C,bar:t.idx,time:k,status:"pending",category:"entry",oca_name:c,oca_type:u,comment:p,_isReversalEntry:b,_base_qty:x};d.pending_orders.push(B)}}var C_=[["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"]],N_={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 I_(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.exit() called before strategy() declaration");let n=Tt(e);if(n===void 0){let F=t.strategy;F._exit_fallback_last_bar!==t.idx&&(F._exit_fallback_counter=0,F._exit_fallback_last_bar=t.idx),n=`exit_raw_${F._exit_fallback_counter++}`}let r=ye(e,C_,N_),i=F=>F==null||typeof F=="string"||typeof F=="number"||typeof F=="boolean"?F:typeof F=="function"?F():F instanceof y?F.get(0):Array.isArray(F)?F[F.length-1]:typeof F=="object"&&F.get!==void 0?F.get(0):F,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),x=t.pine?.syminfo?.mintick??0,b=y.from(t.data.close).get(0),v=u!==void 0?Sr(u,b,x):void 0,E=h!==void 0?Sr(h,b,x):void 0,w=d!==void 0?Sr(d,b,x):void 0,S=a??"",C=!!(S?t.strategy.pending_orders.find(F=>F.category==="entry"&&F.id===S&&F.status==="pending"):t.strategy.pending_orders.find(F=>F.category==="entry"&&F.status==="pending"))?._isReversalEntry,k=t.strategy._exit_call_history,B=k.get(n),P=B!==void 0&&B===t.idx-1;k.set(n,t.idx);let V={id:s??"exit",direction:0,qty:o!==void 0?Math.abs(Number(o)):0,qty_percent:l,type:"market",bar:t.idx,time:y.from(t.data.openTime).get(0),status:"pending",category:"exit",from_entry:S,profit:c,loss:p,limit:v,stop:E,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:C,_isPersistent:P,_callsiteId:n},A=V.id,H=t.strategy.pending_orders;for(let F=H.length-1;F>=0;F--){let I=H[F];I.category==="exit"&&I.id===A&&(I.from_entry??"")===(V.from_entry??"")&&I.status==="pending"&&(I.trail_armed&&(V.trail_armed=!0,V.trail_peak=I.trail_peak),H.splice(F,1))}H.push(V)}}var k_=[["id","comment","qty","qty_percent","alert_message","immediately","disable_alert"]],A_={id:"string",comment:"string",qty:"series",qty_percent:"series",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function M_(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close() called before strategy() declaration");let n=ye(e,k_,A_),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 T_=[["comment","alert_message","immediately","disable_alert"]],P_={comment:"string",alert_message:"string",immediately:"boolean",disable_alert:"boolean"};function D_(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.close_all() called before strategy() declaration");let n=ye(e,T_,P_);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 R_=[["id","immediately"]],O_={id:"string",immediately:"boolean"};function L_(t){return(...e)=>{if(!t.strategy)throw new Error("strategy.cancel() called before strategy() declaration");let n=ye(e,R_,O_).id;n!=null&&(t.strategy.pending_orders=t.strategy.pending_orders.filter(r=>!(r.status==="pending"&&r.id===n)))}}function F_(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 V_(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function $_(t){return e=>{let n=t.strategy,r=t.pine?.syminfo?.currency,i=n?.account_currency??"USD";return r&&r!==i?NaN:e}}function W_(t){return e=>t.strategy?ho(t,void 0,1,e):0}var j_={any:D0,order:L0,param:F0,opentrades:B0,closedtrades:V0,netprofit:$0,position_size:W0,position_avg_price:j0,equity:U0,long:q0,short:z0,cash:H0,percent_of_equity:K0,fixed:Y0,openprofit:G0,openprofit_percent:X0,netprofit_percent:Z0,grossprofit:Q0,grossprofit_percent:J0,grossloss:e_,grossloss_percent:t_,wintrades:n_,losstrades:r_,eventrades:i_,avg_trade:s_,avg_trade_percent:a_,avg_winning_trade:o_,avg_winning_trade_percent:l_,avg_losing_trade:c_,avg_losing_trade_percent:u_,max_drawdown:h_,max_drawdown_percent:p_,max_runup:d_,max_runup_percent:f_,max_contracts_held_all:m_,max_contracts_held_long:y_,max_contracts_held_short:g_,position_entry_name:__,initial_capital:x_,account_currency:b_,margin_liquidation_price:v_,entry:E_,exit:I_,close:M_,close_all:D_,cancel:L_,cancel_all:F_,convert_to_account:V_,convert_to_symbol:$_,default_entry_qty:W_},U_={long:"long",short:"short",all:"all"},q_={none:"none",cancel:"cancel",reduce:"reduce"},z_={percent:"percent",cash_per_order:"cash_per_order",cash_per_contract:"cash_per_contract"},ta=class{constructor(e){this.context=e,Object.entries(j_).forEach(([r,i])=>{this[r]=i(e)}),this.direction=()=>U_,this.oca=()=>q_,this.commission=()=>z_;let n=B_(e);this.risk=()=>n}};function H_(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=vn(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 K_(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 na=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=H_(e,n);return K_(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)}`)}},ra=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 Te(typeof n=="string"?n:String(n??""),"runtime.error")}},Y_=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],G_=["January","February","March","April","May","June","July","August","September","October","November","December"],X_=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Z_=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ct=(t,e)=>String(t).padStart(e,"0"),ia=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 X(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=vn(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?ct(a.year%100,2):m>=4?ct(a.year,4):String(a.year);break;case"M":m>=4?h+=G_[a.month-1]:m===3?h+=Y_[a.month-1]:m===2?h+=ct(a.month,2):h+=String(a.month);break;case"d":h+=m===2?ct(a.day,2):String(a.day);break;case"D":h+=m>=3?ct(u,3):m===2?ct(u,2):String(u);break;case"E":h+=m>=4?Z_[a.dayOfWeek]:X_[a.dayOfWeek];break;case"a":h+=a.hour<12?"AM":"PM";break;case"h":h+=m===2?ct(p,2):String(p);break;case"H":h+=m===2?ct(a.hour,2):String(a.hour);break;case"m":h+=m===2?ct(a.minute,2):String(a.minute);break;case"s":h+=m===2?ct(a.second,2):String(a.second);break;case"S":{let x=i-Math.floor(i/1e3)*1e3;h+=ct(x,3).substring(0,m);break}case"Z":{let x=l>=0?"+":"-",b=Math.abs(l);h+=`${x}${ct(Math.floor(b/60),2)}${ct(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)})}},Q_=Object.defineProperty,J_=(t,e,n)=>e in t?Q_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ex=(t,e,n)=>J_(t,typeof e!="symbol"?e+"":e,n),ti={"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 vl(t){if(!t||/^\\d+$/.test(t))return t;if(ti[t])return ti[t];let e=t.toLowerCase();if(ti[e])return ti[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 sa=class{constructor(e){this.context=e,ex(this,"_normalized",null)}param(e,n=0,r){return y.from(e).get(n)}get normalized(){return this._normalized===null&&(this._normalized=vl(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=Ws(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=js(s,i),l=js(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=vl(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}},tx=Object.defineProperty,nx=Object.getOwnPropertyDescriptor,qt=(t,e,n,r)=>{for(var i=r>1?void 0:r?nx(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&&tx(e,n,i),i},rx=["series","title","color","linewidth","style","trackprice","histbase","offset","join","editable","show_last","display","format","precision","force_overlay"],ix=["series","title","char","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],sx={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"},ax=["series","title","style","location","color","offset","text","textcolor","editable","size","show_last","display","format","precision","force_overlay"],ox=["series","title","colorup","colordown","offset","minheight","maxheight","editable","show_last","display","format","precision","force_overlay"],lx=["open","high","low","close","title","color","editable","show_last","display","format","precision","force_overlay"],cx=["open","high","low","close","title","color","wickcolor","editable","show_last","bordercolor","display","format","precision","force_overlay"],wl=["color","offset","editable","show_last","title","display","force_overlay"],ux=["price","title","color","linestyle","linewidth","editable","display"],hx=["plot1","plot2","color","title","editable","show_last","fillgaps","display"],px={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"},dx={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"},fx={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"},mx={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"},yx={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"},Sl={color:"color",offset:"number",editable:"boolean",show_last:"number",title:"string",display:"string",force_overlay:"boolean"},gx={price:"series",title:"string",color:"color",linestyle:"string",linewidth:"number",editable:"boolean",display:"string"},_x={plot1:"object",plot2:"object",color:"color",title:"string",editable:"boolean",show_last:"number",fillgaps:"boolean",display:"string"},Pt=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=Tt(e),r=ye(e,ix,sx),{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=Tt(e),r=ye(e,rx,px),{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=Tt(e),r=ye(e,ax,dx),{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=Tt(e),r=ye(e,ox,fx),{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=Tt(e),r=ye(e,lx,mx),{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=Tt(e),r=ye(e,cx,yx),{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=Tt(e),r=ye(e,wl,Sl),{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=Tt(e),r=ye(e,wl,Sl),{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([M],Pt.prototype,"plotchar",1),qt([M],Pt.prototype,"any",1),qt([M],Pt.prototype,"plotshape",1),qt([M],Pt.prototype,"plotarrow",1),qt([M],Pt.prototype,"plotbar",1),qt([M],Pt.prototype,"plotcandle",1),qt([M],Pt.prototype,"bgcolor",1),qt([M],Pt.prototype,"barcolor",1);var ki=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=Tt(e),r=ye(e,ux,gx),{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([M],ki.prototype,"any",1);var Ai=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(...e){let n=Tt(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,hx,_x),{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 x=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:x,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:x}})}}};qt([M],Ai.prototype,"any",1);var xx=Object.defineProperty,bx=(t,e,n)=>e in t?xx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,vx=(t,e,n)=>bx(t,typeof e!="symbol"?e+"":e,n),aa=class{constructor(e){this.context=e,vx(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 Ge(r(i),r(s),r(a)??NaN)},from_index(i,s){return new Ge(void 0,r(i),r(s))},from_time(i,s){return new Ge(r(i),void 0,r(s))},copy(i){return i.copy()},now(i){let s=n.idx,a=n.marketData[s]?.openTime;return new Ge(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}},wx=Object.defineProperty,Sx=(t,e,n)=>e in t?wx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fe=(t,e,n)=>Sx(t,typeof e!="symbol"?e+"":e,n),Ex=0,Cr=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"){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,"text_formatting"),Fe(this,"_deleted"),Fe(this,"_helper"),Fe(this,"_createdAtBar",-1),this.id=Ex++,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){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._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.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,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}}},vc=Object.defineProperty,Cx=Object.getOwnPropertyDescriptor,Nx=(t,e,n)=>e in t?vc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Be=(t,e,n,r)=>{for(var i=r>1?void 0:r?Cx(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&&vc(e,n,i),i},Ix=(t,e,n)=>Nx(t,typeof e!="symbol"?e+"":e,n),kx=[["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"]],Ax={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"},Ne=class{constructor(e){this.context=e,Ix(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 rt)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 Cr(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=ye(e,kx,Ax),r,i,s=n.xloc;if(n.point instanceof Ge){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,n.text_formatting)}any(...e){if(e.length===1){let n=e[0];if(n==null||n instanceof rt||typeof n=="number"&&isNaN(n))return null;if(n instanceof Cr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof Cr)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){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"}};Be([M],Ne.prototype,"new",1),Be([M],Ne.prototype,"set_x",1),Be([M],Ne.prototype,"set_y",1),Be([M],Ne.prototype,"set_xy",1),Be([M],Ne.prototype,"set_text",1),Be([M],Ne.prototype,"set_color",1),Be([M],Ne.prototype,"set_textcolor",1),Be([M],Ne.prototype,"set_size",1),Be([M],Ne.prototype,"set_style",1),Be([M],Ne.prototype,"set_textalign",1),Be([M],Ne.prototype,"set_tooltip",1),Be([M],Ne.prototype,"set_text_font_family",1),Be([M],Ne.prototype,"set_text_formatting",1),Be([M],Ne.prototype,"set_xloc",1),Be([M],Ne.prototype,"set_yloc",1),Be([M],Ne.prototype,"set_point",1),Be([M],Ne.prototype,"copy",1),Be([M],Ne.prototype,"delete",1);var Mx=Object.defineProperty,Tx=(t,e,n)=>e in t?Mx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Je=(t,e,n)=>Tx(t,typeof e!="symbol"?e+"":e,n),Px=0,Nr=class t{constructor(e,n,r,i,s="bi",a="none",o="",l="style_solid",c=1,u=!1){Je(this,"id"),Je(this,"x1"),Je(this,"y1"),Je(this,"x2"),Je(this,"y2"),Je(this,"xloc"),Je(this,"extend"),Je(this,"color"),Je(this,"style"),Je(this,"width"),Je(this,"force_overlay"),Je(this,"_deleted"),Je(this,"_helper"),Je(this,"_createdAtBar",-1),this.id=Px++,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}}},wc=Object.defineProperty,Dx=Object.getOwnPropertyDescriptor,Rx=(t,e,n)=>e in t?wc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,je=(t,e,n,r)=>{for(var i=r>1?void 0:r?Dx(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&&wc(e,n,i),i},Ox=(t,e,n)=>Rx(t,typeof e!="symbol"?e+"":e,n),Lx=[["x1","y1","x2","y2","xloc","extend","color","style","width","force_overlay"],["first_point","second_point","xloc","extend","color","style","width","force_overlay"]],Fx={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"},Pe=class{constructor(e){this.context=e,Ox(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 rt?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 Nr(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,Lx,Fx),r,i,s,a,o=n.xloc;if(n.first_point instanceof Ge){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 Ge?(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 rt||typeof n=="number"&&isNaN(n))return null;if(n instanceof Nr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof Nr)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"}};je([M],Pe.prototype,"new",1),je([M],Pe.prototype,"set_x1",1),je([M],Pe.prototype,"set_y1",1),je([M],Pe.prototype,"set_x2",1),je([M],Pe.prototype,"set_y2",1),je([M],Pe.prototype,"set_xy1",1),je([M],Pe.prototype,"set_xy2",1),je([M],Pe.prototype,"set_color",1),je([M],Pe.prototype,"set_width",1),je([M],Pe.prototype,"set_style",1),je([M],Pe.prototype,"set_extend",1),je([M],Pe.prototype,"set_xloc",1),je([M],Pe.prototype,"set_first_point",1),je([M],Pe.prototype,"set_second_point",1),je([M],Pe.prototype,"copy",1),je([M],Pe.prototype,"delete",1);var Bx=Object.defineProperty,Vx=(t,e,n)=>e in t?Bx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Se=(t,e,n)=>Vx(t,typeof e!="symbol"?e+"":e,n),$x=0,Ir=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",x="wrap_none",b="default",v="format_none",E=!1){Se(this,"id"),Se(this,"left"),Se(this,"top"),Se(this,"right"),Se(this,"bottom"),Se(this,"xloc"),Se(this,"extend"),Se(this,"border_color"),Se(this,"border_style"),Se(this,"border_width"),Se(this,"bgcolor"),Se(this,"text"),Se(this,"text_color"),Se(this,"text_size"),Se(this,"text_halign"),Se(this,"text_valign"),Se(this,"text_wrap"),Se(this,"text_font_family"),Se(this,"text_formatting"),Se(this,"force_overlay"),Se(this,"_deleted"),Se(this,"_helper"),Se(this,"_createdAtBar",-1),this.id=$x++,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=x,this.text_font_family=b,this.text_formatting=v,this.force_overlay=E,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)}},Sc=Object.defineProperty,Wx=Object.getOwnPropertyDescriptor,jx=(t,e,n)=>e in t?Sc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xe=(t,e,n,r)=>{for(var i=r>1?void 0:r?Wx(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&&Sc(e,n,i),i},Ux=(t,e,n)=>jx(t,typeof e!="symbol"?e+"":e,n),qx=[["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"]],zx={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"},fe=class{constructor(e){this.context=e,Ux(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 rt?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",x="wrap_none",b="default",v="format_none",E=!1){let w=new Ir(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(x)||"wrap_none",this._resolve(b)||"default",this._resolve(v)||"format_none",E);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,qx,zx),r,i,s,a,o=n.xloc;if(n.top_left instanceof Ge){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 Ge?(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 rt||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_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()}};xe([M],fe.prototype,"new",1),xe([M],fe.prototype,"set_left",1),xe([M],fe.prototype,"set_right",1),xe([M],fe.prototype,"set_top",1),xe([M],fe.prototype,"set_bottom",1),xe([M],fe.prototype,"set_lefttop",1),xe([M],fe.prototype,"set_rightbottom",1),xe([M],fe.prototype,"set_top_left_point",1),xe([M],fe.prototype,"set_bottom_right_point",1),xe([M],fe.prototype,"set_xloc",1),xe([M],fe.prototype,"set_bgcolor",1),xe([M],fe.prototype,"set_border_color",1),xe([M],fe.prototype,"set_border_width",1),xe([M],fe.prototype,"set_border_style",1),xe([M],fe.prototype,"set_extend",1),xe([M],fe.prototype,"set_text",1),xe([M],fe.prototype,"set_text_color",1),xe([M],fe.prototype,"set_text_size",1),xe([M],fe.prototype,"set_text_halign",1),xe([M],fe.prototype,"set_text_valign",1),xe([M],fe.prototype,"set_text_wrap",1),xe([M],fe.prototype,"set_text_font_family",1),xe([M],fe.prototype,"set_text_formatting",1),xe([M],fe.prototype,"copy",1),xe([M],fe.prototype,"delete",1);var Hx=Object.defineProperty,Kx=(t,e,n)=>e in t?Hx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Zn=(t,e,n)=>Kx(t,typeof e!="symbol"?e+"":e,n),Yx=0,Mi=class{constructor(e,n,r){Zn(this,"id"),Zn(this,"line1"),Zn(this,"line2"),Zn(this,"color"),Zn(this,"_deleted"),Zn(this,"_createdAtBar",-1),this.id=Yx++,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}}},Ec=Object.defineProperty,Gx=Object.getOwnPropertyDescriptor,Xx=(t,e,n)=>e in t?Ec(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ns=(t,e,n,r)=>{for(var i=r>1?void 0:r?Gx(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&&Ec(e,n,i),i},Zx=(t,e,n)=>Xx(t,typeof e!="symbol"?e+"":e,n),ir=class{constructor(e){this.context=e,Zx(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 rt?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 Mi(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 rt||typeof n=="number"&&isNaN(n)?null:n instanceof Mi?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()}};Ns([M],ir.prototype,"new",1),Ns([M],ir.prototype,"set_color",1),Ns([M],ir.prototype,"delete",1);var Qx=Object.defineProperty,Jx=(t,e,n)=>e in t?Qx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dt=(t,e,n)=>Jx(t,typeof e!="symbol"?e+"":e,n),eb=0,kr=class{constructor(e,n=!1,r=!1,i="bi",s="#2962ff",a="",o="style_solid",l=1,c=!1){dt(this,"id"),dt(this,"points"),dt(this,"curved"),dt(this,"closed"),dt(this,"xloc"),dt(this,"line_color"),dt(this,"fill_color"),dt(this,"line_style"),dt(this,"line_width"),dt(this,"force_overlay"),dt(this,"_deleted"),dt(this,"_createdAtBar",-1),this.id=eb++,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}}},Cc=Object.defineProperty,tb=Object.getOwnPropertyDescriptor,nb=(t,e,n)=>e in t?Cc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,El=(t,e,n,r)=>{for(var i=r>1?void 0:r?tb(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&&Cc(e,n,i),i},rb=(t,e,n)=>nb(t,typeof e!="symbol"?e+"":e,n),Br=class{constructor(e){this.context=e,rb(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 rt?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 Ge):[]}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 Ge);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),x=new kr(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 x._createdAtBar=this.context.idx,this._polylines.push(x),this._enforceMaxCount(),x}_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 rt||typeof n=="number"&&isNaN(n))return null;if(n instanceof kr)return n;if(n instanceof y){let r=n.get(0);if(r==null||typeof r=="number"&&isNaN(r))return null;if(r instanceof kr)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()}};El([M],Br.prototype,"new",1),El([M],Br.prototype,"delete",1);var ib=Object.defineProperty,sb=(t,e,n)=>e in t?ib(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,et=(t,e,n)=>sb(t,typeof e!="symbol"?e+"":e,n),ab=0;function Ue(t){return Number.isFinite(t)?Math.trunc(t):NaN}var Vr=class{constructor(e="top_right",n=1,r=1,i="",s="",a=0,o="",l=0,c=!1){et(this,"id"),et(this,"position"),et(this,"columns"),et(this,"rows"),et(this,"bgcolor"),et(this,"frame_color"),et(this,"frame_width"),et(this,"border_color"),et(this,"border_width"),et(this,"force_overlay"),et(this,"_deleted"),et(this,"cells"),et(this,"merges"),et(this,"_helper"),this.id=ab++,this.position=e,this.columns=Ue(n),this.rows=Ue(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=Ue(e),n=Ue(n),!(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 e=Ue(e),n=Ue(n),n>=0&&n<this.rows&&e>=0&&e<this.columns?this.cells[n][e]:null}clearCell(e,n){e=Ue(e),n=Ue(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}}},Nc=Object.defineProperty,ob=Object.getOwnPropertyDescriptor,lb=(t,e,n)=>e in t?Nc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ee=(t,e,n,r)=>{for(var i=r>1?void 0:r?ob(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&&Nc(e,n,i),i},cb=(t,e,n)=>lb(t,typeof e!="symbol"?e+"":e,n),ub=["position","columns","rows","bgcolor","frame_color","frame_width","border_color","border_width","force_overlay"],hb=["column","row","text","width","height","text_color","text_halign","text_valign","text_size","bgcolor","tooltip","text_font_family","text_formatting"],Cl=["start_column","start_row","end_column","end_row"];function ni(t,e){return!!t&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof Vr)&&e.some(n=>n in t)}var be=class{constructor(e){this.context=e,cb(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(ni(p,ub)){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 Vr(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 Vr?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",x=e[e.length-1];if(ni(x,hb)){let w=x,S=e.slice(0,-1);n=S[0],r=S.length>1?S[1]:w.column??0,i=S.length>2?S[2]:w.row??0,s=S[3]??w.text??s,a=S[4]??w.width??a,o=S[5]??w.height??o,l=S[6]??w.text_color??l,c=S[7]??w.text_halign??c,u=S[8]??w.text_valign??u,p=S[9]??w.text_size??p,h=S[10]??w.bgcolor??h,d=S[11]??w.tooltip??d,f=S[12]??w.text_font_family??f,m=S[13]??w.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 b=this._resolve(n);if(!b||b._deleted)return;let v=this._resolve(r)??0,E=this._resolve(i)??0;b.setCell(v,E,{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(ni(o,Cl)){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=Ue(this._resolve(r)??0),u=Ue(this._resolve(i)??0),p=Ue(this._resolve(s)??c),h=Ue(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(ni(o,Cl)){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=Ue(this._resolve(r)??0),u=Ue(this._resolve(i)??0),p=Ue(this._resolve(s)??0),h=Ue(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.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)}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)}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)}};Ee([M],be.prototype,"new",1),Ee([M],be.prototype,"cell",1),Ee([M],be.prototype,"delete",1),Ee([M],be.prototype,"clear",1),Ee([M],be.prototype,"merge_cells",1),Ee([M],be.prototype,"cell_set_text",1),Ee([M],be.prototype,"cell_set_bgcolor",1),Ee([M],be.prototype,"cell_set_text_color",1),Ee([M],be.prototype,"cell_set_text_size",1),Ee([M],be.prototype,"cell_set_height",1),Ee([M],be.prototype,"cell_set_width",1),Ee([M],be.prototype,"cell_set_tooltip",1),Ee([M],be.prototype,"cell_set_text_halign",1),Ee([M],be.prototype,"cell_set_text_valign",1),Ee([M],be.prototype,"cell_set_text_font_family",1),Ee([M],be.prototype,"cell_set_text_formatting",1),Ee([M],be.prototype,"set_position",1),Ee([M],be.prototype,"set_bgcolor",1),Ee([M],be.prototype,"set_border_color",1),Ee([M],be.prototype,"set_border_width",1),Ee([M],be.prototype,"set_frame_color",1),Ee([M],be.prototype,"set_frame_width",1);function rn(t,e){let n=lo(t);if(n instanceof Ei)return n;throw new Te(`The \\`footprint\\` ID used in the \\`${e}()\\` call cannot be \\`na\\`.`,`footprint.${e}`)}var oa=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(){throw new Te("Could not find function or function reference \'footprint\'","footprint")}buy_volume(e){return rn(e,"buy_volume").buy_volume()}sell_volume(e){return rn(e,"sell_volume").sell_volume()}total_volume(e){return rn(e,"total_volume").total_volume()}delta(e){return rn(e,"delta").delta()}poc(e){return rn(e,"poc").poc()}vah(e){return rn(e,"vah").vah()}val(e){return rn(e,"val").val()}rows(e){return rn(e,"rows").rows()}get_row_by_price(e,n){return rn(e,"get_row_by_price").get_row_by_price(n)}};function pn(t,e){let n=lo(t);if(n instanceof Si)return n;throw new Te(`The \\`volume_row\\` ID used in the \\`${e}()\\` call cannot be \\`na\\`.`,`volume_row.${e}`)}var la=class{constructor(e){this.context=e}param(e,n=0,r){return y.from(e).get(n)}any(){throw new Te("Could not find function or function reference \'volume_row\'","volume_row")}up_price(e){return pn(e,"up_price").up_price()}down_price(e){return pn(e,"down_price").down_price()}buy_volume(e){return pn(e,"buy_volume").buy_volume()}sell_volume(e){return pn(e,"sell_volume").sell_volume()}total_volume(e){return pn(e,"total_volume").total_volume()}delta(e){return pn(e,"delta").delta()}has_buy_imbalance(e){return pn(e,"has_buy_imbalance").has_buy_imbalance()}has_sell_imbalance(e){return pn(e,"has_sell_imbalance").has_sell_imbalance()}},ca=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=xn(this._coerce(n)),{modifier:s}=Fr(r);return s&&s!=="standard"?Gs(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?xn(this.context?.pine?.syminfo?.tickerid||this.context?.tickerId||""):xn(this._coerce(e))}heikinashi(e){return Gs(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)}},pb=Object.defineProperty,db=(t,e,n)=>e in t?pb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Q=(t,e,n)=>db(t,typeof e!="symbol"?e+"":e,n),ua=class hi{constructor({marketData:e,source:n,tickerId:r,timeframe:i,limit:s,sDate:a,eDate:o,fullContext:l,inputs:c}){Q(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([])}),Q(this,"indicator"),Q(this,"cache",{}),Q(this,"taState",{}),Q(this,"strategy"),Q(this,"isSecondaryContext",!1),Q(this,"chartTimezone",null),Q(this,"chartStyle","standard"),Q(this,"dataVersion",0),Q(this,"__maxLoops",5e5),Q(this,"NA",NaN),Q(this,"warnings",[]),Q(this,"alerts",[]),Q(this,"_alertMode","realtime"),Q(this,"_propOverrides",{}),Q(this,"_execTick",0),Q(this,"lang"),Q(this,"length",0),Q(this,"_drawingHelpers",[]),Q(this,"pine"),Q(this,"idx",0),Q(this,"params",{}),Q(this,"const",{}),Q(this,"var",{}),Q(this,"let",{}),Q(this,"lctx",new Map),Q(this,"result"),Q(this,"plots",{}),Q(this,"marketData"),Q(this,"source"),Q(this,"tickerId"),Q(this,"timeframe",""),Q(this,"limit"),Q(this,"sDate"),Q(this,"eDate"),Q(this,"fullContext"),Q(this,"viewportLeft"),Q(this,"viewportRight"),Q(this,"pineTSCode"),Q(this,"inputs",{}),Q(this,"_callStack",[]),Q(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 wi(this),p={Type:u.Type.bind(u),na:new rt,nz:u.nz.bind(u),indicator:u.indicator.bind(u),fixnan:u.fixnan.bind(u),alertcondition:u.alertcondition.bind(u),alert:new vi(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 Ut(this,un.dayofmonth),dayofweek:new Ut(this,un.dayofweek),hour:new Ut(this,un.hour),minute:new Ut(this,un.minute),month:new Ut(this,un.month),second:new Ut(this,un.second),weekofyear:new Ut(this,un.weekofyear),year:new Ut(this,un.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 Hs(this),ta:new Js(this),math:new Ks(this),request:new Qs(this),array:new Fs(this),map:new Bs(this),matrix:new Vs(this),ticker:new ca(this),strategy:new ta(this),syminfo:null,timeframe:new sa(this),barstate:new $s(this),session:new Us(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 time_tradingday(){let A=y.from(h.data.closeTime).get(0);if(isNaN(A))return NaN;let H=h.pine?.syminfo?.timezone||"UTC",F=vn(A,H);return Date.UTC(F.year,F.month-1,F.day,0,0,0)},get inputs(){return h.inputs},log:new na(this),runtime:new ra(this),str:new ia(this),...p,...pc};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 Pt(this),m=new ki(this),x=new Ai(this);this.bindContextObject(f,["plotchar","plotshape","plotarrow","plotbar","plotcandle","bgcolor","barcolor"]),this.bindContextObject(f,["any","param","linestyle_dashed","linestyle_dotted","linestyle_solid","style_area","style_areabr","style_circles","style_columns","style_cross","style_histogram","style_line","style_linebr","style_stepline","style_stepline_diamond","style_steplinebr"],"plot"),this.bindContextObject(m,["any","style_dashed","style_solid","style_dotted","param"],"hline"),this.bindContextObject(x,["any","param"],"fill");let b=new aa(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 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 v=new Ne(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_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:()=>v.all});let E=new Pe(this);this.bindContextObject(E,["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:()=>E.all});let w=new fe(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 S=new ir(this);this.bindContextObject(S,["any","new","param","set_color","get_line1","get_line2","delete"],"linefill"),Object.defineProperty(this.pine.linefill,"all",{get:()=>S.all});let C=new Br(this);this.bindContextObject(C,["any","new","param","delete"],"polyline"),Object.defineProperty(this.pine.polyline,"all",{get:()=>C.all});let k=new be(this);this.bindContextObject(k,["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:()=>k.all}),this._drawingHelpers=[v,E,w,S,C,k];let B=new oa(this);this.bindContextObject(B,["any","param","buy_volume","sell_volume","total_volume","delta","poc","vah","val","rows","get_row_by_price"],"footprint");let P=new la(this);this.bindContextObject(P,["any","param","up_price","down_price","buy_volume","sell_volume","total_volume","delta","has_buy_imbalance","has_sell_imbalance"],"volume_row");let V=new zs(this);this.bindContextObject(V,["any","param","new","rgb","from_gradient","r","g","b","t","aqua","black","blue","fuchsia","gray","green","lime","maroon","navy","olive","orange","purple","red","silver","teal","white","yellow"],"color")}warn(e,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,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 _n){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?hi.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{let i=e(...r);return i===void 0?NaN:i}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}`;hi._deprecationWarningsShown.has(r)||(hi._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`))}};Q(ua,"_deprecationWarningsShown",new Set),Q(ua,"PRECISION_EPSILON",10**10);var ar=ua,fb=[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],Ic=[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],mb="\\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",kc="\\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",Is={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",yb={5:ks,"5module":ks+" export import",6:ks+" const class extends export import super"},Ac=/^in(stanceof)?$/,gb=new RegExp("["+kc+"]"),_b=new RegExp("["+kc+mb+"]");function ha(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 Jt(t,e){return t<65?t===36:t<91?!0:t<97?t===95:t<123?!0:t<=65535?t>=170&&gb.test(String.fromCharCode(t)):e===!1?!1:ha(t,Ic)}function wn(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&&_b.test(String.fromCharCode(t)):e===!1?!1:ha(t,Ic)||ha(t,fb)}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 ft(t,e){return new oe(t,{beforeExpr:!0,binop:e})}var mt={beforeExpr:!0},tt={startsExpr:!0},po={};function ie(t,e){return e===void 0&&(e={}),e.keyword=t,po[t]=new oe(t,e)}var g={num:new oe("num",tt),regexp:new oe("regexp",tt),string:new oe("string",tt),name:new oe("name",tt),privateId:new oe("privateId",tt),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(",",mt),semi:new oe(";",mt),colon:new oe(":",mt),dot:new oe("."),question:new oe("?",mt),questionDot:new oe("?."),arrow:new oe("=>",mt),template:new oe("template"),invalidTemplate:new oe("invalidTemplate"),ellipsis:new oe("...",mt),backQuote:new oe("`",tt),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:ft("||",1),logicalAND:ft("&&",2),bitwiseOR:ft("|",3),bitwiseXOR:ft("^",4),bitwiseAND:ft("&",5),equality:ft("==/!=/===/!==",6),relational:ft("</>/<=/>=",7),bitShift:ft("<</>>/>>>",8),plusMin:new oe("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:ft("%",10),star:ft("*",10),slash:ft("/",10),starstar:new oe("**",{beforeExpr:!0}),coalesce:ft("??",1),_break:ie("break"),_case:ie("case",mt),_catch:ie("catch"),_continue:ie("continue"),_debugger:ie("debugger"),_default:ie("default",mt),_do:ie("do",{isLoop:!0,beforeExpr:!0}),_else:ie("else",mt),_finally:ie("finally"),_for:ie("for",{isLoop:!0}),_function:ie("function",tt),_if:ie("if"),_return:ie("return",mt),_switch:ie("switch"),_throw:ie("throw",mt),_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",tt),_super:ie("super",tt),_class:ie("class",tt),_extends:ie("extends",mt),_export:ie("export"),_import:ie("import",tt),_null:ie("null",tt),_true:ie("true",tt),_false:ie("false",tt),_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})},it=/\\r\\n?|\\n|\\u2028|\\u2029/,xb=new RegExp(it.source,"g");function lr(t){return t===10||t===13||t===8232||t===8233}function Mc(t,e,n){n===void 0&&(n=t.length);for(var r=e;r<n;r++){var i=t.charCodeAt(r);if(lr(i))return r<n-1&&i===13&&t.charCodeAt(r+1)===10?r+2:r+1}return-1}var Tc=/[\\u1680\\u2000-\\u200a\\u202f\\u205f\\u3000\\ufeff]/,qe=/(?:\\s|\\/\\/.*|\\/\\*[^]*?\\*\\/)*/g,Pc=Object.prototype,bb=Pc.hasOwnProperty,vb=Pc.toString,cr=Object.hasOwn||(function(t,e){return bb.call(t,e)}),Nl=Array.isArray||(function(t){return vb.call(t)==="[object Array]"}),Il=Object.create(null);function gn(t){return Il[t]||(Il[t]=new RegExp("^(?:"+t.replace(/ /g,"|")+")$"))}function sn(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode((t>>10)+55296,(t&1023)+56320))}var wb=/(?:[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF])/,$r=function(t,e){this.line=t,this.column=e};$r.prototype.offset=function(t){return new $r(this.line,this.column+t)};var Ji=function(t,e,n){this.start=e,this.end=n,t.sourceFile!==null&&(this.source=t.sourceFile)};function Dc(t,e){for(var n=1,r=0;;){var i=Mc(t,r,e);if(i<0)return new $r(n,e-r);++n,r=i}}var pa={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},kl=!1;function Sb(t){var e={};for(var n in pa)e[n]=t&&cr(t,n)?t[n]:pa[n];if(e.ecmaVersion==="latest"?e.ecmaVersion=1e8:e.ecmaVersion==null?(!kl&&typeof console=="object"&&console.warn&&(kl=!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),Nl(e.onToken)){var r=e.onToken;e.onToken=function(i){return r.push(i)}}if(Nl(e.onComment)&&(e.onComment=Eb(e,e.onComment)),e.sourceType==="commonjs"&&e.allowAwaitOutsideFunction)throw new Error("Cannot use allowAwaitOutsideFunction with sourceType: commonjs");return e}function Eb(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 Ji(this,a,o)),t.ranges&&(l.range=[i,s]),e.push(l)}}var Pn=1,Rn=2,fo=4,Rc=8,mo=16,Oc=32,es=64,Lc=128,On=256,qr=512,Fc=1024,ts=Pn|Rn|On;function yo(t,e){return Rn|(t?fo:0)|(e?Rc:0)}var Ti=0,go=1,ln=2,Bc=3,Vc=4,$c=5,Le=function(t,e,n){this.options=t=Sb(t),this.sourceFile=t.sourceFile,this.keywords=gn(yb[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var r="";t.allowReserved!==!0&&(r=Is[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(r+=" await")),this.reservedWords=gn(r);var i=(r?r+" ":"")+Is.strict;this.reservedWordsStrict=gn(i),this.reservedWordsStrictBind=gn(i+" "+Is.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(it).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"?Rn:Pn),this.regexpState=null,this.privateNameStack=[]},vt={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}};Le.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};vt.inFunction.get=function(){return(this.currentVarScope().flags&Rn)>0};vt.inGenerator.get=function(){return(this.currentVarScope().flags&Rc)>0};vt.inAsync.get=function(){return(this.currentVarScope().flags&fo)>0};vt.canAwait.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(On|qr))return!1;if(n&Rn)return(n&fo)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};vt.allowReturn.get=function(){return!!(this.inFunction||this.options.allowReturnOutsideFunction&&this.currentVarScope().flags&Pn)};vt.allowSuper.get=function(){var t=this.currentThisScope(),e=t.flags;return(e&es)>0||this.options.allowSuperOutsideMethod};vt.allowDirectSuper.get=function(){return(this.currentThisScope().flags&Lc)>0};vt.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};vt.allowNewDotTarget.get=function(){for(var t=this.scopeStack.length-1;t>=0;t--){var e=this.scopeStack[t],n=e.flags;if(n&(On|qr)||n&Rn&&!(n&mo))return!0}return!1};vt.allowUsing.get=function(){var t=this.currentScope(),e=t.flags;return!(e&Fc||!this.inModule&&e&Pn)};vt.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&On)>0};Le.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};Le.parse=function(t,e){return new this(e,t).parse()};Le.parseExpressionAt=function(t,e,n){var r=new this(n,t,e);return r.nextToken(),r.parseExpression()};Le.tokenizer=function(t,e){return new this(e,t)};Object.defineProperties(Le.prototype,vt);var Ze=Le.prototype,Cb=/^(?:\'((?:\\\\[^]|[^\'\\\\])*?)\'|"((?:\\\\[^]|[^"\\\\])*?)")/;Ze.strictDirective=function(t){if(this.options.ecmaVersion<5)return!1;for(;;){qe.lastIndex=t,t+=qe.exec(this.input)[0].length;var e=Cb.exec(this.input.slice(t));if(!e)return!1;if((e[1]||e[2])==="use strict"){qe.lastIndex=t+e[0].length;var n=qe.exec(this.input),r=n.index+n[0].length,i=this.input.charAt(r);return i===";"||i==="}"||it.test(n[0])&&!(/[(`.[+\\-/*%<>=,?^&]/.test(i)||i==="!"&&this.input.charAt(r+1)==="=")}t+=e[0].length,qe.lastIndex=t,t+=qe.exec(this.input)[0].length,this.input[t]===";"&&t++}};Ze.eat=function(t){return this.type===t?(this.next(),!0):!1};Ze.isContextual=function(t){return this.type===g.name&&this.value===t&&!this.containsEsc};Ze.eatContextual=function(t){return this.isContextual(t)?(this.next(),!0):!1};Ze.expectContextual=function(t){this.eatContextual(t)||this.unexpected()};Ze.canInsertSemicolon=function(){return this.type===g.eof||this.type===g.braceR||it.test(this.input.slice(this.lastTokEnd,this.start))};Ze.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};Ze.semicolon=function(){!this.eat(g.semi)&&!this.insertSemicolon()&&this.unexpected()};Ze.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0};Ze.expect=function(t){this.eat(t)||this.unexpected()};Ze.unexpected=function(t){this.raise(t??this.start,"Unexpected token")};var ns=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};Ze.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")}};Ze.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")};Ze.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")};Ze.isSimpleAssignTarget=function(t){return t.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(t.expression):t.type==="Identifier"||t.type==="MemberExpression"};var j=Le.prototype;j.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 _o={kind:"loop"},Nb={kind:"switch"};j.isLet=function(t){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;qe.lastIndex=this.pos;var e=qe.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(Jt(r)){var i=n;do n+=r<=65535?1:2;while(wn(r=this.fullCharCodeAt(n)));if(r===92)return!0;var s=this.input.slice(i,n);if(!Ac.test(s))return!0}return!1};j.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;qe.lastIndex=this.pos;var t=qe.exec(this.input),e=this.pos+t[0].length,n;return!it.test(this.input.slice(this.pos,e))&&this.input.slice(e,e+8)==="function"&&(e+8===this.input.length||!(wn(n=this.fullCharCodeAt(e+8))||n===92))};j.isUsingKeyword=function(t,e){if(this.options.ecmaVersion<17||!this.isContextual(t?"await":"using"))return!1;qe.lastIndex=this.pos;var n=qe.exec(this.input),r=this.pos+n[0].length;if(it.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||wn(s=this.fullCharCodeAt(i))||s===92)return!1;qe.lastIndex=i;var a=qe.exec(this.input);if(r=i+a[0].length,a&&it.test(this.input.slice(i,r)))return!1}var o=this.fullCharCodeAt(r);if(!Jt(o)&&o!==92)return!1;var l=r;do r+=o<=65535?1:2;while(wn(o=this.fullCharCodeAt(r)));if(o===92)return!0;var c=this.input.slice(l,r);return!(Ac.test(c)||e&&c==="of")};j.isAwaitUsing=function(t){return this.isUsingKeyword(!0,t)};j.isUsing=function(t){return this.isUsingKeyword(!1,t)};j.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){qe.lastIndex=this.pos;var a=qe.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)}};j.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")};j.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")};j.parseDoStatement=function(t){return this.next(),this.labels.push(_o),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")};j.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(_o),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 ns,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))};j.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))};j.parseFunctionStatement=function(t,e,n){return this.next(),this.parseFunction(t,Ar|(n?0:da),!1,e)};j.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")};j.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")};j.parseSwitchStatement=function(t){this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(g.braceL),this.labels.push(Nb),this.enterScope(Fc);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")};j.parseThrowStatement=function(t){return this.next(),it.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 Ib=[];j.parseCatchClauseParam=function(){var t=this.parseBindingAtom(),e=t.type==="Identifier";return this.enterScope(e?Oc:0),this.checkLValPattern(t,e?Vc:ln),this.expect(g.parenR),t};j.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")};j.parseVarStatement=function(t,e,n){return this.next(),this.parseVar(t,!1,e,n),this.semicolon(),this.finishNode(t,"VariableDeclaration")};j.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(_o),t.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(t,"WhileStatement")};j.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")};j.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")};j.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")};j.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")};j.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")};j.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")};j.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")};j.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};j.parseVarId=function(t,e){t.id=e==="using"||e==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(t.id,e==="var"?go:ln,!1)};var Ar=1,da=2,Wc=4;j.parseFunction=function(t,e,n,r,i){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===g.star&&e&da&&this.unexpected(),t.generator=this.eat(g.star)),this.options.ecmaVersion>=8&&(t.async=!!r),e&Ar&&(t.id=e&Wc&&this.type!==g.name?null:this.parseIdent(),t.id&&!(e&da)&&this.checkLValSimple(t.id,this.strict||t.generator||t.async?this.treatFunctionsAsVar?go:ln:Bc));var s=this.yieldPos,a=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(yo(t.async,t.generator)),e&Ar||(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&Ar?"FunctionDeclaration":"FunctionExpression")};j.parseFunctionParams=function(t){this.expect(g.parenL),t.params=this.parseBindingList(g.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};j.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"&&kb(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")};j.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&&Pi(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};j.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};j.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)};j.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&&Pi(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")};j.parseClassField=function(t){return Pi(t,"constructor")?this.raise(t.key.start,"Classes can\'t have a field named \'constructor\'"):t.static&&Pi(t,"prototype")&&this.raise(t.key.start,"Classes can\'t have a static field named \'prototype\'"),this.eat(g.eq)?(this.enterScope(qr|es),t.value=this.parseMaybeAssign(),this.exitScope()):t.value=null,this.semicolon(),this.finishNode(t,"PropertyDefinition")};j.parseClassStaticBlock=function(t){t.body=[];var e=this.labels;for(this.labels=[],this.enterScope(On|es);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")};j.parseClassId=function(t,e){this.type===g.name?(t.id=this.parseIdent(),e&&this.checkLValSimple(t.id,ln,!1)):(e===!0&&this.unexpected(),t.id=null)};j.parseClassSuper=function(t){t.superClass=this.eat(g._extends)?this.parseExprSubscripts(null,!1):null};j.enterClassBody=function(){var t={declared:Object.create(null),used:[]};return this.privateNameStack.push(t),t.declared};j.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];cr(e,a.name)||(i?i.used.push(a):this.raiseRecoverable(a.start,"Private field \'#"+a.name+"\' must be declared in an enclosing class"))}};function kb(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 Pi(t,e){var n=t.computed,r=t.key;return!n&&(r.type==="Identifier"&&r.name===e||r.type==="Literal"&&r.value===e)}j.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")};j.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")};j.parseExportDeclaration=function(t){return this.parseStatement(null)};j.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,Ar|Wc,!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}};j.checkExport=function(t,e,n){t&&(typeof e!="string"&&(e=e.type==="Identifier"?e.name:e.value),cr(t,e)&&this.raiseRecoverable(n,"Duplicate export \'"+e+"\'"),t[e]=!0)};j.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)};j.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)}};j.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};j.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")};j.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};j.parseImport=function(t){return this.next(),this.type===g.string?(t.specifiers=Ib,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")};j.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,ln),this.finishNode(t,"ImportSpecifier")};j.parseImportDefaultSpecifier=function(){var t=this.startNode();return t.local=this.parseIdent(),this.checkLValSimple(t.local,ln),this.finishNode(t,"ImportDefaultSpecifier")};j.parseImportNamespaceSpecifier=function(){var t=this.startNode();return this.next(),this.expectContextual("as"),t.local=this.parseIdent(),this.checkLValSimple(t.local,ln),this.finishNode(t,"ImportNamespaceSpecifier")};j.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};j.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;cr(e,i)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key \'"+i+"\'"),e[i]=!0,t.push(r)}return t};j.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")};j.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===g.string){var t=this.parseLiteral(this.value);return wb.test(t.value)&&this.raise(t.start,"An export name cannot include a lone surrogate."),t}return this.parseIdent(!0)};j.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)};j.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 wt=Le.prototype;wt.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};wt.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};wt.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")};wt.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")};wt.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()};wt.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};wt.parseAssignableListItem=function(t){var e=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(e),e};wt.parseBindingListItem=function(t){return t};wt.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")};wt.checkLValSimple=function(t,e,n){e===void 0&&(e=Ti);var r=e!==Ti;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===ln&&t.name==="let"&&this.raiseRecoverable(t.start,"let is disallowed as a lexically bound name"),n&&(cr(n,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),n[t.name]=!0),e!==$c&&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")}};wt.checkLValPattern=function(t,e,n){switch(e===void 0&&(e=Ti),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)}};wt.checkLValInnerPattern=function(t,e,n){switch(e===void 0&&(e=Ti),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 kt=function(t,e,n,r,i){this.token=t,this.isExpr=!!e,this.preserveSpace=!!n,this.override=r,this.generator=!!i},we={b_stat:new kt("{",!1),b_expr:new kt("{",!0),b_tmpl:new kt("${",!1),p_stat:new kt("(",!1),p_expr:new kt("(",!0),q_tmpl:new kt("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new kt("function",!1),f_expr:new kt("function",!0),f_expr_gen:new kt("function",!0,!1,null,!0),f_gen:new kt("function",!1,!1,null,!0)},ur=Le.prototype;ur.initialContext=function(){return[we.b_stat]};ur.curContext=function(){return this.context[this.context.length-1]};ur.braceIsBlock=function(t){var e=this.curContext();return e===we.f_expr||e===we.f_stat?!0:t===g.colon&&(e===we.b_stat||e===we.b_expr)?!e.isExpr:t===g._return||t===g.name&&this.exprAllowed?it.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===we.b_stat:t===g._var||t===g._const||t===g.name?!1:!this.exprAllowed};ur.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};ur.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};ur.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===we.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)?we.b_stat:we.b_expr),this.exprAllowed=!0};g.dollarBraceL.updateContext=function(){this.context.push(we.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?we.p_stat:we.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()!==we.p_stat)&&!(t===g._return&&it.test(this.input.slice(this.lastTokEnd,this.start)))&&!((t===g.colon||t===g.braceL)&&this.curContext()===we.b_stat)?this.context.push(we.f_expr):this.context.push(we.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()===we.q_tmpl?this.context.pop():this.context.push(we.q_tmpl),this.exprAllowed=!1};g.star.updateContext=function(t){if(t===g._function){var e=this.context.length-1;this.context[e]===we.f_expr?this.context[e]=we.f_expr_gen:this.context[e]=we.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 Z=Le.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===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};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 ns,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};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(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};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!==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};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===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"&&jc(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&fa(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 jc(t){return t.type==="Identifier"||t.type==="ParenthesizedExpression"&&jc(t.expression)}function fa(t){return t.type==="MemberExpression"&&t.property.type==="PrivateIdentifier"||t.type==="ChainExpression"&&fa(t.expression)||t.type==="ParenthesizedExpression"&&fa(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(g.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(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 ns,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 x=this.startNodeAt(e,n);x.callee=t,x.arguments=m,o&&(x.optional=l),t=this.finishNode(x,"CallExpression")}else if(this.type===g.backQuote){(l||s)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var b=this.startNodeAt(e,n);b.tag=t,b.quasi=this.parseTemplate({isTagged:!0}),t=this.finishNode(b,"TaggedTemplateExpression")}return t};Z.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(we.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(we.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()}};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===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()};Z.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")};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(g.parenL);var t=this.parseExpression();return this.expect(g.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 ns,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,x=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,x)):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};Z.parseParenItem=function(t){return t};Z.parseParenArrowList=function(t,e,n,r){return this.parseArrowExpression(this.startNodeAt(t,e),n,!1,r)};var Ab=[];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===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=Ab,this.finishNode(t,"NewExpression")};Z.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")};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===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")};Z.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)&&!it.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(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")};Z.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")};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===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()};Z.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")};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(yo(e,r.generator)|es|(n?Lc: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")};Z.parseArrowExpression=function(t,e,n,r){var i=this.yieldPos,s=this.awaitPos,a=this.awaitIdentPos;return this.enterScope(yo(n,!1)|mo),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!==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,$c),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,go,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(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};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&ts)&&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===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};Z.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};Z.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")};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 Di=Le.prototype;Di.raise=function(t,e){var n=Dc(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};Di.raiseRecoverable=Di.raise;Di.curPosition=function(){if(this.options.locations)return new $r(this.curLine,this.pos-this.lineStart)};var En=Le.prototype,Mb=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};En.enterScope=function(t){this.scopeStack.push(new Mb(t))};En.exitScope=function(){this.scopeStack.pop()};En.treatFunctionsAsVarInScope=function(t){return t.flags&Rn||!this.inModule&&t.flags&Pn};En.declareName=function(t,e,n){var r=!1;if(e===ln){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&Pn&&delete this.undefinedExports[t]}else if(e===Vc){var s=this.currentScope();s.lexical.push(t)}else if(e===Bc){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&Oc&&l.lexical[0]===t)||!this.treatFunctionsAsVarInScope(l)&&l.functions.indexOf(t)>-1){r=!0;break}if(l.var.push(t),this.inModule&&l.flags&Pn&&delete this.undefinedExports[t],l.flags&ts)break}r&&this.raiseRecoverable(n,"Identifier \'"+t+"\' has already been declared")};En.checkLocalExport=function(t){this.scopeStack[0].lexical.indexOf(t.name)===-1&&this.scopeStack[0].var.indexOf(t.name)===-1&&(this.undefinedExports[t.name]=t)};En.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};En.currentVarScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(ts|qr|On))return e}};En.currentThisScope=function(){for(var t=this.scopeStack.length-1;;t--){var e=this.scopeStack[t];if(e.flags&(ts|qr|On)&&!(e.flags&mo))return e}};var rs=function(t,e,n){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new Ji(t,n)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},zr=Le.prototype;zr.startNode=function(){return new rs(this,this.start,this.startLoc)};zr.startNodeAt=function(t,e){return new rs(this,t,e)};function Uc(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}zr.finishNode=function(t,e){return Uc.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)};zr.finishNodeAt=function(t,e,n,r){return Uc.call(this,t,e,n,r)};zr.copyNode=function(t){var e=new rs(this,t.start,this.startLoc);for(var n in t)e[n]=t[n];return e};var Tb="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",qc="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",zc=qc+" Extended_Pictographic",Hc=zc,Kc=Hc+" EBase EComp EMod EPres ExtPict",Yc=Kc,Pb=Yc,Db={9:qc,10:zc,11:Hc,12:Kc,13:Yc,14:Pb},Rb="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Ob={9:"",10:"",11:"",12:"",13:"",14:Rb},Al="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",Gc="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",Xc=Gc+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",Zc=Xc+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",Qc=Zc+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",Jc=Qc+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",Lb=Jc+" "+Tb,Fb={9:Gc,10:Xc,11:Zc,12:Qc,13:Jc,14:Lb},eu={};function Bb(t){var e=eu[t]={binary:gn(Db[t]+" "+Al),binaryOfStrings:gn(Ob[t]),nonBinary:{General_Category:gn(Al),Script:gn(Fb[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(ri=0,As=[9,10,11,12,13,14];ri<As.length;ri+=1)Ml=As[ri],Bb(Ml);var Ml,ri,As,W=Le.prototype,Ri=function(t,e){this.parent=t,this.base=e||this};Ri.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};Ri.prototype.sibling=function(){return new Ri(this.parent,this.base)};var en=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=eu[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};en.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)};en.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};en.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};en.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};en.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};en.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};en.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};en.prototype.eat=function(t,e){return e===void 0&&(e=!1),this.current(e)===t?(this.advance(e),!0):!1};en.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 Vb(t){for(var e in t)return!0;return!1}W.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&Vb(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 Ri(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&&$b(n);)e+=sn(n),t.advance();return e};function $b(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 tu(e)?(t.lastIntValue=e,t.advance(),!0):!1};function tu(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&&!tu(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+=sn(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=sn(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),Wb(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function Wb(t){return Jt(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),jb(r)?(t.lastIntValue=r,!0):(t.pos=e,!1)};function jb(t){return wn(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&&!is(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 nu(e)?(t.lastIntValue=e%32,t.advance(),!0):!1};function nu(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)&&Ub(t.lastIntValue))return!0;r&&t.raise("Invalid unicode escape"),t.pos=n}return!1};function Ub(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 ru=0,an=1,xt=2;W.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(qb(e))return t.lastIntValue=-1,t.advance(),an;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===xt&&t.raise("Invalid property name"),r;t.raise("Invalid property name")}return ru};function qb(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),an}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var i=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,i)}return ru};W.regexp_validateUnicodePropertyNameAndValue=function(t,e,n){cr(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 an;if(t.switchV&&t.unicodeProperties.binaryOfStrings.test(e))return xt;t.raise("Invalid property name")};W.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";iu(e=t.current());)t.lastStringValue+=sn(e),t.advance();return t.lastStringValue!==""};function iu(t){return nu(t)||t===95}W.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";zb(e=t.current());)t.lastStringValue+=sn(e),t.advance();return t.lastStringValue!==""};function zb(t){return iu(t)||is(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===xt&&t.raise("Negated character class may contain strings"),!0}return!1};W.regexp_classContents=function(t){return t.current()===93?an:t.switchV?this.regexp_classSetExpression(t):(this.regexp_nonEmptyClassRanges(t),an)};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||ou(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=an,n;if(!this.regexp_eatClassSetRange(t))if(n=this.regexp_eatClassSetOperand(t)){n===xt&&(e=xt);for(var r=t.pos;t.eatChars([38,38]);){if(t.current()!==38&&(n=this.regexp_eatClassSetOperand(t))){n!==xt&&(e=an);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===xt&&(e=xt)}};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)?an: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===xt&&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)===xt&&(e=xt);return e};W.regexp_classString=function(t){for(var e=0;this.regexp_eatClassSetCharacter(t);)e++;return e===1?an:xt};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()&&Hb(n)||Kb(n)?!1:(t.advance(),t.lastIntValue=n,!0)};function Hb(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 Kb(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 Yb(e)?(t.lastIntValue=e,t.advance(),!0):!1};function Yb(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 is(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;is(n=t.current());)t.lastIntValue=10*t.lastIntValue+(n-48),t.advance();return t.pos!==e};function is(t){return t>=48&&t<=57}W.regexp_eatHexDigits=function(t){var e=t.pos,n=0;for(t.lastIntValue=0;su(n=t.current());)t.lastIntValue=16*t.lastIntValue+au(n),t.advance();return t.pos!==e};function su(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function au(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 ou(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)};function ou(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(!su(i))return t.pos=n,!1;t.lastIntValue=16*t.lastIntValue+au(i),t.advance()}return!0};var xo=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Ji(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},ne=Le.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 xo(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 xo(this)};typeof Symbol<"u"&&(ne[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===g.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(g.eof);if(t.override)return t.override(this);this.readToken(this.fullCharCodeAtPos())};ne.readToken=function(t){return Jt(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=Mc(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&&!lr(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&&Tc.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(g.ellipsis)):(++this.pos,this.finishToken(g.dot))};ne.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)};ne.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)};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(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)};ne.readToken_caret=function(){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(g.assign,2):this.finishOp(g.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||it.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)};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(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))};ne.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)};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(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)};ne.readToken_numberSign=function(){var t=this.options.ecmaVersion,e=35;if(t>=13&&(++this.pos,e=this.fullCharCodeAtPos(),Jt(e,!0)||e===92))return this.finishToken(g.privateId,this.readWord1());this.raise(this.pos,"Unexpected character \'"+sn(e)+"\'")};ne.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 \'"+sn(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(it.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 en(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})};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 Gb(t,e){return e?parseInt(t,8):parseFloat(t.replace(/_/g,""))}function lu(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=lu(this.input.slice(e,this.pos)),++this.pos):Jt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(g.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=lu(this.input.slice(e,this.pos));return++this.pos,Jt(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")),Jt(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var s=Gb(this.input.slice(e,this.pos),n);return this.finishToken(g.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)):(lr(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return e+=this.input.slice(n,this.pos++),this.finishToken(g.string,e)};var cu={};ne.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t===cu)this.readInvalidTemplateToken();else throw t}this.inTemplateElement=!1};ne.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw cu;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===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(lr(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(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")};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 sn(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 lr(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(wn(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?Jt:wn)(a,r)||this.invalidStringToken(s,"Invalid Unicode escape"),t+=sn(a),n=this.pos}else break;e=!1}return t+this.input.slice(n,this.pos)};ne.readWord=function(){var t=this.readWord1(),e=g.name;return this.keywords.test(t)&&(e=po[t]),this.finishToken(e,t)};var Xb="8.16.0";Le.acorn={Parser:Le,version:Xb,defaultOptions:pa,Position:$r,SourceLocation:Ji,getLineInfo:Dc,Node:rs,TokenType:oe,tokTypes:g,keywordTypes:po,TokContext:kt,tokContexts:we,isIdentifierChar:wn,isIdentifierStart:Jt,Token:xo,isNewLine:lr,lineBreak:it,lineBreakG:xb,nonASCIIwhitespace:Tc};function bo(t,e){return Le.parse(t,e)}var{stringify:Zb}=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 ii={"||":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},Rt=17,Qb={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:Rt,ClassExpression:Rt,FunctionExpression:Rt,ObjectExpression:Rt,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};function Qn(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 uu(t,e,n,r){let i=t.expressionsPrecedence[e.type];if(i===Rt)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?ii[e.operator]<=ii[n.operator]:ii[e.operator]<ii[n.operator]}function si(t,e,n,r){let{generator:i}=t;uu(t,e,n,r)?(t.write("("),i[e.type](e,t),t.write(")")):i[e.type](e,t)}function Jb(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 He(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("/*"),Jb(t,a.value,n,r),t.write("*/"+r))}}function e1(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 Ms(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 Tl,Pl,Dl,Rl,Ol,Ll,vo={Program(t,e){let n=e.indent.repeat(e.indentLevel),{lineEnd:r,writeComments:i}=e;i&&t.comments!=null&&He(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&&He(e,l.comments,n,r),e.write(n),this[l.type](l,e),e.write(r)}i&&t.trailingComments!=null&&He(e,t.trailingComments,n,r)},BlockStatement:Ll=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&&He(e,t.comments,s,r);let{length:o}=a;for(let l=0;l<o;l++){let c=a[l];i&&c.comments!=null&&He(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),He(e,t.comments,s,r),e.write(n));i&&t.trailingComments!=null&&He(e,t.trailingComments,s,r),e.write("}"),e.indentLevel--},ClassBody:Ll,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===Rt||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&&He(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&&He(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"?Ms(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:Tl=function(t,e){e.write(`for ${t.await?"await ":""}(`);let{left:n}=t;n.type[0]==="V"?Ms(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:Tl,DebuggerStatement(t,e){e.write("debugger;",t)},FunctionDeclaration:Pl=function(t,e){e.write((t.async?"async ":"")+(t.generator?"function* ":"function ")+(t.id?t.id.name:""),t),Qn(e,t.params),e.write(" "),this[t.body.type](t.body,e)},FunctionExpression:Pl,VariableDeclaration(t,e){Ms(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===Rt||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),Qn(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]):Qn(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:Dl=function(t,e){e.write("..."),this[t.argument.type](t.argument,e)},SpreadElement:Dl,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),si(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){si(e,t.tag,t),this[t.quasi.type](t.quasi,e)},ArrayExpression:Ol=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:Ol,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&&He(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&&He(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&&He(e,t.trailingComments,s,r),e.write(n+"}")}else i?t.comments!=null?(e.write(r),He(e,t.comments,s,r),t.trailingComments!=null&&He(e,t.trailingComments,s,r),e.write(n+"}")):t.trailingComments!=null?(e.write(r),He(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){Qn(e,t.expressions)},UnaryExpression(t,e){if(t.prefix){let{operator:n,argument:r,argument:{type:i}}=t;e.write(n);let s=uu(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:Rl=function(t,e){let n=t.operator==="in";n&&e.write("("),si(e,t.left,t,!1),e.write(" "+t.operator+" "),si(e,t.right,t,!0),n&&e.write(")")},LogicalExpression:Rl,ConditionalExpression(t,e){let{test:n}=t,r=e.expressionsPrecedence[n.type];r===Rt||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===Rt||n<e.expressionsPrecedence.CallExpression||e1(t.callee)?(e.write("("),this[t.callee.type](t.callee,e),e.write(")")):this[t.callee.type](t.callee,e),Qn(e,t.arguments)},CallExpression(t,e){let n=e.expressionsPrecedence[t.callee.type];n===Rt||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("?."),Qn(e,t.arguments)},ChainExpression(t,e){this[t.expression.type](t.expression,e)},MemberExpression(t,e){let n=e.expressionsPrecedence[t.object.type];n===Rt||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(Zb(t.value),t)},RegExpLiteral(t,e){let{regex:n}=t;e.write(`/${n.pattern}/${n.flags}`,t)}},t1={},n1=vo,ma=class{constructor(e){let n=e??t1;this.output="",n.output!=null?(this.output=n.output,this.write=this.writeToStream):this.output="",this.generator=n.generator!=null?n.generator:vo,this.expressionsPrecedence=n.expressionsPrecedence!=null?n.expressionsPrecedence:Qb,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 wo(t,e){let n=new ma(e);return n.generator[t.type](t,n),n.output}var r1=Object.defineProperty,i1=(t,e,n)=>e in t?r1(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,le=(t,e,n)=>i1(t,typeof e!="symbol"?e+"":e,n),s1=new Set(["Infinity","NaN","undefined","null","true","false"]),a1=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 ya(t){if(!t||typeof t!="string")return;let e=t.trim(),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 ga=class{constructor(){le(this,"scopes",[]),le(this,"scopeTypes",[]),le(this,"scopeCounts",new Map),le(this,"contextBoundVars",new Set),le(this,"arrayPatternElements",new Set),le(this,"rootParams",new Set),le(this,"localSeriesVars",new Set),le(this,"varKinds",new Map),le(this,"loopVars",new Set),le(this,"loopVarNames",new Map),le(this,"paramIdCounter",0),le(this,"cacheIdCounter",0),le(this,"tempVarCounter",0),le(this,"taCallIdCounter",0),le(this,"userCallIdCounter",0),le(this,"plotCallIdCounter",0),le(this,"alertCallIdCounter",0),le(this,"loopGuardCounter",0),le(this,"hoistingStack",[]),le(this,"suppressHoisting",!1),le(this,"reservedNames",new Set),le(this,"userFunctions",new Set),le(this,"userMethods",new Set),le(this,"regularUserFunctions",new Set),le(this,"udtTypeNames",new Map),le(this,"udtInstances",new Map),le(this,"functionReturnTypes",new Map),le(this,"functionReturnTupleTypes",new Map),le(this,"functionParamUdtTypes",new Map),le(this,"varStaticTypes",new Map),le(this,"methodReceiverTypes",new Map),le(this,"functionParamStaticTypes",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=ya(n);r&&this.varStaticTypes.set(e,r)}getVarStaticType(e){return this.varStaticTypes.get(e)}unsetVarStaticType(e){this.varStaticTypes.delete(e)}setMethodReceiverType(e,n){let r=ya(n);r&&this.methodReceiverTypes.set(e,r)}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 s1.has(e)||a1.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 bt(t,e,n,r,i){n||(n=D),(function s(a,o,l){var c=l||a.type;pu(n,c,a,o,s),e[c]&&e[c](a,o)})(t,r,i)}function hu(t,e,n,r,i){var s=[];n||(n=D),(function a(o,l,c){var u=c||o.type,p=o!==s[s.length-1];p&&s.push(o),pu(n,u,o,l,a),e[u]&&e[u](o,l||s,s),p&&s.pop()})(t,r,i)}function Re(t,e,n,r,i){var s=n?o1(n,r||void 0):r;(function a(o,l,c){s[c||o.type](o,l,a)})(t,e,i)}function o1(t,e){var n=Object.create(e||D);for(var r in t)n[r]=t[r];return n}function So(t,e,n){n(t,e)}function Ln(t,e,n){}function pu(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 D={};D.Program=D.BlockStatement=D.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")}};D.Statement=So;D.EmptyStatement=Ln;D.ExpressionStatement=D.ParenthesizedExpression=D.ChainExpression=function(t,e,n){return n(t.expression,e,"Expression")};D.IfStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Statement"),t.alternate&&n(t.alternate,e,"Statement")};D.LabeledStatement=function(t,e,n){return n(t.body,e,"Statement")};D.BreakStatement=D.ContinueStatement=Ln;D.WithStatement=function(t,e,n){n(t.object,e,"Expression"),n(t.body,e,"Statement")};D.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)}};D.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")}};D.ReturnStatement=D.YieldExpression=D.AwaitExpression=function(t,e,n){t.argument&&n(t.argument,e,"Expression")};D.ThrowStatement=D.SpreadElement=function(t,e,n){return n(t.argument,e,"Expression")};D.TryStatement=function(t,e,n){n(t.block,e,"Statement"),t.handler&&n(t.handler,e),t.finalizer&&n(t.finalizer,e,"Statement")};D.CatchClause=function(t,e,n){t.param&&n(t.param,e,"Pattern"),n(t.body,e,"Statement")};D.WhileStatement=D.DoWhileStatement=function(t,e,n){n(t.test,e,"Expression"),n(t.body,e,"Statement")};D.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")};D.ForInStatement=D.ForOfStatement=function(t,e,n){n(t.left,e,"ForInit"),n(t.right,e,"Expression"),n(t.body,e,"Statement")};D.ForInit=function(t,e,n){t.type==="VariableDeclaration"?n(t,e):n(t,e,"Expression")};D.DebuggerStatement=Ln;D.FunctionDeclaration=function(t,e,n){return n(t,e,"Function")};D.VariableDeclaration=function(t,e,n){for(var r=0,i=t.declarations;r<i.length;r+=1){var s=i[r];n(s,e)}};D.VariableDeclarator=function(t,e,n){n(t.id,e,"Pattern"),t.init&&n(t.init,e,"Expression")};D.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")};D.Pattern=function(t,e,n){t.type==="Identifier"?n(t,e,"VariablePattern"):t.type==="MemberExpression"?n(t,e,"MemberPattern"):n(t,e)};D.VariablePattern=Ln;D.MemberPattern=So;D.RestElement=function(t,e,n){return n(t.argument,e,"Pattern")};D.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")}};D.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")}};D.Expression=So;D.ThisExpression=D.Super=D.MetaProperty=Ln;D.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")}};D.ObjectExpression=function(t,e,n){for(var r=0,i=t.properties;r<i.length;r+=1){var s=i[r];n(s,e)}};D.FunctionExpression=D.ArrowFunctionExpression=D.FunctionDeclaration;D.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")}};D.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")}};D.TemplateElement=Ln;D.UnaryExpression=D.UpdateExpression=function(t,e,n){n(t.argument,e,"Expression")};D.BinaryExpression=D.LogicalExpression=function(t,e,n){n(t.left,e,"Expression"),n(t.right,e,"Expression")};D.AssignmentExpression=D.AssignmentPattern=function(t,e,n){n(t.left,e,"Pattern"),n(t.right,e,"Expression")};D.ConditionalExpression=function(t,e,n){n(t.test,e,"Expression"),n(t.consequent,e,"Expression"),n(t.alternate,e,"Expression")};D.NewExpression=D.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")}};D.MemberExpression=function(t,e,n){n(t.object,e,"Expression"),t.computed&&n(t.property,e,"Expression")};D.ExportNamedDeclaration=D.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)}};D.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)}};D.ImportAttribute=function(t,e,n){n(t.value,e,"Expression")};D.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)}};D.ImportExpression=function(t,e,n){n(t.source,e,"Expression"),t.options&&n(t.options,e,"Expression")};D.ImportSpecifier=D.ImportDefaultSpecifier=D.ImportNamespaceSpecifier=D.Identifier=D.PrivateIdentifier=D.Literal=Ln;D.TaggedTemplateExpression=function(t,e,n){n(t.tag,e,"Expression"),n(t.quasi,e,"Expression")};D.ClassDeclaration=D.ClassExpression=function(t,e,n){return n(t,e,"Class")};D.Class=function(t,e,n){t.id&&n(t.id,e,"Pattern"),t.superClass&&n(t.superClass,e,"Expression"),n(t.body,e)};D.ClassBody=function(t,e,n){for(var r=0,i=t.body;r<i.length;r+=1){var s=i[r];n(s,e)}};D.MethodDefinition=D.PropertyDefinition=D.Property=function(t,e,n){t.computed&&n(t.key,e,"Expression"),t.value&&n(t.value,e,"Expression")};var Ce="$",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}}},Cn=["ta","math","request","array","input","color","ticker","strategy"],Lt=["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"],l1=["request.security","request.security_lower_tf","request.footprint"],c1=["chart.left_visible_bar_time","chart.right_visible_bar_time"],Fl=["plot","hline","fill","strategy.exit"],u1=["line.new","line.copy","label.new","label.copy","polyline.new","box.new","box.copy","table.new","linefill.new"],pi=new Set([...Cn,"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"]),ai=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"]),h1=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"]),p1={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"])},du=new Set(["poc","vah","val","get_row_by_price"]),fu=["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4","openTime","closeTime"],Eo=[...Cn,"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","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"],d1=["na","nz","plot","plotchar","color","hline","fill"];function f1(t){let e=null,n=Ce;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)})};Re(t,{},{VariableDeclarator(d,f,m){s(d.id),d.init&&m(d.init,f)},FunctionDeclaration(d,f,m){s(d.id);for(let x of d.params)x&&x.type==="AssignmentPattern"&&x.right&&m(x.right,f);m(d.body,f)},Identifier(d,f,m){i.add(d.name)},MemberExpression(d,f,m){m(d.object,f),d.computed&&m(d.property,f)},Property(d,f,m){d.computed&&m(d.key,f),m(d.value,f)}}),e.forEach(d=>{d.type==="VariableDeclaration"?d.declarations.forEach(f=>s(f.id)):d.type==="FunctionDeclaration"&&s(d.id)});let a=fu,o=Eo,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 m1(t){let e=null,n=Ce;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(fu),i=new Set(Eo),s=new Set(d1),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"&&Cn.includes(c)){let p=c,h=l.id.name;p!==h&&(a.set(h,p),l.id.name=p)}}})}),a.size>0&&Re(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 y1(t){try{let e=bo(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 g1(t){return t.async=!0,wo(t)}function _1(t){t=t.trim();let{isWrapped:e,isAsync:n,functionNode:r}=y1(t);return e&&r?n?t:g1(r):`async (context) => {\n${t}\n}`}function x1(t){Re(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 b1(t,e){bt(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,bt(t,{FunctionDeclaration(r){if(!r.id?.name)return;let i=r.id.name;if(e.getFunctionReturnType(i)||e.getFunctionReturnTupleType(i))return;let s=S1(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=>Mr(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=>Mr(l,e)),o=a[0];!o||!a.every(l=>l===o)||(e.setFunctionReturnType(i,o),n=!0)}});bt(t,{VariableDeclaration(r){for(let i of r.declarations)if(i.init){if(i.id?.type==="Identifier"){let s=Mr(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)}}}}),bt(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 v1=new Set(["table","line","label","box","linefill","polyline","array","matrix","map"]),w1={"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(v1.has(e)&&(n==="new"||n==="copy"||n==="from"||n.startsWith("new_")))return e;let r=w1[`${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 S1(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 Mr(t,e){if(t){if(t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&!t.callee.computed&&t.callee.object?.type==="Identifier"&&t.callee.property?.type==="Identifier"&&(t.callee.property.name==="new"||t.callee.property.name==="copy")&&e.isUdtTypeName(t.callee.object.name))return t.callee.object.name;if(t.type==="CallExpression"&&t.callee?.type==="Identifier"){let n=e.getFunctionReturnType(t.callee.name);if(n)return n}if(t.type==="ConditionalExpression"){let n=Mr(t.consequent,e),r=Mr(t.alternate,e);if(n&&n===r)return n}}}function E1(t,e){bt(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===Ce||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===Ce||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 C1(t,e,n=!1){t.params.forEach(r=>{r.type==="Identifier"&&n&&e.addContextBoundVar(r.name,n)})}function N1(t,e){let n;return hu(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=Ce),C1(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(p=>{p&&p.type==="Identifier"&&e.addReservedName(p.name)}),a)return;let l=e.generateTempVar(),c={type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:l},init:o.init,_tupleArity:o.id.elements.length}]};o.id.elements?.forEach(p=>{p.type==="Identifier"&&e.addArrayPatternElement(p.name)});let u=o.id.elements.map((p,h)=>({type:"VariableDeclaration",kind:r.kind,declarations:[{type:"VariableDeclarator",id:p,init:{type:"MemberExpression",object:{type:"Identifier",name:l},property:{type:"Literal",value:h},computed:!0}}]}));Object.assign(r,{type:"BlockStatement",body:[c,...u]})}})},ForStatement(r){}}),n}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,A1=(t,e,n)=>k1(t,typeof e!="symbol"?e+"":e,n),M1=new Set(["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]),T1=new Set(["input.int","math.floor","math.ceil","array.size","matrix.rows","matrix.columns","str.length","timestamp","ta.barssince","ta.highestbars","ta.lowestbars"]);function P1(t){return t&&t.type==="Literal"&&typeof t.value=="number"&&Number.isInteger(t.value)&&!(typeof t.raw=="string"&&/[.eE]/.test(t.raw))}function D1(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 R1(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 xa(t,e){return t!=="notint"&&e!=="notint"?"int":"notint"}var ba=class{constructor(){A1(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,xa(this.stack[r].get(e),n));return}this.stack[this.stack.length-1].set(e,xa(n,n))}};function O1(t,e){let n=new ba,r=R1(t);function i(a){if(!a||typeof a!="object")return"notint";switch(a.type){case"Literal":return typeof a.value=="number"&&P1(a)?"constint":"notint";case"Identifier":return M1.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=N.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 xa(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=D1(a.callee);return o&&T1.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 L1=new Set(["ArrowFunctionExpression","FunctionExpression","FunctionDeclaration"]),F1=new Set(["&&","||","??"]);function Bl(t){return t!==null&&typeof t=="object"&&typeof t.type=="string"}function B1(t){return t.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.type==="Identifier"&&t.callee.object.name==="request"}function At(t,e,n){if(Bl(t)){if(e&&(t._lazyOperand=!0),L1.has(t.type)){Array.isArray(t.params)&&t.params.forEach(r=>At(r,e,n)),At(t.body,!1,n);return}if(B1(t)){t._lazyOperand=!1,t.arguments.forEach(r=>At(r,!1,n));return}if(t.type==="ConditionalExpression"){At(t.test,e,n),At(t.consequent,!0,n),At(t.alternate,!0,n);return}if(t.type==="LogicalExpression"&&F1.has(t.operator)){if(n.lazyLogical){At(t.left,e,n),At(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=>At(s,e,n)):Bl(i)&&At(i,e,n)}}}function V1(t,e){At(t,!1,e)}var Oi={type:"Identifier",name:"undefined"};function Tr(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 Oe(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 Co(t,e){let n=Oe(t,e);return N.createGetCall(n,0)}function Fn(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=Oe(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=Oe(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=Oe(t.object.name,e)),t.property.type==="MemberExpression"){let n=t.property;n._indexTransformed||(Fn(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=Zt(t.property,e))}function Xe(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 De(t,e){if(!t._skipTransformation&&t.name!==Ce){if(Lt.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===Ce&&["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"&&Cn.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===Ce&&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=Oe(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=Oe(t.name,e)}if(a)Object.assign(t,p);else{let h=N.createGetCall(p,0);Object.assign(t,h)}}}function Ie(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||Me(t.object,n);let l=n.generateParamId(),c={type:"CallExpression",callee:N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("param")),arguments:[t.object,Oi,Tr(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"&&Cn.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||(Fn(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===Ce||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"&&Lt.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})():Oe(c,n);l.object=N.createGetCall(u,t.property);let p=t.object;Object.assign(t,p),delete t.computed;return}}}function Pr(t,e){if(t.type==="Identifier"){if(Lt.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?Oe(t.name,e):n===t.name&&!e.isContextBound(t.name)?t:Oe(t.name,e)}return t}function Zt(t,e,n=""){switch(t.type){case"BinaryExpression":return di(t,e,n);case"LogicalExpression":return fi(t,e,n);case"MemberExpression":{let r=!t.computed&&t.object.type==="Identifier"&&Lt.includes(t.object.name)&&e.isContextBound(t.object.name);if(t.computed&&t.object.type==="Identifier"&&Lt.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,t.property)}let i=t.object.type==="Identifier"&&!r?Pr(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=Pr(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 mi(t,e,n);case"ConditionalExpression":{let r=Zt(t.test,e,n),i=Zt(t.consequent,e,n),s=Zt(t.alternate,e,n);return{type:"ConditionalExpression",test:r,consequent:i,alternate:s,start:t.start,end:t.end}}}return t}function di(t,e,n){let r=Zt(t.left,e,n),i=Zt(t.right,e,n),s={type:"BinaryExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return Re(s,e,{CallExpression(a,o){a._transformed||Me(a,o)},MemberExpression(a){Ie(a,"",e)}}),s}function fi(t,e,n){let r=Zt(t.left,e,n),i=Zt(t.right,e,n),s={type:"LogicalExpression",operator:t.operator,left:r,right:i,start:t.start,end:t.end};return Re(s,e,{CallExpression(a,o){a._transformed||Me(a,o)}}),s}function Ts(t,e,n){Re(t,{parent:t,inNamespaceCall:!1},{Identifier(a,o,l){if(a.name=="NaN")return;if(Lt.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=N.createGetCall(u,0);Object.assign(a,p),delete a.name;return}a.parent=o.parent,De(a,e);let c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?Fn(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===Ce&&a.parent.callee.property.name==="get"||Xe(a)))},MemberExpression(a,o,l){Ie(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);Me(a,e),!(a.type!=="CallExpression"||No(a))&&a.arguments.forEach(u=>l(u,{parent:a,inNamespaceCall:c||o.inNamespaceCall}))}});let r=N.createMemberExpression(N.createIdentifier(n),N.createIdentifier("param")),i=e.generateParamId(),s={type:"CallExpression",callee:r,arguments:[t,Oi,Tr(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 mi(t,e,n){let r=Zt(t.argument,e,n),i={type:"UnaryExpression",operator:t.operator,prefix:t.prefix,argument:r,start:t.start,end:t.end};return Re(i,e,{CallExpression(s,a){s._transformed||Me(s,a)},MemberExpression(s){Ie(s,"",e)}}),i}function Vl(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)&&!Lt.includes(r.name)&&!Cn.includes(r.name)&&(n.object=Co(r.name,e));break}n=n.object}}function nr(t,e,n){switch(t?.type){case"BinaryExpression":t=di(t,n,e);break;case"LogicalExpression":t=fi(t,n,e);break;case"ConditionalExpression":return Ts(t,n,e);case"UnaryExpression":t=mi(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=N.createIdentifier(c.name);return N.createGetCall(u,0)}return Co(c.name,n)}return c.type==="CallExpression"?(Me(c,n),c):c.type==="BinaryExpression"?di(c,n,e):c.type==="LogicalExpression"?fi(c,n,e):c.type==="ConditionalExpression"?Ts(c,n,e):c.type==="UnaryExpression"?mi(c,n,e):(c.type==="MemberExpression"&&(Ie(c,e,n),c.computed||Vl(c,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,x=n.isLocalSeriesVar(m)?(()=>{let b=N.createIdentifier(m);return b._skipTransformation=!0,b})():Oe(m,n);return f.object=N.createGetCall(x,t.property),t.object}}t.object.type==="CallExpression"?Me(t.object,n):t.object.type==="MemberExpression"?(Ie(t.object,"",n),Vl(t.object,n)):t.object.type==="BinaryExpression"?t.object=di(t.object,n,e):t.object.type==="LogicalExpression"?t.object=fi(t.object,n,e):t.object.type==="ConditionalExpression"?t.object=Ts(t.object,n,e):t.object.type==="UnaryExpression"&&(t.object=mi(t.object,n,e));let c=t.object.type==="Identifier"&&n.isContextBound(t.object.name)&&!n.isRootParam(t.object.name)?t.object:Pr(t.object,n),u;t.property.type==="Identifier"&&!n.isContextBound(t.property.name)&&!n.isLoopVariable(t.property.name)?u=N.createGetCall(Pr(t.property,n),0):t.property.type==="BinaryExpression"||t.property.type==="UnaryExpression"||t.property.type==="LogicalExpression"||t.property.type==="ConditionalExpression"?u=Zt(t.property,n,e):u=t.property;let p=N.createMemberExpression(N.createIdentifier(e),N.createIdentifier("param")),h=n.generateParamId(),d={type:"CallExpression",callee:p,arguments:[c,u,Tr(n,h)],_transformed:!0,_isParamCall:!0};if(!n.shouldSuppressHoisting()){let f=h;n.addLocalSeriesVar(f);let m=N.createVariableDeclaration(f,d);return n.addHoistedStatement(m),N.createIdentifier(f)}return d}if(i){if(t.object.type==="Identifier"&&Cn.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=Oe(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"?nr(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=>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:N.createIdentifier(c.value.name),kind:"init",method:!1,shorthand:!1,computed:!1}:{type:"Property",key:{type:"Identifier",name:c.key.name},value:Oe(c.value.name,n),kind:"init",method:!1,shorthand:!1,computed:!1}:(c.value.type!=="Literal"&&(c.value=nr(c.value,e,n)),c))),t.type==="Identifier"){if(Lt.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,Oi,Tr(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"?Pr(t,n):t,o=n.generateParamId(),l={type:"CallExpression",callee:s,arguments:[a,Oi,Tr(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 vr(t){if(!t)return!1;if(mu(t))return!0;if(t.type==="MemberExpression")return vr(t.object);if(t.type==="ChainExpression")return vr(t.expression);if(t.type==="CallExpression"){let e=t.callee;if(e?.type==="MemberExpression")return vr(e.object);if(e?.type==="ChainExpression")return vr(e.expression)}return!1}function $1(t,e){if(t?._orderflowType)return t._orderflowType;if(t?.type!=="CallExpression"||t.callee?.type!=="MemberExpression"||t.callee.computed||!du.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 mu(t){return t?.type==="CallExpression"&&t.callee?.type==="MemberExpression"&&t.callee.object?.name==="$"&&t.callee.property?.name==="get"}function va(t,e,n){t&&(t.type==="Identifier"?(t.parent=e,De(t,n)):t.type==="MemberExpression"?va(t.object,t,n):t.type==="CallExpression"&&(t.callee&&t.callee.type==="MemberExpression"&&va(t.callee.object,t.callee,n),t._transformed||Me(t,n)))}function No(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{$l(t,e,n)}finally{e.setSuppressHoisting(!1)}return}$l(t,e)}}function $l(t,e,n){t.callee&&t.callee.name,t.callee&&t.callee.type==="Identifier"&&(Cn.includes(t.callee.name)||Lt.includes(t.callee.name))&&e.isContextBound(t.callee.name)&&(t.callee=N.createMemberExpression(t.callee,N.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===Ce&&["get","init","param"].includes(t.callee.property.name))return;let s=t.callee.object.name,a=[];t.arguments.forEach(d=>{if(d._isParamCall){a.push(d);return}a.push(nr(d,s,e))}),t.arguments=a;let o=t.callee.property.name,l=`${s}.${o}`;if(Fl.includes(s)||Fl.includes(l)){let d=e.getNextPlotCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:d,kind:"init",computed:!1,shorthand:!1}]})}if(s==="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}]}),s==="alert"){let d=e.getNextAlertCallId();t.arguments.push({type:"ObjectExpression",properties:[{type:"Property",key:{type:"Identifier",name:"__callsiteId"},value:d,kind:"init",computed:!1,shorthand:!1}]})}if(s==="ta")if(e.getCurrentScopeType()==="fn"){let d=e.getNextTACallId(),[f]=e.getVariable("$$"),m;f?m=N.createMemberExpression(N.createLocalContextIdentifier(),N.createIdentifier("id")):m=N.createLiteral("");let x={type:"BinaryExpression",operator:"+",left:m,right:d};t.arguments.push(x)}else t.arguments.push(e.getNextTACallId());let c=t.callee.property.name,u=`${s}.${c}`,p=l1.includes(u),h=t._insideAwait===!0;if(p&&!h){let d=Object.assign({},t),f=N.createAwaitExpression(d);Object.assign(t,f)}if(!e.shouldSuppressHoisting()){let d=e.generateTempVar();e.addLocalSeriesVar(d);let f=t._insideAwait===!0,m=Object.assign({},t);f&&(m=N.createAwaitExpression(m));let x=N.createVariableDeclaration(d,m);e.addHoistedStatement(x);let b=N.createIdentifier(d);Object.assign(t,b),t._wasHoisted=!0,t._wasInsideAwait=f;return}t._transformed=!0}else if(t.callee&&t.callee.type==="Identifier"){if(t.arguments=t.arguments.map(s=>s._isParamCall?s:nr(s,Ce,e)),!e.isContextBound(t.callee.name)){let s=e.getNextUserCallId(),a=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("call")),o=t.callee.name,l=t.callee;e.isUserMethod(o)&&!e.isRegularUserFunction(o)&&(l=N.createIdentifier(`$M_${o}`),l._skipTransformation=!0);let c=[l,s,...t.arguments];t.callee=a,t.arguments=c}t._transformed=!0}let i;if(!r&&t.callee&&t.callee.type==="MemberExpression"){let s=t.callee.property.name,a=e.isUserFunction(s),o=t.callee.object,l=e.isUserMethod(s),c;if(o.name)c=e.getVariableUdtType(o.name)??e.getVarStaticType(o.name);else if(o.type==="MemberExpression"&&!o.computed&&o.property?.type==="Identifier"&&o.object?.name){let m=e.getVariableUdtType(o.object.name);if(m){let x=e.getUdtTypeFields(m)?.[o.property.name];c=ya(x)}}let u=e.getMethodReceiverType(s),p=!!c&&!!u&&c===u,h=c??$1(o,e);h&&p1[h]?.has(s)&&(i=h);let d=!!o.name&&e.isUdtInstance(o.name),f=c===void 0&&!h1.has(s);if(a&&l&&!e.isContextBound(s)&&(p||d||f)){let m=t.callee.object;t.callee.property;let x=t.arguments.map(C=>C._isParamCall?C:nr(C,Ce,e));m.type==="CallExpression"&&Me(m,e);let b=nr(m,Ce,e),v=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("call")),E=e.getNextUserCallId(),w=N.createIdentifier(`$M_${s}`);w._skipTransformation=!0;let S=[w,E,b,...x];t.callee=v,t.arguments=S,t._transformed=!0;return}t.callee.object.type==="Identifier"?De(t.callee.object,e):va(t.callee.object,t.callee,e)}if(t.arguments.forEach(s=>{Re(s,{parent:t},{Identifier(a,o,l){a.parent=o.parent,De(a,e);let c=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||c)&&(a.type==="MemberExpression"?Fn(a,e):a.type==="Identifier"&&(a.parent&&a.parent.type==="CallExpression"&&a.parent.callee&&a.parent.callee.object&&a.parent.callee.object.name===Ce&&a.parent.callee.property.name==="get"||Xe(a)))},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){a.callee&&a.callee.type==="MemberExpression"&&a.callee.object&&(a.callee.object.parent=a.callee,l(a.callee.object,{parent:a.callee})),a._transformed||Me(a,e)},MemberExpression(a,o,l){Ie(a,"",e),a.object&&l(a.object,{parent:a})}})}),i&&!t._transformed){let s=t.callee.property.name,a=N.createMemberExpression(N.createContextIdentifier(),N.createIdentifier("pine")),o=N.createMemberExpression(a,N.createIdentifier(i));t.arguments=[t.callee.object,...t.arguments],t.callee=N.createMemberExpression(o,N.createIdentifier(s)),i==="footprint"&&du.has(s)&&(t._orderflowType="volume_row"),t._transformed=!0;return}if(t.callee&&t.callee.type==="MemberExpression"){let s=t.callee.object,a=mu(s),o=s?.type==="MemberExpression"&&vr(s);if(a||o){let l=Object.assign({},t.callee,{optional:!0});t.callee={type:"ChainExpression",expression:l},t.optional=!0}}}function Io(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 Li(t,e){let n=null;if(t.left.type==="Identifier")n=Oe(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=Oe(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=Oe(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(Re(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(Lt.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},x=N.createGetCall(m,0);Object.assign(r,x),delete r.name;return}r.parent=i.parent,De(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===Ce&&r.parent.callee.property.name==="get";(c||l||o)&&(r.type==="MemberExpression"?Fn(r,e):r.type==="Identifier"&&!h&&!u&&!p&&!d&&!f&&Xe(r))},MemberExpression(r,i,s){Ie(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"||No(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 yu(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"&&Lt.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===Ce||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===Ce||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=Ce;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=Ce;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):Re(n.init,{parent:n.init},{Identifier(h,d){h.parent=d.parent,De(h,e);let f=h.parent&&h.parent.type==="BinaryExpression",m=h.parent&&h.parent.type==="UnaryExpression",x=h.parent&&h.parent.type==="ConditionalExpression",b=h.parent&&h.parent.type==="CallExpression"&&h.parent.callee&&h.parent.callee.object&&h.parent.callee.object.name===Ce&&h.parent.callee.property.name==="get";h.type==="Identifier"&&(f||m||x)&&!b&&Xe(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"||No(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),Ie(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(x=>{e.enterHoistingScope(),f(x,{parent:h.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),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(x=>{e.enterHoistingScope(),f(x,{parent:h.body,insideIIFE:!0});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),h.body.body=m}},BlockStatement(h,d,f){let m=[];h.body.forEach(x=>{e.enterHoistingScope(),f(x,{...d,parent:h});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),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(x=>{e.enterHoistingScope(),x.parent=h,f(x,{parent:h});let b=e.exitHoistingScope();m.push(...b),m.push(x)}),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}}Li(h,e)}}}));let l=Oe(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||(Fn(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,b=m.property?.name;if(m.object?.type==="Identifier"?x=m.object.name:m.object?.type==="MemberExpression"&&m.object.property?.name&&(x=m.object.property.name),x&&b){let v=`${x}.${b}`;u1.includes(v)&&(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=Oe(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"),Re(n.init.body,e,{IfStatement(h,d,f){d.pushScope("if"),h.test&&gu(h.test,d),f(h.consequent,d),h.alternate&&(d.pushScope("els"),f(h.alternate,d),d.popScope()),d.popScope()},VariableDeclaration(h,d){yu(h,d)},Identifier(h,d){De(h,d)},AssignmentExpression(h,d){Li(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(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),h.consequent=m},BlockStatement(h,d,f){let m=[];h.body.forEach(x=>{d.enterHoistingScope(),f(x,d);let b=d.exitHoistingScope();m.push(...b),m.push(x)}),h.body=m}}),e.popScope()),Object.assign(t,p)})}function W1(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&&Re(s.init,e,{Identifier(o,l){!e.isLoopVariable(o.name)&&!o.computed&&(e.pushScope("for"),De(o,l),o.type==="Identifier"&&(e.isContextBound(o.name)&&o.parent&&o.parent.type==="MemberExpression"&&o.parent.object===o||(o.computed=!0,Xe(o))),e.popScope())},MemberExpression(o,l,c){e.pushScope("for"),Ie(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&&Re(t.test,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),De(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Xe(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),Ie(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&&Re(t.update,e,{Identifier(s,a){!e.isLoopVariable(s.name)&&!s.computed&&(e.pushScope("for"),De(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Xe(s))),e.popScope())},MemberExpression(s,a,o){e.pushScope("for"),Ie(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=Io(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 j1(t,e,n){e.setSuppressHoisting(!0),t.test&&Re(t.test,e,{Identifier(s,a){s.computed||(De(s,a),s.type==="Identifier"&&(e.isContextBound(s.name)&&s.parent&&s.parent.type==="MemberExpression"&&s.parent.object===s||(s.computed=!0,Xe(s))))},MemberExpression(s,a,o){Ie(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),Me(s,a),s.arguments)for(let l of s.arguments)o(l,a)}}),e.setSuppressHoisting(!1);let r=e.getNextLoopGuardName(),i=Io(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 gu(t,e){Re(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)),Ie(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";De(n,r),n.type==="Identifier"&&(s||a||o||l)&&(i&&i.type==="CallExpression"&&i.callee&&i.callee.object&&i.callee.object.name===Ce&&i.callee.property?.name==="get"||Xe(n));let c=e.getCurrentScopeType()==="if";e.isContextBound(n.name)&&!e.isRootParam(n.name)&&c&&Xe(n)}})}function U1(t,e,n){t.test&&(e.pushScope("if"),gu(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 q1(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 Co(r.name,e)}else{if(r.type==="MemberExpression")return 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)?N.createGetCall(r,0):(Ie(r,"",e),r);if(r.type==="BinaryExpression"||r.type==="LogicalExpression"||r.type==="ConditionalExpression"||r.type==="CallExpression"||r.type==="UnaryExpression")return Re(r,e,{Identifier(i,s){De(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Xe(i),i._arrayAccessed=!0)},MemberExpression(i){Ie(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:Oe(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=Oe(r.value.name,e))),r));else if(t.argument.type==="Identifier")De(t.argument,e),t.argument.type==="Identifier"&&Xe(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)))De(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)&&Ie(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&&t.argument.object.type==="CallExpression"?Ie(t.argument,"",e):t.argument.object.type==="Identifier"&&e.isContextBound(t.argument.object.name)&&!e.isRootParam(t.argument.object.name)?t.argument.computed?Ie(t.argument,"",e):t.argument._indexTransformed||(Fn(t.argument,e),t.argument._indexTransformed=!0):t.argument.computed&&t.argument.object.type==="Identifier"&&e.isLocalSeriesVar(t.argument.object.name)&&Ie(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")&&Re(t.argument,e,{Identifier(i,s){De(i,s),i.type==="Identifier"&&!i._arrayAccessed&&(Xe(i),i._arrayAccessed=!0)},MemberExpression(i){Ie(i,"",e)},AssignmentExpression(i,s){Li(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 z1(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 H1(t){let e={...D,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;bt(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 bt(o,{AwaitExpression(){l=!0}},c),l}let s=!0,a=0;for(;s&&a<20;){s=!1,a++,bt(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=[];bt(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=[];bt(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 K1={"==":"__eq","===":"__eq","!=":"__neq","!==":"__neq","<":"__lt","<=":"__le",">":"__gt",">=":"__ge"},Y1=new Set(["<","<=",">",">="]);function G1(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 X1(t){let e={...D,LineComment:()=>{}};hu(t,{BinaryExpression(n,r,i){let s=K1[n.operator];if(!s||Y1.has(n.operator)&&G1(n,i))return;let a=N.createMathCompareCall(s,n.left,n.right);a._transformed=!0,Object.assign(n,a)}},e)}var Z1={"&&":"__and","||":"__or"};function Q1(t){let e={...D,LineComment:()=>{}};bt(t,{LogicalExpression(n){if(!n._strictLogical)return;let r=Z1[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 J1={"+":"__union","-":"__minus"};function Wl(t){return t?.type==="MemberExpression"&&!t.computed&&t.object?.type==="Identifier"&&t.object.name==="display"?!0:t?.type==="CallExpression"&&t._displaySetOp===!0}function ev(t){let e={...D,LineComment:()=>{}};bt(t,{BinaryExpression(n){let r=J1[n.operator];if(!r||!Wl(n.left)&&!Wl(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 tv(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};Re(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),q1(a,o)},VariableDeclaration(a,o){yu(a,o)},Identifier(a,o){De(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"?(De(a.right,o),a.right.type==="Identifier"&&Xe(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=Io(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"?(De(a.right,o),a.right.type==="Identifier"&&Xe(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)),Ie(a,n,o)},AssignmentExpression(a,o,l){if(Li(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){z1(a,o,l)},ForStatement(a,o,l){W1(a,o,l)},WhileStatement(a,o,l){j1(a,o,l)},IfStatement(a,o,l){U1(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 nv=Object.defineProperty,rv=(t,e,n)=>e in t?nv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ps=(t,e,n)=>rv(t,typeof e!="symbol"?e+"":e,n),_={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"},iv=new Set(["if","else","for","while","switch","break","continue","var","varip","type","and","or","not","to","by","in","as","import","export","method","enum"]),sv=new Set(["type","method","enum"]),jl=new Set(["catch","class","do","ellipse","is","polygon","range","return","struct","text","throw","try"]),av=["==","!=","<=",">=",":=","+=","-=","*=","/=","%=","=>","//","and","or","not"],wa=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,Ps(this,"wrapped",null),Ps(this,"grouped",!1),Ps(this,"startColumn")}},ov=Object.defineProperty,lv=(t,e,n)=>e in t?ov(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,yt=(t,e,n)=>lv(t,typeof e!="symbol"?e+"":e,n),_u=class wr{constructor(e){yt(this,"source"),yt(this,"pos"),yt(this,"line"),yt(this,"column"),yt(this,"tokens"),yt(this,"indentStack"),yt(this,"atLineStart"),yt(this,"parenDepth"),yt(this,"bracketDepth"),yt(this,"braceDepth"),yt(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(_.DEDENT,"",this.getCurrentIndent());return this.addToken(_.EOF,""),this.resolveContextualKeywords(),this.tokens}resolveContextualKeywords(){let e=r=>r.type===_.NEWLINE||r.type===_.INDENT||r.type===_.DEDENT||r.type===_.COMMENT,n=r=>!!r&&(r.type===_.IDENTIFIER||r.type===_.KEYWORD);for(let r=0;r<this.tokens.length;r++){let i=this.tokens[r];if(i.type!==_.KEYWORD||!sv.has(i.value))continue;let s=r-1;for(;s>=0&&this.tokens[s].type===_.COMMENT;)s--;let a=s>=0?this.tokens[s]:null;!i.wrapped&&(a===null||e(a)||a.type===_.KEYWORD&&a.value==="export")&&n(this.tokens[r+1])||(i.type=_.IDENTIFIER)}}handleNewline(){this.parenDepth===0&&this.bracketDepth===0&&this.braceDepth===0&&(this.addToken(_.NEWLINE,`\n`),this.atLineStart=!0),this.advance(),this.line++,this.column=1}handleIndentation(){let e=0;for(;this.pos<this.source.length;){let i=this.peek();if(i===" ")e+=1,this.advance();else if(i===" ")e+=wr.TAB_WIDTH,this.advance();else break}if(this.peek()===`\n`||this.peek()==="\\r"||this.peek()==="\\0"||this.peek()==="/"&&this.peek(1)==="/")return;if(e%wr.TAB_WIDTH!==0||this.isContinuationFromPrevToken()){this.joinWithPreviousLine(e);return}let n=e/wr.TAB_WIDTH,r=this.indentStack[this.indentStack.length-1];if(n>r){if(n>r+1){let i=(r+1)*wr.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(_.INDENT,"",n)}else if(n<r){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>n;)this.indentStack.pop(),this.addToken(_.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!==_.NEWLINE&&r.type!==_.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===_.NEWLINE||n.type===_.COMMENT))return n.type===_.OPERATOR?n.value!=="=>":n.type===_.COMMA||n.type===_.COLON||n.type===_.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(_.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(_.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(_.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(_.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(_.NUMBER,parseFloat(e),null,e)}readIdentifier(){this.column;let e="";for(;this.pos<this.source.length&&this.isIdentifierChar(this.peek());)e+=this.advance();iv.has(e)?this.addToken(_.KEYWORD,e):e==="true"||e==="false"?this.addToken(_.BOOLEAN,e==="true"):this.addToken(_.IDENTIFIER,e)}readOperatorOrPunctuation(){let e=this.peek(),n=this.peek(1),r=e+n;if(av.includes(r))return this.advance(),this.advance(),this.addToken(_.OPERATOR,r),!0;if("+-*/%<>=!?".includes(e))return this.advance(),this.addToken(_.OPERATOR,e),!0;switch(e){case"(":return this.parenDepth++,this.advance(),this.addToken(_.LPAREN,e),!0;case")":return this.parenDepth--,this.advance(),this.addToken(_.RPAREN,e),!0;case"[":{let i=this.parenDepth>0||this.bracketDepth>0||this.braceDepth>0;return this.bracketDepth++,this.advance(),this.addToken(_.LBRACKET,e),this.tokens[this.tokens.length-1].grouped=i,!0}case"]":return this.bracketDepth--,this.advance(),this.addToken(_.RBRACKET,e),!0;case"{":return this.braceDepth++,this.advance(),this.addToken(_.LBRACE,e),!0;case"}":return this.braceDepth--,this.advance(),this.addToken(_.RBRACE,e),!0;case",":return this.advance(),this.addToken(_.COMMA,e),!0;case".":return this.isDigit(this.peek(1))?(this.readNumber(),!0):(this.advance(),this.addToken(_.DOT,e),!0);case":":return this.advance(),this.addToken(_.COLON,e),!0;case";":return this.advance(),this.addToken(_.SEMICOLON,e),!0}return!1}peek(e=0){let 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 wa(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)}};yt(_u,"TAB_WIDTH",4);var cv=_u,uv=Object.defineProperty,hv=(t,e,n)=>e in t?uv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ht=(t,e,n)=>hv(t,typeof e!="symbol"?e+"":e,n),pe=class{constructor(e){this.type=e}},Sa=class extends pe{constructor(e){super("Program"),this.body=e}},Ke=class extends pe{constructor(e){super("ExpressionStatement"),this.expression=e}},Wt=(t=>(t.VAR="var",t.LET="let",t.CONST="const",t))(Wt||{}),gt=class extends pe{constructor(e,n="let"){super("VariableDeclaration"),this.declarations=e,this.kind=n}},ut=class extends pe{constructor(e,n,r=null){super("VariableDeclarator"),this.id=e,this.init=n,this.varType=r}},Fi=class extends pe{constructor(e,n,r,i=null){super("FunctionDeclaration"),this.id=e,this.params=n,this.body=r,this.returnType=i}},Ea=class extends pe{constructor(e,n){super("TypeDefinition"),this.name=e,this.fields=n}},Ca=class extends pe{constructor(e,n,r=null){super("IfStatement"),this.test=e,this.consequent=n,this.alternate=r,ht(this,"_line")}},Bi=class extends pe{constructor(e,n,r,i){super("ForStatement"),this.init=e,this.test=n,this.update=r,this.body=i,ht(this,"isForIn")}},Na=class extends pe{constructor(e,n){super("WhileStatement"),this.test=e,this.body=n}},zt=class extends pe{constructor(e){super("BlockStatement"),this.body=e}},Vi=class extends pe{constructor(e){super("ReturnStatement"),this.argument=e}},me=class extends pe{constructor(e){super("Identifier"),this.name=e,ht(this,"varType"),ht(this,"returnType"),ht(this,"isMethod")}},_t=class extends pe{constructor(e,n=null){super("Literal"),this.value=e,this.raw=n}},Mt=class extends pe{constructor(e,n,r){super("BinaryExpression"),this.operator=e,this.left=n,this.right=r}},$i=class extends pe{constructor(e,n,r=!0){super("UnaryExpression"),this.operator=e,this.argument=n,this.prefix=r}},fn=class extends pe{constructor(e,n,r){super("AssignmentExpression"),this.operator=e,this.left=n,this.right=r}},Wi=class extends pe{constructor(e,n,r=!1){super("UpdateExpression"),this.operator=e,this.argument=n,this.prefix=r}},Ia=class extends pe{constructor(e,n){super("CallExpression"),this.callee=e,this.args=n,ht(this,"arguments"),this.callee=e,this.arguments=n}},ji=class extends pe{constructor(e,n,r=!1){super("MemberExpression"),this.object=e,this.property=n,this.computed=r}},Ht=class extends pe{constructor(e,n,r){super("ConditionalExpression"),this.test=e,this.consequent=n,this.alternate=r,ht(this,"needsIIFE"),ht(this,"consequentStmts"),ht(this,"alternateStmts")}},ka=class extends pe{constructor(e){super("ArrayExpression"),this.elements=e}},Wr=class extends pe{constructor(e){super("ObjectExpression"),this.properties=e}},or=class extends pe{constructor(e,n){super("Property"),this.key=e,this.value=n,ht(this,"kind"),ht(this,"method"),ht(this,"shorthand"),ht(this,"computed"),this.kind="init",this.method=!1,this.shorthand=!1,this.computed=!1}},Ui=class extends pe{constructor(e){super("ArrayPattern"),this.elements=e}},qi=class extends pe{constructor(e,n){super("AssignmentPattern"),this.left=e,this.right=n}},Aa=class extends pe{constructor(e,n){super("SwitchExpression"),this.discriminant=e,this.cases=n}},Ma=class extends pe{constructor(e,n,r){super("SwitchCase"),this.test=e,this.consequent=n,this.statements=r,this.statements=r}},pv=Object.defineProperty,dv=(t,e,n)=>e in t?pv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,jt=(t,e,n)=>dv(t,typeof e!="symbol"?e+"":e,n),xu=class bu{constructor(e){jt(this,"tokens"),jt(this,"pos"),jt(this,"functionNames",new Set),jt(this,"typeNames",new Set),jt(this,"paramScopes",[]),jt(this,"loopValueCounter",0),jt(this,"functionTupleArity",new Map),jt(this,"functionParamNames",new Map),jt(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===_.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===_.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!==_.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===_.DEDENT;)n--;if(n<0)return!0;let r=this.tokens[n];return r.type===_.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===_.KEYWORD||e.type===_.IDENTIFIER&&jl.has(e.value)}expectName(){let e=this.peek();if(this.isReservedName(e))throw this.reservedNameError(e);if(e.type!==_.IDENTIFIER)throw new Error(`Expected ${_.IDENTIFIER} but got ${e.type} at ${e.line}:${e.column}`);return this.advance()}assertDeclarableName(e,n){if(e?.type==="Identifier"&&jl.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===_.OPERATOR&&n.value==="=")throw this.reservedNameError(e)}isNameSlot(e){return e.type===_.IDENTIFIER?!0:e.type===_.KEYWORD&&!bu.STATEMENT_KEYWORDS.has(e.value)}peekOperatorEx(e){let n=this.peek();return n.type!==_.OPERATOR||!e.includes(n.value)?null:n.value}isLayoutToken(){return this.match(_.NEWLINE)||this.match(_.COMMENT)}skipNewlines(e=!1){for(;this.isLayoutToken();)this.advance();e&&this.match(_.INDENT)&&this.advance()}parse(){let e=[];for(this.collectTopLevelFunctionNames();!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){this.advance();continue}if(this.match(_.EOF))break;let n=this.parseStatement();n&&e.push(n),this.skipNewlines()}return new Sa(e)}collectTopLevelFunctionNames(){let e=0;for(let n=0;n<this.tokens.length;n++){let r=this.tokens[n];r.type===_.INDENT?e++:r.type===_.DEDENT&&e--;let i=n===0||this.tokens[n-1].type===_.NEWLINE||this.tokens[n-1].type===_.DEDENT;if(e===0&&r.type===_.KEYWORD&&r.value==="type"&&n+1<this.tokens.length){let a=this.tokens[n-1];(i||a?.type===_.KEYWORD&&a.value==="export")&&this.typeNames.add(this.tokens[n+1].value)}if(e!==0||!i||r.type!==_.IDENTIFIER||(this.pos=n,!this.isFunctionDeclaration()))continue;let s=this.peek(1).type!==_.LPAREN;this.functionNames.add(this.peek(s?1:0).value)}this.pos=0}parseStatement(e=!0){this.skipNewlines();let n=this.peek().line;if(this.match(_.COMMENT))return this.advance(),null;let r;if(this.match(_.KEYWORD,"enum"))r=this.parseEnumDefinition();else if(this.match(_.KEYWORD,"type"))r=this.parseTypeDefinition();else if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))r=this.parseVarDeclaration();else if(this.match(_.KEYWORD,"method"))r=this.parseMethodDeclaration();else if(this.isFunctionDeclaration())r=this.parseFunctionDeclaration();else if(this.match(_.KEYWORD,"if"))r=this.parseIfStatement();else if(this.match(_.KEYWORD,"for"))r=this.parseForStatement();else if(this.match(_.KEYWORD,"while"))r=this.parseWhileStatement();else if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let i=this.advance().value;r=new Ke(new me(i))}else this.isTupleDestructuring()?r=this.parseTupleDestructuring():this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()&&(r=this.parseTypedVarDeclaration());if(!r){this.rejectReservedAssignmentTarget();let i=this.peek(),s=this.parseExpression();if(this.match(_.OPERATOR)){let a=this.peek().value;if(["=",":=","+=","-=","*=","/=","%="].includes(a)){this.advance(),this.skipNewlines(!0);let o=this.parseExpression();a==="="&&s.type==="Identifier"?(this.assertDeclarableName(s,i),this.assertNotTupleAssignment(s,o,i),r=new gt([new ut(s,o)],Wt.LET)):r=new Ke(new fn(a===":="?"=":a,s,o))}else r=new Ke(s)}else r=new Ke(s)}if(r&&(r._line=n,e&&this.match(_.COMMA))){let i=[r];for(;this.match(_.COMMA);){this.advance(),this.skipNewlines(!0);let a=this.parseStatement(!1);a&&i.push(a)}this.rejectDanglingWrappedLine();let s=new zt(i);return s._sequence=!0,s}return this.rejectDanglingWrappedLine(),r}isFunctionDeclaration(){let e=this.pos;try{let n=0;if(this.peek(n).type===_.IDENTIFIER&&this.isNameSlot(this.peek(n+1))&&n++,!this.isNameSlot(this.peek(n))||(n++,this.peek(n).type!==_.LPAREN))return!1;n++;let r=1;for(;r>0&&this.peek(n).type!==_.EOF;)this.peek(n).type===_.LPAREN&&r++,this.peek(n).type===_.RPAREN&&r--,n++;return this.peek(n).type===_.OPERATOR&&this.peek(n).value==="=>"}finally{this.pos=e}}parseTypeExpression(){let e=this.expect(_.IDENTIFIER).value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.OPERATOR,"<")){this.advance();let n=[];for(n.push(this.parseTypeExpression());this.match(_.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseTypeExpression());return this.expect(_.OPERATOR,">"),e+"<"+n.join(", ")+">"}return this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET?(this.advance(),this.advance(),"array<"+e+">"):e}parseEnumDefinition(){this.expect(_.KEYWORD,"enum");let e=this.expectName().value;this.skipNewlines(),this.expect(_.INDENT);let n=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){if(this.match(_.COMMENT)){this.advance();continue}let s=this.expectName().value,a=null;this.match(_.OPERATOR,"=")&&(this.advance(),a=this.expect(_.STRING).value),n.push({name:s,title:a}),this.skipNewlines()}this.match(_.DEDENT)&&this.advance();let r=n.map(s=>new or(new me(s.name),new _t(s.title!==null?s.title:s.name))),i=new Wr(r);return new gt([new ut(new me(e),i)],Wt.CONST)}parseTypeDefinition(){this.expect(_.KEYWORD,"type");let e=this.expectName().value;this.match(_.OPERATOR,"=>")&&this.advance(),this.skipNewlines(),this.expect(_.INDENT);let n=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){this.match(_.KEYWORD,"varip")&&this.advance();let r=this.parseTypeExpression(),i=this.expectName().value,s=null;this.match(_.OPERATOR,"=")&&(this.advance(),this.skipNewlines(),s=this.parseExpression()),n.push({type:r,name:i,defaultValue:s}),this.skipNewlines()}return this.match(_.DEDENT)&&this.advance(),new Ea(e,n)}parseVarDeclaration(){let e=this.advance(),n=e.value,r=null,i=null;if(this.peek().type===_.IDENTIFIER&&["const","simple","series"].includes(this.peek().value)&&this.peek(1).type===_.IDENTIFIER&&this.advance(),this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET)r=this.advance().value,this.advance(),r+="[]",this.advance(),i=this.expectName().value;else if(this.peek().type===_.IDENTIFIER&&(this.peek(1).type===_.DOT||this.isNameSlot(this.peek(1))||this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<")){for(r=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),r+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),r+="[]",i=this.expectName().value;else if(this.match(_.OPERATOR,"<")){for(this.advance(),r+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(r+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)r+=".",this.advance(),r+=this.advance().value;else if(this.match(_.COMMA))r+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(r+=">",this.advance()),i=this.expectName().value}else i=this.expectName().value}else if(this.isNameSlot(this.peek()))i=this.expectName().value;else throw this.match(_.OPERATOR,"=")||this.match(_.LPAREN)?this.reservedNameError(e):new Error(`Expected identifier after ${n} at ${this.peek().line}:${this.peek().column}`);this.functionNames.has(i)&&(i=i+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let s=this.parseExpression(),a=new me(i);r&&(a.varType=r);let o=[new ut(a,s,r)];for(;this.match(_.COMMA)&&this.peek(1).type===_.KEYWORD&&(this.peek(1).value==="var"||this.peek(1).value==="varip");){this.advance();let l=this.parseVarDeclaration();o.push(...l.declarations)}return new gt(o,n)}isTypedVarDeclaration(){let e=0;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++;this.peek(e).type===_.DOT&&this.peek(e+1).type===_.IDENTIFIER;)e+=2;if(this.peek(e).type===_.LBRACKET&&this.peek(e+1).type===_.RBRACKET)return e+=2,this.isNameSlot(this.peek(e))?(e++,this.peek(e).type===_.OPERATOR&&this.peek(e).value==="="):!1;if(this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"){e++;let n=1;for(;n>0&&this.peek(e).type!==_.EOF;)this.peek(e).type===_.OPERATOR&&this.peek(e).value==="<"?n++:this.peek(e).type===_.OPERATOR&&this.peek(e).value===">"&&n--,e++;return this.isNameSlot(this.peek(e))?(e++,this.peek(e).type===_.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===_.OPERATOR&&this.peek(e).value==="="}parseTypedVarDeclaration(){let e=this.advance().value;for(;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)this.advance(),e+="."+this.advance().value;if(this.match(_.LBRACKET)&&this.peek(1).type===_.RBRACKET)this.advance(),this.advance(),e+="[]";else if(this.match(_.OPERATOR,"<")){for(this.advance(),e+="<";!this.match(_.OPERATOR,">");)if(this.match(_.IDENTIFIER))for(e+=this.advance().value;this.match(_.DOT)&&this.peek(1).type===_.IDENTIFIER;)e+=".",this.advance(),e+=this.advance().value;else if(this.match(_.COMMA))e+=this.advance().value,this.skipNewlines();else break;this.match(_.OPERATOR,">")&&(e+=">",this.advance())}else for(;this.peek().type===_.IDENTIFIER&&this.isNameSlot(this.peek(1));)e+=" "+this.advance().value;let n=this.expectName().value;this.functionNames.has(n)&&(n=n+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let r=this.parseExpression(),i=new me(n);i.varType=e;let s=[new ut(i,r,e)];for(;this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.OPERATOR&&this.peek(2).value==="=";){this.advance(),this.skipNewlines(!0);let a=this.expectName().value;this.functionNames.has(a)&&(a=a+"_var"),this.expect(_.OPERATOR,"="),this.skipNewlines(!0);let o=this.parseExpression(),l=new me(a);l.varType=e,s.push(new ut(l,o,e))}return new gt(s,Wt.LET)}parseFunctionDeclaration(){let e=null;this.peek().type===_.IDENTIFIER&&this.isNameSlot(this.peek(1))&&(e=this.advance().value);let n=this.expectName().value;this.functionNames.add(n),this.expect(_.LPAREN);let r=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let u=this.peek(),p=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)p&&(p+=" "),p=(p||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let f=this.parseTypeExpression();p=p?p+" "+f:f}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let f=this.parseTypeExpression();p=p?p+" "+f:f}let h=this.expectName().value,d=new me(h);if(p&&(d.varType=p),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let f=this.parseExpression();this.assertParamDefault(f,u),r.push(new qi(d,f))}else r.push(d);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.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 me(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 Fi(a,r,s,e)}parseMethodDeclaration(){this.expect(_.KEYWORD,"method");let e=null;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type===_.LPAREN&&(e=this.advance().value);let n=this.expectName().value;this.expect(_.LPAREN);let r=[];for(;!this.match(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let o=this.peek(),l=null;for(;this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.IDENTIFIER&&this.peek(2).type!==_.LPAREN;)l&&(l+=" "),l=(l||"")+this.advance().value;if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.OPERATOR&&this.peek(1).value==="<"){let p=this.parseTypeExpression();l=l?l+" "+p:p}if(this.peek().type===_.IDENTIFIER&&this.peek(1).type===_.LBRACKET&&this.peek(2).type===_.RBRACKET){let p=this.parseTypeExpression();l=l?l+" "+p:p}let c=this.expectName().value,u=new me(c);if(l&&(u.varType=l),this.match(_.OPERATOR,"=")){this.advance(),this.skipNewlines();let p=this.parseExpression();this.assertParamDefault(p,o),r.push(new qi(u,p))}else r.push(u);this.match(_.COMMA)&&this.advance()}this.expect(_.RPAREN),this.skipNewlines(),this.expect(_.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 me(n);return e&&(a.returnType=e),a.isMethod=!0,new Fi(a,r,s,e)}parseFunctionBody(){let e=[];if(!this.match(_.INDENT)){let n=this.parseStatementOrSequence(),r=Array.isArray(n)?n:n?[n]:[];return r.length>0&&this._addImplicitReturn(r),new zt(r)}for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let n=this.parseStatementOrSequence();Array.isArray(n)?e.push(...n):n&&e.push(n)}return this.match(_.DEDENT)&&this.advance(),e.length>0&&this._addImplicitReturn(e),new zt(e)}_addImplicitReturn(e){let n=e[e.length-1];n.type==="ForStatement"||n.type==="WhileStatement"?this._addImplicitReturnToLoop(e):this._emitLastValue(e,r=>new Vi(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 me("na"),s=a=>new Ke(new fn("=",new me(r),a));this._emitLastValue(n.body.body,s)&&(n.body.body.unshift(s(i())),e.splice(e.length-1,0,new gt([new ut(new me(r),i())],Wt.LET)),e.push(new Vi(new me(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 me(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 me(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}parseStatementOrSequence(){this.pos;let e=this.peek().line;if(this.match(_.KEYWORD,"if")){let r=this.parseIfStatement();return r&&(r._line=e),r}if(this.match(_.KEYWORD,"for"))return this.parseForStatement();if(this.match(_.KEYWORD,"while"))return this.parseWhileStatement();if(this.match(_.KEYWORD,"break")||this.match(_.KEYWORD,"continue")){let r=this.advance().value;return new Ke(new me(r))}if(this.match(_.KEYWORD,"var")||this.match(_.KEYWORD,"varip"))return this.parseVarDeclaration();if(this.isTupleDestructuring())return this.parseTupleDestructuring();if(this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration()){let r=this.parseTypedVarDeclaration();if(this.match(_.COMMA)&&this.peek(1).type===_.IDENTIFIER){let i=[r];for(;this.match(_.COMMA);)if(this.advance(),this.skipNewlines(!0),this.peek().type===_.IDENTIFIER&&this.isTypedVarDeclaration())i.push(this.parseTypedVarDeclaration());else{this.rejectReservedAssignmentTarget();let s=this.peek(),a=this.parseExpression();if(this.match(_.OPERATOR)){let o=this.peek().value;if(["=",":="].includes(o)){this.advance(),this.skipNewlines(!0);let l=this.parseExpression();o==="="&&a.type==="Identifier"?(this.assertDeclarableName(a,s),this.assertNotTupleAssignment(a,l,s),i.push(new gt([new ut(a,l)],Wt.LET))):i.push(new Ke(new fn(o===":="?"=":o,a,l)))}}break}return i}return r}let n=[];for(;;){this.rejectReservedAssignmentTarget();let r=this.peek(),i=this.parseExpression();if(this.match(_.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 gt([new ut(i,a)],Wt.LET))):n.push(new Ke(new fn(s===":="?"=":s,i,a))),this.match(_.COMMA)){this.advance(),this.skipNewlines();continue}break}else{if(n.length>0)n.push(new Ke(i));else return new Ke(i);break}}else if(this.match(_.COMMA)){n.push(new Ke(i)),this.advance(),this.skipNewlines();continue}else{if(n.length>0)n.push(new Ke(i));else return new Ke(i);break}}return n.length>1?n:n.length===1?n[0]:null}parseIfStatement(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock(),r=null;return this.skipNewlines(),this.match(_.KEYWORD,"else")&&(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")?r=this.parseIfStatement():r=this.parseBlock()),new Ca(e,n,r)}parseForStatement(){this.expect(_.KEYWORD,"for");let e=null,n=!1;if(this.match(_.LBRACKET)){this.advance();let r=[];for(;!this.match(_.RBRACKET);)this.skipNewlines(),r.push(new me(this.expect(_.IDENTIFIER).value)),this.match(_.COMMA)&&this.advance();this.expect(_.RBRACKET),e=new Ui(r),n=!0}else{let r=this.expectName().value;e=new me(r)}if(this.match(_.KEYWORD,"in")){this.advance();let r=this.parseExpression();this.skipNewlines();let i=this.parseBlock(),s=new gt([new ut(e,r)],Wt.CONST),a=new Bi(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(_.OPERATOR,"=");let r=this.parseExpression();this.expect(_.KEYWORD,"to");let i=this.parseExpression(),s=null;this.match(_.KEYWORD,"by")&&(this.advance(),s=this.parseExpression()),this.skipNewlines();let a=this.parseBlock(),o=new gt([new ut(e,r)],Wt.LET),l=new Mt("<=",r,i),c=new Ht(l,new Mt("<=",e,i),new Mt(">=",e,i)),u;return s?u=new Ht(l,new fn("+=",e,s),new fn("-=",e,s)):u=new Ht(l,new Wi("++",e),new Wi("--",e)),new Bi(o,c,u,a)}}parseWhileStatement(){this.expect(_.KEYWORD,"while");let e=this.parseExpression();this.skipNewlines();let n=this.parseBlock();return new Na(e,n)}parseBlock(){if(!this.match(_.INDENT)){this.rejectDanglingWrappedLine();let r=this.parseStatement();return new zt(r?[r]:[])}let e=this.peek().indent;this.advance();let n=[];for(;!this.match(_.EOF);){if(this.skipNewlines(),this.match(_.DEDENT)){if(this.peek().indent<e)break;this.advance();continue}if(this.match(_.EOF))break;let r=this.parseStatement();r&&n.push(r)}return this.match(_.DEDENT)&&this.peek().indent<e&&this.advance(),new zt(n)}isTupleDestructuring(){if(!this.match(_.LBRACKET))return!1;let e=1;for(;;){for(;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type!==_.IDENTIFIER)return!1;for(e++,this.peek(e).type===_.IDENTIFIER&&e++;this.peek(e).type===_.NEWLINE;)e++;if(this.peek(e).type===_.RBRACKET){e++;break}else if(this.peek(e).type===_.COMMA){e++;continue}else return!1}for(;this.peek(e).type===_.NEWLINE;)e++;return this.peek(e).type===_.OPERATOR&&(this.peek(e).value==="="||this.peek(e).value===":=")}parseTupleDestructuring(){let e=this.expect(_.LBRACKET),n=[],r=new Set;for(;!this.match(_.RBRACKET);){this.skipNewlines();let a=this.expect(_.IDENTIFIER);if(this.match(_.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)}this.functionNames.has(o)&&(o=o+"_var"),n.push(new me(o)),this.match(_.COMMA)&&this.advance()}if(this.expect(_.RBRACKET),this.skipNewlines(),this.match(_.OPERATOR,":="))throw new Error(`Mismatched input ":=" expecting set "=" at ${this.startOf(this.peek())}`);this.expect(_.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 gt([new ut(new Ui(n),i)],Wt.CONST)}parseExpression(){return this.parseTernary()}parseTernary(){let e=this.parseLogicalOr();if(this.match(_.OPERATOR,"?")){let n=this.advance();this.skipNewlines(!0);let r=this.parseExpression();this.expect(_.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 Ht(e,r,i)}return e}parseLogicalOr(){let e=this.parseLogicalAnd();for(;this.match(_.KEYWORD,"or")||this.peekOperatorEx(["||"]);){this.advance(),this.skipNewlines(!0);let n=this.parseLogicalAnd();e=new Mt("||",e,n)}return e}parseLogicalAnd(){let e=this.parseEquality();for(;this.match(_.KEYWORD,"and")||this.peekOperatorEx(["&&"]);){this.advance(),this.skipNewlines(!0);let n=this.parseEquality();e=new Mt("&&",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 Mt(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 Mt(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 Mt(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 Mt(n,e,r)}return e}parseUnary(){if(this.match(_.OPERATOR)){let e=this.peek().value;if(["+","-","!"].includes(e)){let n=this.advance();this.skipNewlines();let r=new $i(e,this.parseUnary());return r._pos=this.startOf(n),r}}return this.match(_.KEYWORD,"not")?(this.advance(),this.skipNewlines(),new $i("!",this.parseUnary())):this.parsePostfix()}parsePostfix(){let e=this.parsePrimary();for(;;)if(this.match(_.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(_.EOF);)if(this.match(_.OPERATOR,"<"))r++,this.advance();else if(this.match(_.OPERATOR,">"))r--,this.advance();else if(this.match(_.IDENTIFIER)||this.match(_.COMMA)||this.match(_.DOT))r===1&&this.match(_.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 me("new_"+s)),i&&this.match(_.LPAREN)){e=this.parseCallExpression(e);continue}else{if(i)continue;break}}else if(this.match(_.LPAREN))e=this.parseCallExpression(e);else if(this.match(_.DOT)){this.advance(),this.skipNewlines();let n=this.peek();if(n.type!==_.IDENTIFIER&&n.type!==_.KEYWORD)throw new Error(`Expected property name but got ${n.type} at ${n.line}:${n.column}`);this.advance(),e=new ji(e,new me(n.value),!1)}else if(this.match(_.LBRACKET)){if(this.startsNewLine())break;this.advance(),this.skipNewlines();let n=this.parseExpression();this.expect(_.RBRACKET),e=new ji(e,n,!0)}else break;return e}parseCallExpression(e){let n=this.tokens[this.pos-1];this.expect(_.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(_.RPAREN)&&(this.skipNewlines(),!this.match(_.RPAREN));){let c=this.peek();if((this.peek().type===_.IDENTIFIER||this.peek().type===_.KEYWORD)&&this.peek(1).type===_.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 me(p);f._pos=this.startOf(u),i.push(new or(f,d))}else{let u=this.parseExpression();o(u,c,l?.[r.length]),r.push(u)}this.match(_.COMMA)&&this.advance(),this.skipNewlines()}return this.expect(_.RPAREN),i.length>0&&r.push(new Wr(i)),new Ia(e,r)}parsePrimary(){let e=this.peek();if(this.match(_.NUMBER)){let n=this.advance(),r=new _t(n.value,n.raw);return typeof n.raw=="string"&&(r._pos=`${n.line}:${n.column-n.raw.length}`),r}if(this.match(_.STRING)){let n=this.advance(),r=new _t(n.value);return n.startColumn!==void 0&&(r._pos=`${n.line}:${n.startColumn}`),r}if(this.match(_.BOOLEAN)){let n=this.advance(),r=new _t(n.value);return r._pos=this.startOf(n),r}if(this.match(_.IDENTIFIER)){let n=this.advance(),r=n.value;this.functionNames.has(r)&&this.peek().type!==_.LPAREN&&!this.isCurrentFunctionParam(r)&&!(this.peek().type===_.DOT&&pi.has(r))&&!(this.peek().type===_.DOT&&this.typeNames.has(r))&&(r=r+"_var");let i=new me(r);return i._pos=this.startOf(n),i}if(this.match(_.LBRACKET))return this.parseArrayLiteral();if(this.match(_.LPAREN)){this.advance(),this.skipNewlines();let n=this.parseExpression();return this.skipNewlines(),this.expect(_.RPAREN),n}if(this.match(_.KEYWORD,"if"))return this.parseIfExpression();if(this.match(_.KEYWORD,"switch"))return this.parseSwitchExpression();if(this.match(_.KEYWORD,"for"))return this.parseForExpression();if(this.match(_.KEYWORD,"while"))return this.parseWhileExpression();throw this.unexpected(e)}parseArrayLiteral(){let e=this.expect(_.LBRACKET),n=[];for(;!this.match(_.RBRACKET)&&(this.skipNewlines(),!this.match(_.RBRACKET));)n.push(this.parseExpression()),this.match(_.COMMA)&&this.advance(),this.skipNewlines();this.expect(_.RBRACKET);let r=new ka(n);return this.tupleLiteralStart.set(r,e),r._pos=this.startOf(e),r}parseIfExpression(){this.expect(_.KEYWORD,"if");let e=this.parseExpression();this.skipNewlines(),this.expect(_.INDENT);let n=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&n.push(a)}this.advance();let r=[];if(this.match(_.KEYWORD,"else"))if(this.advance(),this.skipNewlines(),this.match(_.KEYWORD,"if")){let a=this.parseIfExpression();if(this.needsIIFE(n,r)){let o=new Ht(e,new zt(n),a);return o.needsIIFE=!0,o.consequentStmts=n,o.alternateExpr=a,o}else return new Ht(e,this.getBlockValue(n),a)}else{for(this.expect(_.INDENT);!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&r.push(a)}this.advance()}if(this.needsIIFE(n,r)){let a=new Ht(e,new zt(n),new zt(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 _t(null);return new Ht(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(_.KEYWORD,"switch");let e=null;!this.match(_.NEWLINE)&&!this.match(_.INDENT)&&(e=this.parseExpression()),this.skipNewlines(),this.expect(_.INDENT);let n=[];for(;!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let r=null;this.match(_.OPERATOR,"=>")||(r=this.parseExpression()),this.expect(_.OPERATOR,"=>"),this.skipNewlines();let i=[];if(this.match(_.INDENT)){for(this.advance();!this.match(_.DEDENT)&&!this.match(_.EOF)&&(this.skipNewlines(),!this.match(_.DEDENT));){let a=this.parseStatement();a&&i.push(a)}this.advance()}else{let a=this.parseStatement();a&&i.push(a)}let s=this.getBlockValue(i);n.push(new Ma(r,s,i)),this.skipNewlines()}return this.advance(),new Aa(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 _t(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 _t(null)}};jt(xu,"STATEMENT_KEYWORDS",new Set(["if","else","for","while","switch"]));var fv=xu,mv=Object.defineProperty,yv=(t,e,n)=>e in t?mv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,It=(t,e,n)=>yv(t,typeof e!="symbol"?e+"":e,n),gv=new Set(Eo),Ta=class{constructor(e={}){It(this,"indent"),It(this,"indentStr"),It(this,"output"),It(this,"sourceCode"),It(this,"sourceLines"),It(this,"lastCommentedLine"),It(this,"includeSourceComments"),It(this,"paramRenameCounter"),It(this,"functionParams"),It(this,"userFunctionCollisions"),It(this,"renamedTypeNames"),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.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,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&&(pi.has(e)||ai.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++}`),pi.has(e.id.name)&&this.userFunctionCollisions.add(e.id.name)),e.type==="TypeDefinition"&&typeof e.name=="string"&&ai.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)?(ai.has(e.callee.name)||this.userFunctionCollisions.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)&&pi.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 u of e.params){let p=u.type==="AssignmentPattern"?u.left.name:u.name;if(p&&gv.has(p)){let h=`${p}_$${this.paramRenameCounter++}`;r.set(p,h)}}let i=u=>u.type==="Identifier"&&u.name==="this"||u.type==="AssignmentPattern"&&u.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((u,p)=>{let h=(u.type==="AssignmentPattern"?u.left:u)?.name;!h||!ai.has(h)||r.has(h)||n&&p===0&&h==="this"||a.set(h,`${h}_$${this.paramRenameCounter++}`)}),r.size>0||s.size>0||a.size>0){for(let u of e.params){let p=u.type==="AssignmentPattern"?u.left:u;if(p?.type==="Identifier"){let h=r.get(p.name)??s.get(p.name)??a.get(p.name);h&&(p.name=h)}u.type==="AssignmentPattern"&&u.right&&(r.size>0&&this.renameParamRefsInBody(u.right,r),s.size>0&&this.renameIdentifiersInAST(u.right,s),a.size>0&&this.renameVariableRefsInAST(u.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=n?`$M_${e.id.name}`:e.id.name;this.write("function "),this.write(o),this.write("(");let l=e.params;for(let u=0;u<l.length;u++){let p=l[u];p.type==="Identifier"?this.write(p.name):p.type==="AssignmentPattern"&&(this.write(p.left.name),this.write(" = "),this.generateExpression(p.right)),u<l.length-1&&this.write(", ")}if(this.write(") "),this.generateBlockStatement(e.body,!1),this.write(`\n`),n){this.write(this.indentStr.repeat(this.indent)),this.write(`${o}.__pineMethod__ = true;\n`);let u=e.params[0],p=u?.type==="AssignmentPattern"?u.left?.varType:u?.varType;typeof p=="string"&&p.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${o}.__pineReceiverType__ = ${JSON.stringify(p)};\n`))}let c=[];for(let u=0;u<e.params.length;u++){let p=e.params[u],h=p.type==="AssignmentPattern"?p.left?.name:p.name;if(n&&u===0&&h==="self")continue;let d=p.type==="AssignmentPattern"?p.left?.varType:p.varType;h&&d&&c.push([h,d])}if(c.length>0){this.write(this.indentStr.repeat(this.indent));let u=c.map(([p,h])=>`${JSON.stringify(p)}: ${JSON.stringify(h)}`).join(", ");this.write(`${o}.__pineParamTypes__ = {${u}};\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 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}}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(o=>o.name).join(", ")),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`)):a&&typeof s=="string"&&s.length>0&&(this.write(this.indentStr.repeat(this.indent)),this.write(`${JSON.stringify(`__pineTypedVar:${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];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"&&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.write(this.indentStr.repeat(this.indent)),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("})()")}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}}},Ul={pi:Math.PI,e:Math.E,phi:1.618033988749895,rphi:.618033988749895},vu=/^#[0-9a-f]{6}([0-9a-f]{2})?$/i,Ye=(t,e,n=!0)=>Number.isFinite(t)?{value:t,type:e,exact:n}:void 0,Xt=t=>!!t&&(t.type==="int"||t.type==="float")&&typeof t.value=="number",er=(...t)=>t.every(e=>e.type==="int")?"int":"float",Dr=(...t)=>t.every(e=>e.exact);function zi(t){return t.type==="int"&&typeof t.value=="number"?Math.trunc(t.value):t.value}function on(t){if(t?.type==="Identifier")return t.name;if(t?.type==="MemberExpression"&&!t.computed&&t.property?.type==="Identifier"){let e=on(t.object);return e===null?null:`${e}.${t.property.name}`}return null}function Ot(t,e){if(t!=null)switch(t.type){case"Literal":return _v(t);case"Identifier":return t.name==="na"?void 0:Zi.has(t.name)?{value:t.name,type:"source",exact:!1}:e.lookup(t.name);case"MemberExpression":return xv(t,e);case"UnaryExpression":return bv(t,e);case"BinaryExpression":case"LogicalExpression":return vv(t,e);case"ConditionalExpression":{let n=Ot(t.test,e);return n?.type!=="bool"?void 0:Ot(n.value?t.consequent:t.alternate,e)}case"CallExpression":return Sv(t,e);default:return}}function _v(t){let e=t.value;if(typeof e=="boolean")return{value:e,type:"bool",exact:!0};if(typeof e=="string")return vu.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 Ye(e,n?"float":"int")}}function xv(t,e){let n=on(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 Ul)return Ye(Ul[i],"float");if(r==="color"&&Xi(n))return{value:n,type:"color",exact:!1};let s=Xp[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 bv(t,e){let n=Ot(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(Xt(n)){if(t.operator==="-")return Ye(-n.value,n.type,n.exact);if(t.operator==="+")return n}}}function vv(t,e){let n=t.operator;if(n==="&&"||n==="||"||n==="and"||n==="or"){let l=Ot(t.left,e);if(l?.type!=="bool")return;if(n==="&&"||n==="and"?!l.value:l.value)return l;let c=Ot(t.right,e);return c?.type==="bool"?{value:c.value,type:"bool",exact:l.exact&&c.exact}:void 0}let r=Ot(t.left,e),i=Ot(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:Dr(r,i)};if(n==="=="||n==="==="||n==="!="||n==="!=="){if(!(Xt(r)&&Xt(i)||r.type===i.type&&["string","bool"].includes(r.type)))return;let l=Xt(r)?Math.abs(r.value-i.value)<1e-10:r.value===i.value;return{value:n.startsWith("=")?l:!l,type:"bool",exact:Dr(r,i)}}if(!Xt(r)||!Xt(i))return;let s=r.value,a=i.value,o=Dr(r,i);switch(n){case"+":return Ye(s+a,er(r,i),o);case"-":return Ye(s-a,er(r,i),o);case"*":return Ye(s*a,er(r,i),o);case"/":{if(a===0)return;let l=er(r,i),c=s/a;return Ye(l==="int"&&e.truncatingIntDivision?Math.trunc(c):c,l,o)}case"%":return a===0?void 0:Ye(s%a,er(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 wv={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 Sv(t,e){let n=on(t.callee);if(n===null)return;let r=t.arguments??[];if(r.some(a=>a?.type==="ObjectExpression"))return;let i=r.map(a=>Ot(a,e));if(i.some(a=>!a))return;let s=i;if(n==="int"&&s.length===1&&Xt(s[0]))return Ye(Math.trunc(s[0].value),"int",s[0].exact);if(n==="float"&&s.length===1&&Xt(s[0]))return Ye(zi(s[0]),"float",s[0].exact);if(n.startsWith("math.")){let a=n.slice(5);if(a==="round"){if(!s.every(Xt)||s.length<1||s.length>2)return;let c=s[0].value;if(s.length===1)return Ye(Math.round(c),"int",s[0].exact);let u=Math.pow(10,s[1].value);return Ye(Math.round(c*u)/u,"float",Dr(...s))}let o=wv[a];if(!o||s.length<o.arity[0]||s.length>o.arity[1]||!s.every(Xt))return;let l=o.type==="same"?er(...s):o.type;return Ye(o.fn(...s.map(c=>c.value)),l,Dr(...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"?Ye(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 Ev(n,s);if(n==="timestamp"&&s.length===1&&s[0].type==="string")return Cv(String(s[0].value))}function Ev(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:qs(s,a,o,c),type:"color",exact:!1}}let r=Xi(e[0]?.value),i=e[1]?.value;if(!(!r||typeof i!="number"))return{value:qs(r[0],r[1],r[2],n((100-i)/100)),type:"color",exact:!1}}function Cv(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()),Ye(r,"int",n)}var ql={const:0,input:1,simple:2,series:3},Rr=(...t)=>t.reduce((e,n)=>ql[n]>ql[e]?n:e,"const"),Pa={},Bn=(t,e,n)=>n.forEach(r=>Pa[r]={qual:t,type:e});Bn("series","float",["open","high","low","close","volume","hl2","hlc3","ohlc4","hlcc4"]);Bn("series","int",["bar_index","last_bar_index","time","time_close","timenow","year","month","weekofyear","dayofmonth","dayofweek","hour","minute","second"]);Bn("series","bool",["barstate.isfirst","barstate.islast","barstate.ishistory","barstate.isrealtime","barstate.isnew","barstate.isconfirmed","barstate.islastconfirmedhistory"]);Bn("simple","int",["timeframe.multiplier"]);Bn("simple","float",["syminfo.mintick","syminfo.pointvalue"]);Bn("simple","string",["timeframe.period","syminfo.ticker","syminfo.tickerid","syminfo.timezone","syminfo.currency","syminfo.type","syminfo.prefix","syminfo.root","syminfo.description"]);Bn("simple","bool",["timeframe.isintraday","timeframe.isdaily","timeframe.isweekly","timeframe.ismonthly","timeframe.isdwm","timeframe.isminutes","timeframe.isseconds"]);var Nv=new Set(["cross","crossover","crossunder","rising","falling"]),Iv=new Set(["barssince","highestbars","lowestbars"]),kv=new Set(["floor","ceil"]),Av=new Set(["abs","max","min"]),wu=(...t)=>t.every(e=>e==="int")?"int":"float",yn=t=>t==="int"||t==="float";function Yt(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:vu.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??Pa[t.name]}case"MemberExpression":{let n=on(t);return n?.startsWith("color.")&&Xi(n)?{qual:"const",type:"color"}:n?Pa[n]:void 0}case"UnaryExpression":{let n=Yt(t.argument,e);return n?t.operator==="!"?n.type==="bool"?n:void 0:yn(n.type)?n:void 0:void 0}case"BinaryExpression":case"LogicalExpression":{let n=Yt(t.left,e),r=Yt(t.right,e);if(!n||!r)return;let i=Rr(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)&&yn(n.type)&&yn(r.type)?{qual:i,type:wu(n.type,r.type)}:void 0}case"ConditionalExpression":{let n=Yt(t.test,e),r=Yt(t.consequent,e),i=Yt(t.alternate,e);if(!n||!r||!i)return;let s=Rr(n.qual,r.qual,i.qual);return r.type===i.type?{qual:s,type:r.type}:yn(r.type)&&yn(i.type)?{qual:s,type:"float"}:void 0}case"CallExpression":return Mv(t,e);default:return}}function Mv(t,e){let n=on(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:Nv.has(o)?"bool":Iv.has(o)?"int":"float"}}let i=r.map(o=>Yt(o,e));if(i.some(o=>!o))return;let s=i,a=Rr(...s.map(o=>o.qual));if(n==="timestamp")return s.length===1&&s[0].type==="string"?{qual:a,type:"int"}:s.length>=3?{qual:Rr("simple",a),type:"int"}:void 0;if(n==="color.new"||n==="color.rgb")return{qual:a,type:"color"};if(n==="int"&&s.length===1&&yn(s[0].type))return{qual:a,type:"int"};if(n==="float"&&s.length===1&&yn(s[0].type))return{qual:a,type:"float"};if(n==="str.tostring"||n==="str.format")return{qual:Rr("simple",a),type:"string"};if(n.startsWith("math.")&&s.length&&s.every(o=>yn(o.type))){let o=n.slice(5);return o==="round"?{qual:a,type:s.length===1?"int":"float"}:kv.has(o)?{qual:a,type:"int"}:Av.has(o)?{qual:a,type:wu(...s.map(l=>l.type))}:{qual:a,type:"float"}}}var Tv={"&&":"and","||":"or","!":"not","===":"==","!==":"!="};function zl(t,e){let n=`(${e.qual} ${e.type})`;switch(t?.type){case"Identifier":case"MemberExpression":return on(t)??"";case"CallExpression":return`call "${on(t.callee)}" ${n}`;case"ConditionalExpression":return`call "operator ?:" ${n}`;case"BinaryExpression":case"LogicalExpression":case"UnaryExpression":return`call "operator ${Tv[t.operator]??t.operator}" ${n}`;default:return""}}function Dt(t){switch(t?.type){case"Identifier":case"Literal":case"UnaryExpression":case"ArrayExpression":return t._pos;case"MemberExpression":return Dt(t.object);case"CallExpression":return Dt(t.callee);case"BinaryExpression":case"LogicalExpression":return Dt(t.left);case"ConditionalExpression":return Dt(t.test);default:return}}var Pv=Object.defineProperty,Dv=(t,e,n)=>e in t?Pv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dn=(t,e,n)=>Dv(t,typeof e!="symbol"?e+"":e,n),Rv="untitled",Ov=new Set(["bool","color","enum","float","int","price","session","source","string","symbol","text_area","time","timeframe"]),Hl={"":["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"]},Lv=["defval","title","inline","group","tooltip","display","active"],Kl=["defval","title","options","tooltip","inline","group","confirm","display","active"],Yl=["defval","title","minval","maxval","step","tooltip","inline","group","confirm","display","active"],Fv={"":"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 Bv(t,e){if(e==="defval")return Fv[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 mn=class{constructor(e){this.parent=e,dn(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 Vv(t,e={}){return new Da(t,e).run()}function Su(t){if(t?.type!=="CallExpression")return null;let e=on(t.callee);return e==="input"?"":e?.startsWith("input.")&&Ov.has(e.slice(6))?e.slice(6):null}var Da=class{constructor(e,n){this.ast=e,dn(this,"sites",[]),dn(this,"enums",new Map),dn(this,"reassigned",new Set),dn(this,"visited",new WeakSet),dn(this,"inputDefaults",new WeakMap),dn(this,"functionNames",new Set),dn(this,"truncatingIntDivision"),this.truncatingIntDivision=n.version!=null&&n.version<6}run(){this.collectEnumsAndReassignments(this.ast);let e=new mn(null);return this.visitStatements(this.ast.body??[],{scope:e,target:null,fnName:null}),this.sites}collectEnumsAndReassignments(e){yi(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=Ot(i.init,this.env(i.scope))??null,i.busy=!1),i.cache??void 0}}}fold(e,n){return Ot(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:Zl(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&&Zl(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 mn(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 mn(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 mn(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=Su(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 mn(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 mn(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(S=>S.key?.name==="defval")?.value,h=n==="int"||n==="float"?o.some(S=>S.key?.name==="options")||l[2]?.type==="ArrayExpression"?Kl:Yl:n===""&&Ds(p,r.scope)?Lv:Hl[n];l.forEach((S,C)=>{C<h.length&&(u[h[C]]={node:S,holder:i,key:String(C)})});let d=n==="int"||n==="float"?new Set([...Kl,...Yl]):new Set(Hl[n]);for(let S of o)if(!(S.type!=="Property"||!S.key?.name)){if(!d.has(S.key.name))throw new Error(`The "${c}" function does not have an argument with the name "${S.key.name}"${S.key._pos?` at ${S.key._pos}`:""}`);u[S.key.name]={node:S.value,holder:S,key:"value"}}this.validateArguments(e,r.scope,u.active?.node),this.checkArgumentTypes(e,n,u,r.scope);let f={},m;for(let[S,{node:C}]of Object.entries(u)){let k=C?.type==="ArrayExpression"?void 0:S==="active"?Ot(C,this.env(r.scope,!0)):this.fold(C,r.scope);S==="defval"&&(m=k?.type,k&&this.inputDefaults.set(e,k)),f[S]=k?zi(k):$v(C,B=>this.fold(B,r.scope))}if(this.checkDefvalConstraints(e,n,u,f,r.scope),n==="enum"&&f.options===void 0){let S=this.enumField(u.defval?.node,r.scope),C=S?.slice(0,S.lastIndexOf(".")+1);C&&(f.options=[...this.enums].filter(([k])=>k.startsWith(C)&&!k.slice(C.length).includes(".")).map(([,k])=>k))}this.inlineDefval(u.defval,r.scope);let x=`in_${this.sites.length}`,b=typeof f.title=="string"?f.title:void 0,v=r.target??void 0,E={id:x,fn:n,name:b??r.target??r.fnName??Rv,args:f};v!==void 0&&(E.varId=v),m!==void 0&&(E.defvalType=m),this.sites.push(E);let w=[new or(new me("__inputId"),new _t(x))];v!==void 0&&w.push(new or(new me("__varId"),new _t(v))),i.push(new Wr(w))}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=zi(r),s=r.type==="float"&&typeof i=="number"&&Number.isInteger(i)?`${i}.0`:typeof i=="number"?String(i):null;e.holder[e.key]=new _t(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=Yt(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=Rs(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(Ds(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(Dt(u))}`):new Error(`The "defval" parameter of the "${a}()" function cannot accept a "na" argument.${l(Dt(u))}`);if(c==="options"&&u.type==="ArrayExpression"){this.checkOptionTypes(a,n,u,s);continue}let p=Bv(n,c);if(!p)continue;let h=Yt(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(Ds(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&&Gl(h.type,p))continue;let f=u.type==="Literal",m=f?Xl(u):zl(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(Dt(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=>Yt(p,i));if(o.some(p=>!p)||o.every(p=>p.qual!=="simple"&&p.qual!=="series"&&Gl(p.type,s)))return;let l=a.map((p,h)=>p.type==="Literal"?Xl(p):zl(p,o[h])).join(","),c=a.map((p,h)=>`${p.type==="Literal"?"literal":o[h].qual} ${o[h].type}`).join(", "),u=Dt(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 on(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(Rs(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(Dt(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(Dt(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(Dt(a))}`)}}validateArguments(e,n,r){let i=new Set;r&&yi(r,s=>i.add(s)),yi({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=Rs(e.callee);throw new Error(`Arguments of input function must be of constant type, or "source" builtin variables.${c?` at ${c}`:""}`)}}})}};function Ds(t,e){return t?.type==="Identifier"&&Zi.has(t.name)&&!e.resolve(t.name)}function Gl(t,e){return t===e||e==="float"&&t==="int"}function Xl(t){return String(t.value)}function $v(t,e){if(t?.type==="ArrayExpression")return(t.elements??[]).map(n=>{let r=e(n);return r?zi(r):void 0})}function Zl(t){let e=!1;return yi(t,n=>{!e&&Su(n)!==null&&(e=!0)}),e}function Rs(t){let e=t;for(;e?.type==="MemberExpression";)e=e.object;return e?._pos}function yi(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 Eu(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 ko(t,e={}){let n=Eu(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 cv(t).tokenize(),i=new fv(r).parse(),s=Vv(i,{version:n}),a={...e,sourceCode:t},o=new Ta(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 Wv=new Set(["security_lower_tf","security"]),Cu=new Set(["type","loc","start","end","range","parent","leadingComments","trailingComments"]);function jv(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:Wv.has(e.property.name)}function Uv(t){let e=t?.arguments?.[2];return e?.type==="Identifier"&&typeof e.name=="string"?e.name:null}function qv(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]);jv(i)&&e.push({call:i,path:a});for(let o of Object.keys(i)){if(Cu.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 Ra(t){return t?t.type==="FunctionExpression"||t.type==="ArrowFunctionExpression"||t.type==="FunctionDeclaration":!1}function Kt(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(Kt(r,e,n+1)),{...t,body:s}}case"IfStatement":return r===t.test?{...t,test:Kt(r,e,n+1),consequent:{type:"BlockStatement",body:[]},alternate:null}:r===t.consequent?{...t,consequent:Kt(r,e,n+1),alternate:null}:r===t.alternate?{...t,alternate:Kt(r,e,n+1)}:t;case"ForStatement":case"WhileStatement":case"DoWhileStatement":case"ForInStatement":case"ForOfStatement":return r===t.body?{...t,body:Kt(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(Kt(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(Kt(r,e,n+1)),{...t,consequent:s}}return t}case"FunctionDeclaration":case"FunctionExpression":case"ArrowFunctionExpression":return r===t.body?{...t,body:Kt(r,e,n+1)}:t;default:return t}}function zv(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 Hv(t,e,n){let r=t.body||[];for(let i=0;i<r.length;i++){let s=r[i];if(s!==n&&Kv(s,e))return i}return-1}function Kv(t,e){let n=!1,r=new WeakSet;function i(s){if(!(n||!s||typeof s!="object")&&!r.has(s)){if(r.add(s),zv(s)===e){n=!0;return}for(let a of Object.keys(s)){if(Cu.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 Yv(t,e){let n=-1;for(let h=1;h<e.length;h++)if(Ra(e[h])){n=h;break}if(n<0)return null;let r=e[n];for(let h=n+1;h<e.length;h++)if(Ra(e[h]))return null;if(r.type!=="FunctionDeclaration"||!r.id?.name)return null;let i=r.id.name,s=e.slice(n),a=Kt(r,s,0),o=Hv(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 Gv(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 = ${wo(n)}\n; return _r;`;return new Function("",r)()}function Xv(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=qv(r.body);for(let{call:s,path:a}of i){let o=Uv(s);if(!o||o in e)continue;let l=a.some(p=>Ra(p)),c=null;if(l)c=Yv(r.body,a);else{let p=Kt(r.body,a,0);c=p&&p.body?p.body:[]}if(!c||c.length===0)continue;let u=Gv(r,c);e[o]=u}return e}function Zv(t){if(typeof t=="function")return{code:t.toString(),version:null};{let e=Eu(t);if(e===null)return{code:t,version:null};if(e>=5){let n=ko(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 Qv(t,e={debug:!1,ln:!1}){typeof e=="boolean"&&(e={debug:e,ln:!0});let{debug:n}=e,{code:r,version:i}=Zv(t),s=r;s=_1(s);let a=n?s.split(`\n`):[],o=bo(s,{ecmaVersion:"latest",sourceType:"module",locations:n});x1(o),m1(o),f1(o);let l=new ga;E1(o,l),b1(o,l);let c=N1(o,l)||"";if(i!==null&&i<6&&O1(o),V1(o,{lazyLogical:i===null||i>=6}),tv(o,l,c,e,a),X1(o),Q1(o),ev(o),H1(o),o.type==="Program"&&o.body.length>0){let m=o.body[0],x=m?.expression||m;x.body?.type==="BlockStatement"&&x.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=n1||vo||void 0,p=Object.assign({},u,{LineComment(m,x){x.write("//"+m.value)}}),h=wo(o,{generator:p,comments:n}),d=typeof process<"u"&&process?.env?.PINETS_DISABLE_LTF_SLICING==="1"?{}:Xv(o),f=new Function("",`var _r = ${h}\n; return _r;`)(this);return d&&Object.keys(d).length>0&&(f._ltfSlices=d),f}var Jv={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"},ew=new Set(["bool","color","time","text_area"]),tw=["open","high","low","close","hl2","hlc3","hlcc4","ohlc4"];function nw(t){if(typeof t!="string")return[];let e=ko(t);if(!e.success||!e.inputs)return[];let n=[];for(let r of e.inputs){let i=rw(r);i&&n.push(i)}return n}function rw(t){let e=t.args,n=t.fn===""?iw(e.defval,t.defvalType):Jv[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?sw(e.display):ew.has(n)?"none":"all";return i!==void 0&&(r.display=i),Array.isArray(e.options)?r.options=e.options:n==="source"&&(r.options=[...tw]),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 iw(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"?Zi.has(t)?"source":t.startsWith("#")?"color":"string":null}function sw(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 Nu(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 aw(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 aw(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 ${Jn(e)}`);break;case"float":case"price":case"time":if(typeof e!="number"||!Number.isFinite(e))throw new TypeError(`[${n}] "${r}" expects a number; got ${Jn(e)}`);break;case"bool":if(typeof e!="boolean")throw new TypeError(`[${n}] "${r}" expects a boolean; got ${Jn(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 ${Jn(e)}`);break}if(t.options&&!t.options.some(i=>ow(i,e)))throw new RangeError(`[${n}] "${r}" value ${Jn(e)} is not one of: ${t.options.map(Jn).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 ow(t,e){return t===e?!0:typeof t=="number"&&typeof e=="number"?Math.abs(t-e)<1e-12:!1}function Jn(t){return t===null?"null":typeof t=="string"?JSON.stringify(t):String(t)}function lw(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}=Nu(r,"Indicator.input",e,void 0,"input key");return{proxy:s,values:a,metaByKey:n}}var Iu=[{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}],ku=[...Iu.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"}],Au=[...Iu.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 cw(t){return t==="strategy"?Au:ku}function uw(t){return typeof t=="string"?hw(t):typeof t=="function"?pw(t):{type:null,args:{}}}function hw(t){let e=ko(t);if(!e.success||!e.ast)return{type:null,args:{}};let n=null;return Hi(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:Tu(i.arguments??[],Mu(s.name))}))}),n??{type:null,args:{}}}function pw(t){let e;try{e=bo(`(${t.toString()})`,{ecmaVersion:"latest"})}catch{return{type:null,args:{}}}let n=null;return Hi(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:Tu(r.arguments??[],Mu(i.name))}))}),n??{type:null,args:{}}}function Mu(t){return t==="strategy"?Au:ku}function Tu(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]=Oa(s[a])}if(i)for(let a of r.properties??[])a.type!=="Property"||!a.key?.name||(n[a.key.name]=Oa(a.value));return n}function Oa(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(Oa);default:return}}function Hi(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)Hi(i,e);else r&&typeof r=="object"&&typeof r.type=="string"&&Hi(r,e)}}}function dw(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}=Nu(i,"Indicator.prop",n,e);return{proxy:s,values:a,propByName:r}}var fw=Object.defineProperty,mw=(t,e,n)=>e in t?fw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nt=(t,e,n)=>mw(t,typeof e!="symbol"?e+"":e,n),Dn=class t{constructor(e,n={}){nt(this,"source"),nt(this,"inputs"),nt(this,"_prepared",null),nt(this,"_inputMeta",null),nt(this,"_inputValues",{}),nt(this,"_explicitOverrides",new Set),nt(this,"_inputProxy",null),nt(this,"_inputMetaByKey",new Map),nt(this,"_propMeta",null),nt(this,"_propValues",{}),nt(this,"_propProxy",null),nt(this,"_declarationType",null),nt(this,"_sourcePropArgs",{}),nt(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=Qv(this.source,{debug:!!e.debug,ln:e.ln}),r=yw(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=nw(this.source);for(let n of this._inputMeta)n.type==="color"&&n.defval!==void 0&&(n.defval=cm(n.defval));let e=lw(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=uw(this.source);this._declarationType=e.type,this._sourcePropArgs=e.args,this._propMeta=cw(e.type);let n=dw(this._propMeta,this._sourcePropArgs,r=>this._explicitPropOverrides.add(r));this._propValues=n.values,this._propProxy=n.proxy}_getPropProxy(){return this._ensurePropsScanned(),this._propProxy}};function yw(t){let e=t.toString();return c1.some(n=>{let r=n.replace(/\\./g,"\\\\.");return new RegExp(`\\\\b${r}\\\\b`).test(e)})}var gw=Object.defineProperty,_w=(t,e,n)=>e in t?gw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,de=(t,e,n)=>_w(t,typeof e!="symbol"?e+"":e,n),Ql={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 xw(t){return t?Ql[t]??Ql[t.toUpperCase()]??864e5:864e5}var Sn=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,de(this,"data",[]),de(this,"open",[]),de(this,"high",[]),de(this,"low",[]),de(this,"close",[]),de(this,"volume",[]),de(this,"hl2",[]),de(this,"hlc3",[]),de(this,"ohlc4",[]),de(this,"hlcc4",[]),de(this,"openTime",[]),de(this,"closeTime",[]),de(this,"_readyPromise",null),de(this,"_ready",!1),de(this,"_debugSettings",{ln:!1,debug:!1}),de(this,"_transpiledCode",null),de(this,"_currentIndicator",null),de(this,"_isSecondaryContext",!1),de(this,"_syminfo"),de(this,"_chartTimezone",null),de(this,"_maxLoops",5e5),de(this,"_alertMode","realtime"),de(this,"_viewportLeft"),de(this,"_viewportRight"),de(this,"_usesVisibleRange",!1),de(this,"_lastRunViewport",{}),de(this,"_lastResult",null),de(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),x=c.map(C=>(C.high+C.low)/2),b=c.map(C=>(C.high+C.low+C.open+C.close)/4),v=c.map(C=>(C.high+C.low+C.close+C.close)/4),E=c.map(C=>C.openTime),w=xw(this.timeframe),S=c.map(C=>C.closeTime!=null?C.closeTime:C.openTime+w);this.open=u,this.close=p,this.high=h,this.low=d,this.volume=f,this.hl2=x,this.hlc3=m,this.ohlc4=b,this.hlcc4=v,this.openTime=E,this.closeTime=S,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=Dn.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=Dn.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],x=m&&m.closeTime<Date.now(),b=f.idx>=f.marketData.length-1;(!x||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),x=this._getResultLength(a.result),b=o+m;i&&b>=c&&m>1?(await this._executeIterations(a,this._transpiledCode,o,b-1),l=this._snapshotVarState(a),await this._executeIterations(a,this._transpiledCode,b-1,b)):i&&b>=c&&m===1?await this._executeIterations(a,this._transpiledCode,o,b):await this._executeIterations(a,this._transpiledCode,o,b),o+=m,yield this._createPageContext(a,x);continue}if(!i||Array.isArray(this.source))break;let 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 ar({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=T0(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++})}P0(e.strategy,n.strategy)}_initializeContext(e,n={},r=!1){let i=new ar({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=Fr(String(this.tickerId??"")).modifier;return i.chartStyle=s==="heikinashi"?"heikinashi":"standard",this._syminfo&&s==="heikinashi"&&(i.pine.syminfo={...this._syminfo,tickerid:Gs(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){w0(e),f0(e),Cs(e,"open");let c=S0(e);c&&Cs(e,"extreme"),v0(e,"intrabar"),c||Cs(e,"extreme"),E0(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&&C0(e)}},Jl={"1m":6e4,"3m":18e4,"5m":3e5,"15m":9e5,"30m":18e5,"1h":36e5,"2h":72e5,"4h":144e5,"1d":864e5,"1w":6048e5,"1M":2592e6},Or={"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 Lr(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 Gt(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"),x=Date.UTC(p,h-1,d,f,m,0,0)-l;return l-x}function ec(t,e,n,r,i=1){if(e==="24x7")return Lr(t,r,i);let s=e.split("-")[1];if(!s||s.length!==4)return Lr(t,r,i);let a=s.slice(0,2),o=s.slice(2,4),l=`${a}:${o}`,c=tc(t,n);if(r==="second"||r==="minute"||r==="hour"){let u=t+i*{second:1e3,minute:6e4,hour:36e5}[r],p=Gt(c,l,n);return Math.min(u,p)}if(r==="day")return Gt(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=tc(h,n);return Gt(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 Gt(m,l,n)}return Lr(t,r,i)}function tc(t,e){return new Intl.DateTimeFormat("en-CA",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(t))}function bw(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 vw=["1S","5S","10S","15S","30S","1","3","5","15","30","45","60","120","180","240","D","W","M"];function ww(t,e){if(t==="W"||t==="M")return e.has("D")?"D":null;let n=Or[t];if(!n)return null;let r=vw.filter(i=>i!=="W"&&i!=="M"&&e.has(i)&&Or[i]<n&&n%Or[i]===0);return r.length===0?null:r[r.length-1]}function Pu(t,e){if(t==="W"||t==="M")return 1/0;let n=Or[t],r=Or[e];return!n||!r||r===0?1/0:n/r}function Sw(t,e,n){if(t.length===0)return[];if(e==="W")return Cw(t);if(e==="M")return Nw(t);let r=Pu(e,n);return Ew(t,r)}function Ew(t,e){if(t.length===0)return[];let n=[],r=[t[0]],i=Iw(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(Ki(r)),r=[]),r.push(t[a])}return r.length>0&&n.push(Ki(r)),n}function Cw(t){let e=[],n=[],r="";for(let i of t){let s=kw(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(Ki)}function Nw(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(Ki)}function Ki(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 Iw(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 kw(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 Aw=Object.defineProperty,Mw=(t,e,n)=>e in t?Aw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oi=(t,e,n)=>Mw(t,typeof e!="symbol"?e+"":e,n),li={"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 Tw(t){if(li[t]!==void 0)return li[t];let e=t.toLowerCase();return li[e]!==void 0?li[e]:/^\\d+$/.test(t)?t:/^\\d+S$/i.test(t)?t.toUpperCase():t}var jr=class{constructor(e){oi(this,"_configured"),oi(this,"_requiresApiKey"),oi(this,"_providerName"),oi(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){bw(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=xn(e);let a=Tw(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:ww(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=Sw(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=Pu(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)}},Pw=Object.defineProperty,Dw=(t,e,n)=>e in t?Pw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Yi=(t,e,n)=>Dw(t,typeof e!="symbol"?e+"":e,n),Os="https://api.binance.com/api/v3",nc="https://api.binance.us/api/v3",ci={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"},La=class{constructor(e=300*1e3){Yi(this,"cache"),Yi(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)}},Fa=class extends jr{constructor(){super({requiresApiKey:!1,providerName:"Binance"}),Yi(this,"cacheManager"),Yi(this,"activeApiUrl",null),this.cacheManager=new La(300*1e3)}async getBaseUrl(){if(this.activeApiUrl)return this.activeApiUrl;try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${Os}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=Os,this.activeApiUrl}catch{}try{let e=new AbortController,n=setTimeout(()=>e.abort(),5e3),r=await fetch(`${nc}/ping`,{signal:e.signal});if(clearTimeout(n),r.ok)return this.activeApiUrl=nc,this.activeApiUrl}catch{}return Os}async _fetchRawChunk(e,n,r,i,s){let a=ci[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=ci[n.toUpperCase()];if(!s)return console.error(`Unsupported timeframe: ${n}`),[];let a=[],o=r,l=i,c=Jl[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(!ci[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=ci[e.toUpperCase()],a=Jl[s];if(a)return Math.ceil((i-r)/a)>1e3}return!1}async getSymbolInfo(e){e=xn(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(E=>E.symbol===i):l[0];if(!c)return console.error(`Symbol ${i} not found in exchange info`),null;let u=c.filters?.find(E=>E.filterType==="PRICE_FILTER"),p=c.filters?.find(E=>E.filterType==="LOT_SIZE"),h=u?parseFloat(u.tickSize):.01,d=p?parseFloat(p.minQty):0,f=Math.round(1/h),m=c.baseAsset,x=c.quoteAsset,b=s?` ${s}`:"",v=`${m} / ${x}${b}`;return{ticker:e,tickerid:`BINANCE:${e}`,prefix:"BINANCE",root:m,description:v,type:n,main_tickerid:`BINANCE:${e}`,current_contract:s,isin:"",basecurrency:m,currency:x,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}}},Rw=Object.defineProperty,Ow=(t,e,n)=>e in t?Rw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,br=(t,e,n)=>Ow(t,typeof e!="symbol"?e+"":e,n),Lw="https://financialmodelingprep.com",rc=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"]),ic={"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"}},sc={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"},ac={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"},Fw={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}},Ba=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"FMP"}),br(this,"_apiKey",null),br(this,"_baseUrl",Lw),br(this,"_profileCache",new Map),br(this,"_symbolInfoCache",new Map),br(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=ic[a]||ic[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=ec(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}=Fw[r]||{periodType:"minute",multiplier:1},{session:d,timezone:f}=await this._resolveSessionInfo(e);return u.map(m=>{let x=this._dateTimeStrToMs(m.date),b=ec(x,d,f,p,h);return{openTime:x,open:m.open,high:m.high,low:m.low,close:m.close,volume:m.volume,closeTime:b,quoteAssetVolume:0,numberOfTrades:0,takerBuyBaseAssetVolume:0,takerBuyQuoteAssetVolume:0,ignore:0}})}async getSymbolInfo(e){if(this.ensureConfigured(),e=xn(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":sc[i]||"America/New_York",a=r==="crypto"?"24x7":r==="forex"?"0000-0000":ac[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":sc[r]||"America/New_York";return{session:i?"24x7":ac[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)&&rc.has(e.slice(0,3))&&rc.has(e.slice(3,6))}_isCrypto(e){return this._isForex(e)?!1:/^[A-Z]+(USD|USDT|BTC|ETH)$/.test(e)&&e.length<=15}},Bw=Object.defineProperty,Vw=(t,e,n)=>e in t?Bw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kn=(t,e,n)=>Vw(t,typeof e!="symbol"?e+"":e,n),$w="https://data.alpaca.markets",Ww="https://paper-api.alpaca.markets/v2",jw="https://api.alpaca.markets/v2",Ls=1e4,oc={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"},Uw={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"},qw={NASDAQ:"0930-1600",NYSE:"0930-1600",AMEX:"0930-1600",ARCA:"0930-1600",BATS:"0930-1600",OTC:"0930-1600",CRYPTO:"24x7"},zw={Min:"minute",Hour:"hour",Day:"day",Week:"week",Month:"month"},Va=class extends jr{constructor(e){super({requiresApiKey:!0,providerName:"Alpaca"}),kn(this,"_apiKey",null),kn(this,"_apiSecret",null),kn(this,"_dataUrl",$w),kn(this,"_tradingUrl",Ww),kn(this,"_feed",null),kn(this,"_assetCache",new Map),kn(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=jw)}_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||Ls,Ls);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,Ls))),o&&c.set("page_token",o),!r&&this._feed&&c.set("feed",this._feed),`${l}?${c.toString()}`}async getSymbolInfo(e){this.ensureConfigured(),e=xn(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":Uw[r]||"America/New_York",a=i?"24x7":qw[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():Lr(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=Gt(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=Gt(o,p,i);l=Math.min(c,h)}else n==="week"?l=this._weeklyCloseFromCalendar(o,i):n==="month"?l=this._monthlyCloseFromCalendar(o,i):l=Lr(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 Gt(u,p.close,n)}let a=r.getTime()+s*864e5,o=new Date(a).toISOString().split("T")[0];return Gt(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 Gt(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 Gt(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=zw[n[2]];if(i)return{periodType:i,multiplier:r}}return{periodType:"day",multiplier:1}}_resolveTimeframe(e){return oc[e.toUpperCase()]||oc[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]}},$a=class{async getMarketData(){return[]}},Hw=typeof process<"u"&&process.versions&&process.versions.node,Gi=null;if(Hw)try{Gi=new $a}catch{Gi=null}var W2={Binance:new Fa,FMP:new Ba,Alpaca:new Va,...Gi?{Mock:Gi}:{}};function z(t){return typeof t=="string"?t:void 0}function he(t){return typeof t=="number"&&Number.isFinite(t)?t:void 0}function Du(t){if(typeof t=="boolean")return t;if(typeof t=="object"&&t!==null&&Array.isArray(t.data)){let e=t;return Du(e.data[e.offset??0])}}function Kw(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 Ao(t){let e=t??{},n=e.fullContext??e;return Object.keys({...n.indicator,...n.strategy?.config}).length>0}function ss(t){let e=t??{},n=e.fullContext??e,r={...n.indicator,...n.strategy?.config},i={title:z(r.title)??"Indicator",overlay:Du(r.overlay)??!1,precision:he(r.precision),shorttitle:z(r.shorttitle),format:z(r.format)},s=n.plots??{},a=Object.entries(s).map(([l,c])=>{let u=c??{},p=u.options??{};return{key:l,title:z(u.title),style:z(p.style),options:p,data:Array.isArray(u.data)?Kw(u.data):[],plot1:z(u.plot1)??z(p.plot1),plot2:z(u.plot2)??z(p.plot2)}}),o=n.strategy?Yw(n.strategy):void 0;return{meta:i,plots:a,...o?{trades:o}:{}}}function Yw(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=he(s.entry_price),o=he(s.entry_time),l=he(s.size);a===void 0||o===void 0||l===void 0||l===0||e.push({id:z(s.id)??`trade_${e.length}`,entry_id:z(s.entry_id)??"",entry_price:a,entry_time:o,entry_comment:z(s.entry_comment),exit_id:z(s.exit_id),exit_price:he(s.exit_price),exit_time:he(s.exit_time),exit_comment:z(s.exit_comment),size:l,status:s.status==="closed"?"closed":"open"})}return e}var Gw={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 Ru(t){return t==null||t===""?"line":Gw[t]??"line"}function as(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 ce(t,e){return as(t)?t.trim():e}var Ou="#00000000";var Vn="#2962ff",Mo="#38c0fd",Ft="#089981",tn="#f23645",$n="#787b86";var To="#ff9800",Wn="#5b9cf6",Po="#ff5d00",Do="#0ecb81",Ro="#f6465d";var Xw=new Map;function R(t,e){Xw.set(t,e)}function Zw(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 T(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 q=Zw;R("style-candles",q(\'<path d="M4.5 2v2M4.5 12v2M11.5 2v1.5M11.5 11v3"/><rect x="2.8" y="4" width="3.4" height="8" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="3.5" width="3.4" height="7.5" rx="0.6" fill="currentColor"/>\'));R("style-bars",q(\'<path d="M4.5 2.5v11M2.5 5h2M4.5 11h2"/><path d="M11.5 2.5v11M9.5 4.5h2M11.5 10.5h2"/>\'));R("style-line",q(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/>\'));R("style-area",q(\'<path d="M1.5 11.5 5.5 7l3 2.5 5-6"/><path d="M1.5 11.5 5.5 7l3 2.5 5-6V13.5h-12z" fill="currentColor" fill-opacity="0.25" stroke="none"/>\'));R("style-baseline",q(\'<path d="M1.5 8h13" stroke-dasharray="2 2"/><path d="M2.5 8 5.25 4.5 8 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M2.5 8 5.25 4.5 8 8"/><path d="M8 8l2.75 3.5L13.5 8h-5.5z" fill="currentColor" fill-opacity="0.25" stroke="none"/><path d="M8 8l2.75 3.5L13.5 8"/>\'));R("style-heikinashi",q(\'<path d="M4.5 12v2M11.5 2v2"/><rect x="2.8" y="5" width="3.4" height="7" rx="0.6" fill="currentColor" fill-opacity="0.25"/><rect x="9.8" y="4" width="3.4" height="7" rx="0.6" fill="currentColor"/>\'));R("indicators",q(\'<path d="M1.5 12.5 5 7l2.5 3.5L11 4l3.5 5"/><circle cx="11" cy="4" r="1.4" fill="currentColor" stroke="none"/>\'));R("undo",q(\'<path d="M6.2 9.5 2.7 6l3.5-3.5"/><path d="M2.7 6h6.8a3.65 3.65 0 0 1 0 7.3H7.5"/>\'));R("redo",q(\'<path d="M9.8 9.5 13.3 6 9.8 2.5"/><path d="M13.3 6H6.5a3.65 3.65 0 0 0 0 7.3h2"/>\'));R("objects",q(\'<path d="M8 1.8 14 5 8 8.2 2 5z"/><path d="M2 8l6 3.2L14 8" opacity="0.7"/><path d="M2 11l6 3.2 6-3.2" opacity="0.4"/>\'));R("clock",q(\'<circle cx="8" cy="8" r="6.2"/><path d="M8 4.8V8l2.4 1.6"/>\'));R("calendar",q(\'<rect x="2.2" y="3.2" width="11.6" height="10.6" rx="1.4"/><path d="M5.2 1.8v2.8M10.8 1.8v2.8M2.2 6.8h11.6"/>\'));R("datawindow",q(\'<rect x="1.8" y="2.5" width="12.4" height="11" rx="1.5"/><path d="M4.5 5.5h4M4.5 8h7M4.5 10.5h5.5"/>\'));R("camera",q(\'<path d="M5.5 4 6.5 2.5h3L10.5 4h3A1 1 0 0 1 14.5 5v7.5a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1z"/><circle cx="8" cy="8.5" r="2.6"/>\'));R("gear",q(\'<path d="M6.55 1.4h2.9l.32 1.72c.48.14.92.38 1.3.7l1.66-.55 1.45 2.5-1.35 1.1c.08.34.12.7.12 1.07s-.04.73-.12 1.07l1.35 1.1-1.45 2.5-1.66-.55a4.3 4.3 0 0 1-1.3.7L9.45 14.6h-2.9l-.32-1.72a4.3 4.3 0 0 1-1.3-.7l-1.66.55-1.45-2.5 1.35-1.1A4.4 4.4 0 0 1 3.05 7.94c0-.37.04-.73.12-1.07l-1.35-1.1 1.45-2.5 1.66.55c.38-.32.82-.56 1.3-.7L6.55 1.4z"/><circle cx="8" cy="8" r="2.2"/>\'));R("search",q(\'<circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3.5 3.5"/>\'));R("bell",q(\'<path d="M8 2a4 4 0 0 0-4 4v2.5L2.5 11v1h11v-1L12 8.5V6a4 4 0 0 0-4-4z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/>\'));R("market-open",T(\'<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",T(\'<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",T(\'<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",T(\'<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",T(\'<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>\'));R("market-holiday",T(\'<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",q(\'<path d="m6 3.5 4.5 4.5L6 12.5"/>\'));R("chevron-left",q(\'<path d="M10 3.5 5.5 8l4.5 4.5"/>\'));R("chevron-down",q(\'<path d="M3.5 6 8 10.5 12.5 6"/>\'));R("chevron-up",q(\'<path d="M3.5 10 8 5.5 12.5 10"/>\'));R("chevrons-right",q(\'<path d="m4 3.5 4.5 4.5L4 12.5"/><path d="m8.5 3.5 4.5 4.5-4.5 4.5"/>\'));R("chevrons-left",q(\'<path d="M12 3.5 7.5 8l4.5 4.5"/><path d="M7.5 3.5 3 8l4.5 4.5"/>\'));R("replay",q(\'<path d="M14 4.2v7.6L8.6 8z"/><path d="M7.4 4.2v7.6L2 8z"/>\'));R("check",q(\'<path d="m2.8 8.4 3.4 3.4 7-7.6"/>\'));R("close",q(\'<path d="m3.8 3.8 8.4 8.4M12.2 3.8l-8.4 8.4"/>\'));R("pin",q(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/>\'));R("pin-filled",q(\'<path d="M5.6 2.5h4.8M6.4 2.5v3.6L4.4 8.4v.9h7.2v-.9L9.6 6.1V2.5M8 9.3v4.2"/><path d="M6.4 2.5h3.2v3.6l2 2.3v.9H4.4v-.9l2-2.3z" fill="currentColor" stroke="none"/>\'));R("eye",q(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="1.8"/>\'));R("eye-off",q(\'<path d="M1.5 8s2.5-5.4 6.5-5.4S14.5 8 14.5 8 12 13.4 8 13.4 1.5 8 1.5 8z" opacity="0.45"/><path d="m3 13 10-10"/>\'));R("lock",q(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.8 0V7"/>\'));R("unlock",q(\'<rect x="3.2" y="7" width="9.6" height="6.6" rx="1.2"/><path d="M5.6 7V5.2a2.4 2.4 0 0 1 4.7-.7"/>\'));R("trash",q(\'<path d="M2.5 4.3h11M6.2 4.3V3.1a1 1 0 0 1 1-1h1.6a1 1 0 0 1 1 1v1.2M4.2 4.3l.5 9.1a1.15 1.15 0 0 0 1.15 1.1h4.3a1.15 1.15 0 0 0 1.15-1.1l.5-9.1M6.5 7v4.5M9.5 7v4.5"/>\'));R("group",q(\'<path d="M1.8 4.5V2.4a.6.6 0 0 1 .6-.6h2.1M11.5 1.8h2.1a.6.6 0 0 1 .6.6v2.1M14.2 11.5v2.1a.6.6 0 0 1-.6.6h-2.1M4.5 14.2H2.4a.6.6 0 0 1-.6-.6v-2.1"/><rect x="4" y="4" width="4.2" height="4.2" rx="0.7"/><rect x="7.8" y="7.8" width="4.2" height="4.2" rx="0.7"/>\'));R("ungroup",q(\'<rect x="1.6" y="1.6" width="6.2" height="6.2" rx="0.9"/><rect x="8.2" y="8.2" width="6.2" height="6.2" rx="0.9" stroke-dasharray="2 1.5"/>\'));R("clone",q(\'<rect x="5.5" y="5.5" width="9" height="9" rx="1.2"/><path d="M11 5.5v-3a1 1 0 0 0-1-1H2.5a1 1 0 0 0-1 1V10a1 1 0 0 0 1 1h3"/>\'));R("arrow-up",q(\'<path d="M8 13.2V3M4.2 6.8 8 3l3.8 3.8"/>\'));R("arrow-down",q(\'<path d="M8 2.8V13M4.2 9.2 8 13l3.8-3.8"/>\'));R("move-vertical",q(\'<path d="M8 2.5v11M5 5.5 8 2.5l3 3M5 10.5l3 3 3-3"/>\'));R("move",q(\'<path d="M8 1.8v12.4M1.8 8h12.4M5.6 4.2 8 1.8l2.4 2.4M5.6 11.8 8 14.2l2.4-2.4M4.2 5.6 1.8 8l2.4 2.4M11.8 5.6 14.2 8l-2.4 2.4"/>\'));R("pen",q(\'<path d="m10.8 2.2 3 3-8 8-3.6.6.6-3.6z"/><path d="m9.2 3.8 3 3"/>\'));R("wave",q(\'<path d="M1.5 10.4c1.6 0 1.9-4.8 3.4-4.8s1.8 4.8 3.4 4.8 1.8-4.8 3.4-4.8 1.6 4.8 2.8 4.8"/>\'));R("folder-plus",q(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M8 7.6v3.6M6.2 9.4h3.6"/>\'));R("folder-minus",q(\'<path d="M1.6 4.4a1 1 0 0 1 1-1h2.7l1.3 1.7h6.8a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-10.8a1 1 0 0 1-1-1z"/><path d="M6.2 9.4h3.6"/>\'));R("collapse",q(\'<path d="M3 8h10"/>\'));R("expand",q(\'<rect x="2.2" y="2.2" width="11.6" height="11.6" rx="1.4"/><path d="M8 5.4v5.2M5.4 8h5.2"/>\'));R("plus",q(\'<path d="M8 2.8v10.4M2.8 8h10.4"/>\'));R("minus",q(\'<path d="M2.8 8h10.4"/>\'));R("maximize",q(\'<path d="M2.5 6V3a.5.5 0 0 1 .5-.5h3M10 2.5h3a.5.5 0 0 1 .5.5v3M13.5 10v3a.5.5 0 0 1-.5.5h-3M6 13.5H3a.5.5 0 0 1-.5-.5v-3"/>\'));R("restore",q(\'<path d="M6.2 2.5v3.7H2.5M9.8 13.5V9.8h3.7M13.5 6.2H9.8V2.5M2.5 9.8h3.7v3.7"/>\'));R("star",q(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\'));R("star-filled",q(\'<path d="M8 2.2l1.75 3.55 3.9.55-2.8 2.75.65 3.9L8 11.1l-3.5 1.85.65-3.9-2.8-2.75 3.9-.55z"/>\',\'fill="currentColor"\'));R("grip",q(\'<circle cx="6" cy="3.5" r="1"/><circle cx="10" cy="3.5" r="1"/><circle cx="6" cy="8" r="1"/><circle cx="10" cy="8" r="1"/><circle cx="6" cy="12.5" r="1"/><circle cx="10" cy="12.5" r="1"/>\',\'fill="currentColor" stroke="none"\'));R("kebab",q(\'<circle cx="8" cy="3.2" r="1.2"/><circle cx="8" cy="8" r="1.2"/><circle cx="8" cy="12.8" r="1.2"/>\',\'fill="currentColor" stroke="none"\'));R("burger",q(\'<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>\'));R("info",q(\'<path d="M8 7.4v4.4"/><circle cx="8" cy="4.6" r="0.9" fill="currentColor" stroke="none"/>\'));R("reset",q(\'<path d="M2 8a6 6 0 1 0 6-6 6.5 6.5 0 0 0-4.5 1.83L2 5.33"/><path d="M2 2v3.33h3.33"/>\'));R("pane-collapse",q(\'<path d="M2.6 9.4h4v4M13.4 6.6h-4v-4"/><path d="m9.4 6.6 4.2-4.2M2.4 13.6l4.2-4.2"/>\'));R("pane-expand",q(\'<path d="M9.8 2.4h3.8v3.8M6.2 13.6H2.4V9.8"/><path d="m13.6 2.4-4.4 4.4M2.4 13.6l4.4-4.4"/>\'));R("cursor",T(\'<path d="M5 3l6 16 2-6 6-2z"/>\',\'fill="currentColor" stroke="none"\'));R("ruler",T(\'<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",T(\'<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",T(\'<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",T(\'<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",T(\'<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",T(\'<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",T(\'<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",T(\'<path d="M5 6V4.5h14V6"/><path d="M12 4.5v15"/><path d="M9.5 19.5h5"/>\'));R("bold",T(\'<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",T(\'<path d="M15 5h-5M14 19H9M14.5 5 10 19"/>\',\'stroke-width="2.2"\'));R("price-delta",T(\'<path d="M12 4v16"/><path d="M8 8l4-4 4 4"/><path d="M8 16l4 4 4-4"/>\'));R("date-delta",T(\'<path d="M4 12h16"/><path d="M8 8l-4 4 4 4"/><path d="M16 8l4 4-4 4"/>\'));R("bring-front",T(\'<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",T(\'<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",T(\'<path d="M3 6h18"/><path d="M3 18h18"/><path d="M3 12h18" stroke-dasharray="3 3"/>\'));R("dedekind",T(\'<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",T(\'<circle cx="15" cy="12" r="4"/><circle cx="12" cy="12" r="2.5"/><path d="M8 5v14"/>\'));R("supersonic",T(\'<circle cx="16" cy="12" r="3.5"/><path d="M6 12 15 6M6 12 15 18"/>\'));var O=Mo;function Qw(){return{lineColor:O,lineWidth:2,lineStyle:"solid"}}function ls(t=""){return{value:t,size:"normal",hAlign:"left",vAlign:"top"}}var Xu=class Zu{constructor(e){this.locked=!1,this.visible=!0,this.zIndex=0,this.id=e.id??`dw-${Zu.seq+=1}`,this.paneId=e.paneId,this.anchors=(e.anchors??[]).map(n=>({time:n.time,price:n.price})),this.style=e.style?{...e.style}:Qw(),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=ls()),Jw(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){}};Xu.seq=0;var ge=Xu;function Jw(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 hr=[{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:hr,group:"line"}],ot=[{path:"style.fillColor",label:"Fill color",kind:"color",group:"fill"}],Lo=[{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:Lo,group:"text"},{path:"text.bold",label:"Bold",kind:"boolean",group:"text"},{path:"text.italic",label:"Italic",kind:"boolean",group:"text"}];function Ve(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 Fo(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=Ve(t,e,s[0],s[1],a[0],a[1]);o<r&&(r=o)}return r}function cn(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 Yr(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 _e(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 Qe(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 eS=class extends ge{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&&Ve(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 _e(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]}}},tS=class extends ge{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 _e(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]}}},nS=class extends ge{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]=Qe(i[0],i[1],i[2],i[3],"right",n.width,n.height);return Ve(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 _e(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]}}},Bo=class extends ge{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&&Ve(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 _e(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]}}},rS=class extends Bo{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]=Qe(i[0],i[1],i[2],i[3],"both",n.width,n.height);return Ve(t,e,s,a,o,l)<=r}timeExtent(){return null}},iS=class extends ge{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 _e(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]}}},sS=class extends ge{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&&Ve(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 _e(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]}}},aS=class extends ge{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 _e(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]}}},oS=class extends Bo{constructor(){super(...arguments),this.type="infoline"}},lS=class extends Bo{constructor(){super(...arguments),this.type="trendangle"}},cS=class extends ge{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&&cn(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=>Ve(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 _e(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]}}},uS={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},Vo=class extends ge{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=uS[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&&cn(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 _e(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}},hS=class extends Vo{constructor(t){super(t),this.type="text",this.text||(this.text={...ls(),size:"large"})}schema(){return{fields:[...se],textIsContent:!0}}},pS=class extends Vo{constructor(t){super(t),this.type="note",this.text||(this.text=ls("Note"))}defaultLabel(){return"Note"}schema(){return{fields:[...re,...ot,...se],textIsContent:!0}}},dS=class extends Vo{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,...ot,...se.filter(t=>t.path!=="text.value")]}}},fS={tiny:10,small:12,normal:14,large:18,huge:24,auto:14},cs=class extends ge{constructor(t){super(t),this.text||(this.text=ls(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=fS[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&&cn(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&&Ve(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 _e(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,...ot,...se],textIsContent:!0}}},mS=class extends cs{constructor(){super(...arguments),this.type="callout"}},yS=class extends cs{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,...ot,...se.filter(t=>t.path!=="text.value")]}}},gS=class extends cs{constructor(){super(...arguments),this.type="comment"}defaultLabel(){return"Comment"}},_S=class extends cs{constructor(){super(...arguments),this.type="signpost"}defaultLabel(){return"Signpost"}},Bt=class extends ge{hitTest(t,e,n,r){let i=this.geometry(n);return i?this.style.fillColor&&i.fill&&Yr(t,e,i.fill)?!0:i.segments.some(s=>Ve(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 _e(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}}},xS=class extends Bt{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,...ot,...se]}}},bS=class extends Bt{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,...ot,...se]}}},vS=class extends Bt{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,...ot,...se]}}},wS=2;function Lu(){return{midColor:$n,midStyle:"solid",upperColor:Ft,upperStyle:"solid",lowerColor:tn,lowerStyle:"solid",upperFill:`${Ft}26`,lowerFill:`${tn}26`,showR2:!0}}function SS(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:wS*p,r2:Math.max(0,Math.min(1,d*d)),n:e}}var ES=class extends ge{constructor(t){super(t),this.type="regressionchannel",this.cachedRange=null,this.reg||(this.reg=Lu())}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?SS(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 Yr(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=>Ve(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 _e(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={...Lu(),...t}}},Fu=`${Wn}00`;function Bu(){return{midColor:Wn,midStyle:"solid",multiplier:1,upperColor:Fu,upperStyle:"solid",lowerColor:Fu,lowerStyle:"solid",bandFill:`${Wn}33`}}function CS(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 NS=class extends ge{constructor(t){super(t),this.type="anchoredvwap",this.cachedRange=null,this.cachedExtent=null,this.vwap||(this.vwap=Bu())}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=CS(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?Yr(t,e,this.bandPolygon(i))?!0:Oo(t,e,i.mid,r)||Oo(t,e,i.upper,r)||Oo(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 _e(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={...Bu(),...t}}};function Oo(t,e,n,r){for(let i=1;i<n.length;i+=1)if(Ve(t,e,n[i-1][0],n[i-1][1],n[i][0],n[i][1])<=r)return!0;return!1}var IS=`${Ft}66`,kS=`${tn}66`,AS=`${Ft}BF`,MS=`${tn}BF`;function Vu(){return{rows:24,valueAreaPct:70,widthPct:35,anchor:"left",upColor:IS,downColor:kS,vaUpColor:AS,vaDownColor:MS,showVah:!0,vahColor:$n,vahStyle:"solid",showVal:!0,valColor:$n,valStyle:"solid",showPoc:!0,pocColor:void 0,pocStyle:"solid",showDevelopingPoc:!1,developingPocColor:Vn,developingPocStyle:"dotted",showDevelopingVa:!1,developingVaColor:Vn,developingVaStyle:"dotted"}}function TS(t,e){return t<0?0:t>=e?e-1:t}function Qu(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 Ju(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(TS(Math.floor((l-e)/n),s));for(let l of o)t[l][a]+=i}function eh(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 PS(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)Ju(o,r,a,d);let l=eh(o);if(!l)return null;let{poc:c,maxTotal:u}=l,{vaFrom:p,vaTo:h}=Qu(o,c,n);return{rows:o,rowH:a,min:r,maxTotal:u,poc:c,vaFrom:p,vaTo:h}}function DS(t,e,n,r){let i=PS(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){Ju(l,s,a,h);let d=eh(l);if(!d)continue;let{poc:f}=d,{vaFrom:m,vaTo:x}=Qu(l,f,n);c.push({time:h.time,price:l[f].price+a/2}),u.push({time:h.time,price:l[x].price+a}),p.push({time:h.time,price:l[m].price})}return{profile:i,developingPoc:c,developingVaHigh:u,developingVaLow:p}}var RS=class extends ge{constructor(t){super(t),this.type="fixedrangevp",this.cachedRange=null,this.frvp||(this.frvp=Vu())}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=DS(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 S=t.yOf(i.min+w*i.rowH,this.paneId);if(S==null)return null;f.push(S)}let m=w=>t.yOf(w,this.paneId),x=i.rows[i.vaTo].price+i.rowH,b=i.rows[i.vaFrom].price,v=i.rows[i.poc].price+i.rowH/2,E=w=>{let S=[];for(let C of w){let k=m(C.price);k!=null&&S.push([t.xOf(C.time),k])}return S};return{x0:Math.min(o,l),x1:Math.max(o,l),anchorX:h,maxW:u,grow:d,profile:i,yEdges:f,vahY:m(x),valY:m(b),pocY:m(v),developingPoc:E(r.developingPoc),developingVaHigh:E(r.developingVaHigh),developingVaLow:E(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(Yr(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&&Ve(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(Ve(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 _e(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:hr,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:hr,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:hr,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:hr,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:hr,group:"line"}]}}writeProps(){return{...this.frvp}}readProps(t){this.frvp={...Vu(),...t}}},OS=class extends Bt{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:[Qe(i[0],i[1],l,c,"right",h,d),Qe(s[0],s[1],s[0]+u,s[1]+p,"right",h,d),Qe(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]}}},th=class extends Bt{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 x=t.yOf(m.price,this.paneId);return x==null?null:[t.xOf(m.time),x]},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:[Qe(o[0],o[1],c,u,"right",d,f),Qe(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Qe(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]}}},LS=class extends th{constructor(){super(...arguments),this.type="schiffpitchfork"}medianStart(t,e){return{time:t.time,price:(t.price+e.price)/2}}},FS=class extends th{constructor(){super(...arguments),this.type="modifiedschiffpitchfork"}medianStart(t,e){return{time:(t.time+e.time)/2,price:(t.price+e.price)/2}}},BS=class extends Bt{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 x=t.yOf(m.price,this.paneId);return x==null?null:[t.xOf(m.time),x]},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:[Qe(c,u,c+p,u+h,"right",d,f),Qe(s[0],s[1],s[0]+p,s[1]+h,"right",d,f),Qe(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]}}},VS=class extends ge{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&&Ve(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 _e(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]}}},$u=48,$S=class extends ge{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<=$u;n+=1){let r=n/$u*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:Fo(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 _e(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,...ot,...se]}}},WS=class extends Bt{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,...ot,...se]}}},jS=512,$o=class extends Bt{anchorSchema(){return{min:2,max:jS,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]}}},US=class extends $o{constructor(){super(...arguments),this.type="polyline"}},nh=class extends $o{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}}},qS=class extends nh{constructor(){super(...arguments),this.type="freehand"}},zS=[{path:"style.lineColor",label:"Color",kind:"color",group:"line"},{path:"style.lineWidth",label:"Width",kind:"number",min:4,max:60,step:1,group:"line"}],HS=class extends nh{constructor(){super(...arguments),this.type="highlighter"}schema(){return{fields:zS}}},KS=class extends ge{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 _e(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,...ot,...se]}}},YS=class extends Bt{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")})),...ot,...se]}}},GS=class extends $o{constructor(){super(...arguments),this.type="path"}},Wu=40,XS=class extends Bt{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 x=0;x<=Wu;x+=1){let b=x/Wu*Math.PI,v=Math.cos(b),E=Math.sin(b);f.push([s+v*o+E*d*u,a+v*l+E*d*p])}let m=[];for(let x=1;x<f.length;x+=1)m.push([f[x-1][0],f[x-1][1],f[x][0],f[x][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")})),...ot,...se]}}},ju=40,ZS=class extends Bt{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<=ju;a+=1){let o=a/ju,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,...ot,...se]}}},QS={head:11,headW:9,stemW:3.5,len:22},rh=class extends ge{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}=QS,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&&Yr(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 _e(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]}}},JS=class extends rh{constructor(){super(...arguments),this.type="arrowmarkup"}dir(){return"up"}},eE=class extends rh{constructor(){super(...arguments),this.type="arrowmarkdown"}dir(){return"down"}},tE=["\\u2605","\\u2606","\\u25CF","\\u25C6","\\u25B2","\\u25BC","\\u27A4","\\u2691","\\u271A","\\u2715","\\u2764","\\u2666"],nE=["small","normal","large","huge"],Uu={small:16,normal:22,large:32,huge:44},ih=class extends ge{constructor(t){super(t),this.glyph||(this.glyph=this.defaultGlyph()),this.size||(this.size="normal")}sizePx(){return Uu[this.size]??Uu.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 _e(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:tE.map(t=>({value:t,label:t})),group:"line"},{path:"size",label:"Size",kind:"select",options:nE.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)}},rE=class extends ih{constructor(){super(...arguments),this.type="flagmark"}defaultGlyph(){return"\\u2691"}},iE=class extends ih{constructor(){super(...arguments),this.type="iconstamp"}defaultGlyph(){return"\\u2605"}},qu=t=>t==="small"||t==="normal"||t==="large"||t==="huge";function sE(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 Vt=class extends ge{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=>Ve(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 _e(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(sE).filter(n=>n!=null);e.length&&(this.levels=e)}qu(t.numbersSize)&&(this.numbersSize=t.numbersSize),qu(t.labelsSize)&&(this.labelsSize=t.labelsSize)}},sh=class extends Vt{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)}}},pr=$n,jn=tn,Un=To,os="#4caf50",Kr=Ft,qn=Wn,us="#9c27b0",aE="#e91e63",ah="#26a69a",oE="#ab47bc",lE="#ef5350",cE="#ffb74d",uE="#38c0fd",oh="#b2b5be",Hr=[uE,qn,Kr,os,Un,jn,aE,us,pr,ah,oE,lE];function lh(t){return Hr[(t%Hr.length+Hr.length)%Hr.length]}var hE=[[0,pr],[.125,jn],[.236,jn],[.25,jn],[.382,Un],[.5,os],[.618,Kr],[.75,qn],[.786,qn],[1,pr],[1.272,qn],[1.382,Un],[1.618,jn],[2,pr],[2.382,Un],[2.618,Un],[3,pr],[4.236,os],[6.854,Kr],[11.09,qn]];function pE(t,e=0){return hE.find(([n])=>n===t)?.[1]??lh(e)}function lt(t){return t.map((e,n)=>{let r=typeof e=="number"?{ratio:e}:e;return{ratio:r.ratio,color:r.color??pE(r.ratio,n),enabled:r.enabled!==!1,...r.label?{label:r.label}:{}}})}function dE(t,e=t){return Array.from({length:t},(n,r)=>({ratio:r+1,color:lh(r),enabled:r<e,label:String(r+1)}))}var fE=lt([0,.236,.382,.5,.618,.786,1]),mE=class extends sh{constructor(){super(...arguments),this.type="fibretracement"}defaultLevels(){return fE}},yE=lt([0,.382,.618,1,1.272,1.618,{ratio:2.618,color:us}]),gE=class extends sh{constructor(){super(...arguments),this.type="fibextension"}defaultLevels(){return yE}},_E=lt([0,.382,.5,.618,1,1.618,{ratio:2.618,color:us}]),xE=class extends Vt{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 _E}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)}}},bE=lt([.236,.382,.5,.618,.786,1]),vE=class extends Vt{constructor(){super(...arguments),this.type="fibfan"}defaultLevels(){return bE}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]=Qe(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)}}},wE=[0,1,2,3,5,8,13,21,34].map(t=>({ratio:t,color:O,enabled:!0})),SE=class extends Vt{constructor(){super(...arguments),this.type="fibtimezones"}defaultLevels(){return wE}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}},EE=lt([0,.236,.382,.5,.618,.786,1,1.618,2.618]),CE=class extends Vt{constructor(){super(...arguments),this.type="fibchannel"}defaultLevels(){return EE}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}},NE=lt([0,.236,.382,.5,.618,.786,1]),IE=class extends Vt{constructor(){super(...arguments),this.type="fibspeedfan"}defaultLevels(){return NE}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,x=Qe(s,r,f,m,c,u,p);if(h.push({color:d.color,label:d.label,x1:x[0],y1:x[1],x2:x[2],y2:x[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,E=Qe(s,r,b,v,c,u,p);h.push({color:d.color,label:d.label,x1:E[0],y1:E[1],x2:E[2],y2:E[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)}}},kE=lt([0,.382,{ratio:.5,enabled:!1},.618,1,1.382,1.618,2,2.382,2.618,3]),AE=class extends Vt{constructor(){super(...arguments),this.type="trendfibtime"}defaultLevels(){return kE}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 ME(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 Wo=class extends Vt{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(ME(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=>Ve(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)}}},TE=lt([.236,.382,.5,.618,.786,1,1.618,2.618]),PE=class extends Wo{constructor(){super(...arguments),this.type="fibcircles"}defaultLevels(){return TE}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}}},DE=lt([.236,.382,.5,.618,.786,1,1.618,2.618]),RE=class extends Wo{constructor(){super(...arguments),this.type="fibarcs"}defaultLevels(){return DE}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]]:[]}},OE=lt([.236,.382,.5,.618,.786,1]),LE=class extends Wo{constructor(){super(...arguments),this.type="fibwedge"}defaultLevels(){return OE}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}},FE=1.6180339887,zu=Math.log(FE)/(Math.PI/2),BE=Math.PI/64,VE=Math.PI,$E=.5,WE=class extends ge{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($E/o)/zu,-8*Math.PI*2),u=[];for(let p=c;p<=VE;p+=BE){let h=o*Math.exp(zu*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&&Fo(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 _e(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]}}},jE=lt([{ratio:.125,color:jn,label:"1/8"},{ratio:.25,color:Un,label:"1/4"},{ratio:.333,color:cE,label:"1/3"},{ratio:.5,color:os,label:"1/2"},{ratio:1,color:oh,label:"1/1"},{ratio:2,color:Kr,label:"2/1"},{ratio:3,color:qn,label:"3/1"},{ratio:4,color:ah,label:"4/1"},{ratio:8,color:us,label:"8/1"}]),UE=class extends Vt{constructor(){super(...arguments),this.type="gannfan"}defaultLevels(){return jE}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]=Qe(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)}}},qE=lt([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),zE=class extends Vt{constructor(){super(...arguments),this.type="gannbox"}defaultLevels(){return qE}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??pr;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&&cn(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)}}},HE=lt([0,.25,.382,.5,.618,.75,1].map(t=>({ratio:t,label:String(t)}))),KE=[{label:"3x1",x:3,y:1,color:jn},{label:"2x1",x:2,y:1,color:Un},{label:"1x1",x:1,y:1,color:oh},{label:"1x2",x:1,y:2,color:Kr},{label:"1x3",x:1,y:3,color:qn}];var YE=class extends Vt{constructor(){super(...arguments),this.type="gannsquare"}defaultLevels(){return HE}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 KE){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&&cn(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 GE=24,XE=.75;function ZE(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 QE(t){let e=[];for(let n=0;n<t;n+=1)ZE(n,t)&&e.push(n);return e}var JE=class extends ge{constructor(t){super(t),this.type="dedekind",this.maxCurvature===void 0&&(this.maxCurvature=GE)}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 x=n+(m/2-a)*s;x<n-.5||x>p+.5||h.push({kind:"vline",x,y0:i,y1:r})}for(let m=1;m<=l;m+=1){let x=1/m,b=x*s;if(b<XE)continue;let v=QE(m);if(v.length===0)continue;let E=Math.floor(c)-1,w=Math.ceil(u)+1;for(let S=E;S<=w;S+=1)for(let C of v){let k=C/m+S;if(k+x<c||k-x>u)continue;let B=n+(k-a)*s;B+b<n-1||B-b>p+1||h.push({kind:"arc",cx:B,cy:i,r:b})}}return h}hitTest(t,e,n,r){let i=this.box(n);return i!=null&&cn(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 _e(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 hs=6,eC=2;function ch(t=hs){return[...dE(Hr.length,t)]}function tC(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 ps={path:"showRatios",label:"Show ratios",kind:"boolean",group:"behavior"},ds=class extends ge{constructor(t){super(t),this.waveCount===void 0&&(this.waveCount=hs),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(S=>S.enabled&&S.ratio>0).slice().sort((S,C)=>S.ratio-C.ratio);if(d.length===0)return null;let f=Math.max(1,this.machNumber()),m=[];for(let S of d){let C=S.ratio*c;m.push({cx:o+f*(C-c)*u,cy:l+f*(C-c)*p,r:C,color:S.color,ratio:S.ratio})}let x=o-f*c*u,b=l-f*c*p,v=m[m.length-1].r,E=f*v+2*c,w=[];if(f<=1+1e-9){let S=-p,C=u;w.push([x-S*E,b-C*E,x+S*E,b+C*E])}else{let S=Math.asin(1/f),C=Math.cos(S),k=Math.sin(S),B=(F,I,U)=>[F*C-I*U*k,F*U*k+I*C],[P,V]=B(u,p,1),[A,H]=B(u,p,-1);w.push([x,b,x+P*E,b+V*E]),w.push([x,b,x+A*E,b+H*E])}return{c0x:o,c0y:l,R:c,fx:u,fy:p,noseX:x,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=>Ve(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 _e(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"},ps,...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(tC).filter(n=>n!=null);e.length&&(this.levels=e)}}},nC=class extends ds{constructor(){super(...arguments),this.type="sonic"}defaultLevels(){return ch(hs)}machNumber(){return 1}},rC=class extends ds{constructor(t){super(t),this.type="supersonic",this.mach===void 0&&(this.mach=eC)}defaultLevels(){return ch(hs)}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"},ps,...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)))}},uh=lt([.236,.382,.5,.618,.786,1,1.618,2.618,4.236,6.854,11.09]),iC=2,sC=class extends ds{constructor(){super(...arguments),this.type="goldensonic"}shouldSyncWaveCount(){return!1}defaultLevels(){return uh}machNumber(){return 1}schema(){return{fields:[...re,ps,...se]}}},aC=class extends ds{constructor(t){super(t),this.type="goldensupersonic",this.mach===void 0&&(this.mach=iC)}shouldSyncWaveCount(){return!1}defaultLevels(){return uh}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"},ps,...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)))}},dr=class extends ge{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&&Fo(t,e,i)<=r}hitHandle(t,e,n,r){return _e(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?ot:[]]}}},oC=class extends dr{constructor(){super(...arguments),this.type="xabcd"}vertexLabels(){return["X","A","B","C","D"]}legRatios(){return!0}fillTriangles(){return[[0,1,2],[2,3,4]]}},lC=class extends dr{constructor(){super(...arguments),this.type="abcd"}vertexLabels(){return["A","B","C","D"]}legRatios(){return!0}},cC=class extends dr{constructor(){super(...arguments),this.type="elliottimpulse"}vertexLabels(){return["1","2","3","4","5"]}},uC=class extends dr{constructor(){super(...arguments),this.type="elliottcorrection"}vertexLabels(){return["A","B","C"]}},hC=class extends dr{constructor(){super(...arguments),this.type="headshoulders"}vertexLabels(){return["","LS","","H","","RS",""]}necklineIndices(){return[2,4]}},fr=class extends dr{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)}},pC=class extends fr{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}}}},dC=class extends fr{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}}}},fC=class extends fr{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}}}},mC=class extends fr{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}}}},yC=class extends fr{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}}}},gC={min:1.272,max:1.414},_C={min:.74,max:.83},xC=class extends fr{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(),gC)&&this.inBand(this.cdOverXc(),_C)}};function Hu(t){return`${t>=0?"+":""}${t.toFixed(2)}`}function bC(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 vC=class extends ge{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`${Hu(n)} (${Hu(r)}%)`}timeLabel(t){let e=this.anchors[0],n=this.anchors[1];if(!e||!n)return"";let r=bC(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&&cn(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 _e(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:Lo,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)}},wC=class extends vC{constructor(){super(...arguments),this.type="datepricerange"}},SC=[{value:"long",label:"Long"},{value:"short",label:"Short"}],nn=class St extends ge{constructor(e){super(e),this.type="position",this.riskPercent===void 0&&(this.riskPercent=St.DEFAULT_RISK_PERCENT),this.accountBalance===void 0&&(this.accountBalance=St.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=St.DEFAULT_PROFIT_COLOR),this.lossColor===void 0&&(this.lossColor=St.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)>=St.MIN_DRAG_PX?(o=a,l=r+Math.max(Math.abs(e.xOf(s.time)-r),St.MIN_WIDTH_PX)):(o=i-St.DEFAULT_RISK_PX*St.DEFAULT_RR,l=r+St.DEFAULT_WIDTH_PX);let c=i-(o-i)/St.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)/St.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 $${CC(this.dollarLoss())} \\xB7 Size ${NC(this.positionSize())}`}targetLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Ku(e.target)}`:"";return`Target +${this.rewardPct().toFixed(2)}%${n}`}stopLabel(){let e=this.prices(),n=this.showPrices&&e?` @ ${Ku(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 Yu(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 cn(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 _e(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:SC,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:Lo,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)}};nn.DEFAULT_RR=2;nn.MIN_DRAG_PX=6;nn.DEFAULT_RISK_PX=64;nn.DEFAULT_WIDTH_PX=150;nn.MIN_WIDTH_PX=48;nn.DEFAULT_RISK_PERCENT=1;nn.DEFAULT_ACCOUNT_BALANCE=1e4;nn.DEFAULT_PROFIT_COLOR=Do;nn.DEFAULT_LOSS_COLOR=Ro;var EC=nn;function CC(t){if(!Number.isFinite(t))return"0";let e=Math.round(t*100)/100;return Number.isInteger(e)?String(e):e.toFixed(2)}function NC(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 Ku(t){return Number.isFinite(t)?Math.abs(t)>=1?t.toFixed(2):t.toPrecision(4).replace(/\\.?0+$/,""):"0"}function Yu(t){return Math.round(t*1e8)/1e8}var IC=[{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 Gu(){return{timeframe:"auto",upColor:"",downColor:""}}var kC=class extends ge{constructor(t){super(t),this.type="magnifier",this.chipRect=null,this.magnifier||(this.magnifier=Gu())}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?cn(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=>Ve(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 _e(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:IC,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={...Gu(),...t}}},AC=new Map;function L(t){AC.set(t.type,t)}var MC=T(\'<line x1="4" y1="19" x2="20" y2="5"/>\'),TC=T(\'<line x1="3" y1="12" x2="21" y2="12"/>\');L({type:"trendline",group:"lines",label:"Trend Line",icon:MC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new eS(t)});L({type:"hline",group:"lines",label:"Horizontal Line",icon:TC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"dashed"},create:t=>new tS(t)});var PC=T(\'<line x1="3" y1="20" x2="21" y2="6"/><circle cx="3" cy="20" r="1.6" fill="currentColor"/>\'),DC=T(\'<rect x="4" y="6" width="16" height="12" rx="1"/>\'),RC=T(\'<path d="M5 6h14M12 6v13"/>\');L({type:"ray",group:"lines",label:"Ray",icon:PC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new nS(t)});var OC=T(\'<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"/>\'),LC=T(\'<line x1="12" y1="3" x2="12" y2="21"/>\'),FC=T(\'<line x1="5" y1="12" x2="21" y2="12"/><circle cx="5" cy="12" r="1.6" fill="currentColor"/>\'),BC=T(\'<line x1="3" y1="12" x2="21" y2="12"/><line x1="12" y1="3" x2="12" y2="21"/>\'),VC=T(\'<path d="M4 20 20 4"/><rect x="9" y="9" width="9" height="6" rx="1"/>\'),$C=T(\'<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:OC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new rS(t)});L({type:"vline",group:"lines",label:"Vertical Line",icon:LC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new iS(t)});L({type:"hray",group:"lines",label:"Horizontal Ray",icon:FC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new sS(t)});L({type:"crossline",group:"lines",label:"Cross Line",icon:BC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new aS(t)});L({type:"infoline",group:"lines",label:"Info Line",icon:VC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new oS(t)});L({type:"trendangle",group:"lines",label:"Trend Angle",icon:$C,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new lS(t)});L({type:"box",group:"shapes",label:"Rectangle",icon:DC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}26`},create:t=>new cS(t)});L({type:"text",group:"annotations",label:"Text",icon:RC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new hS(t)});var WC=T(\'<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:WC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new mS(t)});var jC=T(\'<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"/>\'),UC=T(\'<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"/>\'),qC=T(\'<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"/>\'),zC=T(\'<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"/>\'),HC=T(\'<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:jC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new pS(t)});L({type:"pricenote",group:"annotations",label:"Price Note",icon:UC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new yS(t)});L({type:"comment",group:"annotations",label:"Comment",icon:qC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new gS(t)});L({type:"pricelabel",group:"annotations",label:"Price Label",icon:zC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new dS(t)});L({type:"signpost",group:"annotations",label:"Signpost",icon:HC,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid",fillColor:`${O}d9`},create:t=>new _S(t)});var KC=T(\'<line x1="3" y1="16" x2="21" y2="8"/><line x1="3" y1="21" x2="21" y2="13"/>\'),YC=T(\'<line x1="3" y1="7" x2="21" y2="10"/><line x1="3" y1="18" x2="21" y2="14"/>\'),GC=T(\'<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:KC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new xS(t)});L({type:"disjointchannel",group:"channels",label:"Disjoint Channel",icon:YC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new bS(t)});var XC=T(\'<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:XC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new vS(t)});var ZC=T(\'<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:ZC,defaultStyle:{lineColor:$n,lineWidth:1,lineStyle:"solid"},create:t=>new ES(t)});L({type:"pitchfork",group:"pitchforks",label:"Pitchfork",icon:GC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new OS(t)});var QC=T(\'<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"/>\'),JC=T(\'<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"/>\'),eN=T(\'<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:QC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new LS(t)});L({type:"modifiedschiffpitchfork",group:"pitchforks",label:"Modified Schiff Pitchfork",icon:JC,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new FS(t)});L({type:"insidepitchfork",group:"pitchforks",label:"Inside Pitchfork",icon:eN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new BS(t)});var tN=T(\'<path d="M7 7h10v10"/><path d="M7 17 17 7"/>\'),nN=T(\'<ellipse cx="12" cy="12" rx="9" ry="6"/>\'),rN=T(\'<path d="M12 4 20 19 4 19Z"/>\');L({type:"arrow",group:"shapes",label:"Arrow",icon:tN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",arrowRight:!0},create:t=>new VS(t)});L({type:"ellipse",group:"shapes",label:"Ellipse",icon:nN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new $S(t)});L({type:"triangle",group:"shapes",label:"Triangle",icon:rN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new WS(t)});var iN=T(\'<polyline points="3 17 9 10 13 14 21 5"/>\'),sN=T(\'<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"/>\'),aN=T(\'<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:iN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new US(t)});L({type:"freehand",group:"shapes",label:"Brush",icon:sN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new qS(t)});L({type:"highlighter",group:"shapes",label:"Highlighter",icon:aN,defaultStyle:{lineColor:`${Po}59`,lineWidth:14,lineStyle:"solid"},create:t=>new HS(t)});var oN=T(\'<circle cx="12" cy="12" r="8"/>\'),lN=T(\'<path d="M5 14 9.5 5 19 10 14.5 19 Z"/>\'),cN=T(\'<path d="M4 19 9 11 13 14 17 8 20 4"/><path d="M17.2 5.5 20 4 19.4 7.1"/>\'),uN=T(\'<path d="M4 17a8 8 0 0 1 16 0"/><path d="M4 17 20 17"/>\'),hN=T(\'<path d="M4 18Q12 1 20 14"/>\'),pN=T(\'<path d="M12 5 12 19"/><path d="M6 11 12 5 18 11"/>\'),dN=T(\'<path d="M12 5 12 19"/><path d="M6 13 12 19 18 13"/>\');L({type:"circle",group:"shapes",label:"Circle",icon:oN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}1a`},create:t=>new KS(t)});L({type:"rotatedrect",group:"shapes",label:"Rotated Rectangle",icon:lN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}26`},create:t=>new YS(t)});L({type:"path",group:"shapes",label:"Path",icon:cN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new GS(t)});L({type:"arc",group:"shapes",label:"Arc",icon:uN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid",fillColor:`${O}26`},create:t=>new XS(t)});L({type:"curve",group:"shapes",label:"Curve",icon:hN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new ZS(t)});L({type:"arrowmarkup",group:"shapes",label:"Arrow Mark Up",icon:pN,defaultStyle:{lineColor:Ft,lineWidth:1,lineStyle:"solid"},create:t=>new JS(t)});L({type:"arrowmarkdown",group:"shapes",label:"Arrow Mark Down",icon:dN,defaultStyle:{lineColor:tn,lineWidth:1,lineStyle:"solid"},create:t=>new eE(t)});var fN=T(\'<path d="M6 21V4"/><path d="M6 5h11l-2.5 3.5L17 12H6" fill="currentColor" stroke="none"/>\'),mN=T(\'<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:fN,defaultStyle:{lineColor:Vn,lineWidth:1,lineStyle:"solid"},create:t=>new rE(t)});L({type:"iconstamp",group:"stamps",label:"Icon",icon:mN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new iE(t)});var yN=T(\'<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"/>\'),gN=T(\'<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:yN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new mE(t)});L({type:"fibextension",group:"fibonacci",label:"Fib Extension",icon:gN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new gE(t)});var _N=T(\'<path d="M3 20 10 9l4 5"/><path d="M14 14h7M14 9h7M14 4h7"/>\');L({type:"fibextensiontrend",group:"fibonacci",label:"Trend-Based Fib Extension",icon:_N,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new xE(t)});var xN=T(\'<path d="M4 20 20 5M4 20 21 11M4 20 21 17M4 20 20 20"/>\'),bN=T(\'<path d="M3 5v14M6 5v14M11 5v14M19 5v14"/>\');L({type:"fibfan",group:"fibonacci",label:"Fib Fan",icon:xN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new vE(t)});L({type:"fibtimezones",group:"fibonacci",label:"Fib Time Zones",icon:bN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"dashed"},create:t=>new SE(t)});var vN=T(\'<path d="M3 18 18 9M5 21 20 12M6 13 21 4"/>\'),wN=T(\'<path d="M4 4 20 20M4 4 20 12M4 4 12 20M4 4 20 4M4 4 4 20"/>\'),SN=T(\'<path d="M3 19 9 8M9 8 12 5v14M14 5v14M18 5v14M21 5v14"/>\');L({type:"fibchannel",group:"fibonacci",label:"Fib Channel",icon:vN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new CE(t)});L({type:"fibspeedfan",group:"fibonacci",label:"Fib Speed Resistance Fan",icon:wN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new IE(t)});L({type:"trendfibtime",group:"fibonacci",label:"Trend-Based Fib Time",icon:SN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"dashed"},create:t=>new AE(t)});var EN=T(\'<circle cx="12" cy="12" r="3"/><circle cx="12" cy="12" r="6.5"/><circle cx="12" cy="12" r="10"/>\'),CN=T(\'<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"/>\'),NN=T(\'<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"/>\'),IN=T(\'<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:EN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new PE(t)});L({type:"fibarcs",group:"fibonacci",label:"Fib Speed Resistance Arcs",icon:CN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new RE(t)});L({type:"fibwedge",group:"fibonacci",label:"Fib Wedge",icon:NN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new LE(t)});L({type:"fibspiral",group:"fibonacci",label:"Fib Spiral",icon:IN,defaultStyle:{lineColor:O,lineWidth:2,lineStyle:"solid"},create:t=>new WE(t)});var kN=T(\'<path d="M4 20 20 20M4 20 20 13M4 20 20 6M4 20 15 4M4 20 9 4M4 20 4 4"/>\'),AN=T(\'<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:kN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new UE(t)});L({type:"gannbox",group:"fibonacci",label:"Gann Box",icon:AN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new zE(t)});var MN=T(\'<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:MN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new YE(t)});var TN=T(\'<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:TN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new JE(t)});var PN=T(\'<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"/>\'),DN=T(\'<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:PN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new nC(t)});L({type:"supersonic",group:"geometry",label:"Supersonic",icon:DN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new rC(t)});var RN=T(\'<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"/>\'),ON=T(\'<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:RN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new sC(t)});L({type:"goldensupersonic",group:"geometry",label:"Golden Supersonic",icon:ON,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new aC(t)});var LN=T(\'<path d="M3 18 7 8 11 14 15 6 20 16"/>\'),FN=T(\'<path d="M4 17 9 7 14 15 20 5"/>\'),BN=T(\'<path d="M3 19 8 9 12 13 17 5 21 9"/>\'),VN=T(\'<path d="M4 7 11 16 20 9"/>\'),$N=T(\'<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:LN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new oC(t)});L({type:"abcd",group:"patterns",label:"ABCD Pattern",icon:FN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new lC(t)});L({type:"elliottimpulse",group:"patterns",label:"Elliott Impulse Wave (1-5)",icon:BN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new cC(t)});L({type:"elliottcorrection",group:"patterns",label:"Elliott Correction Wave (ABC)",icon:VN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new uC(t)});L({type:"headshoulders",group:"patterns",label:"Head & Shoulders",icon:$N,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new hC(t)});var WN=T(\'<path d="M3 17 7 6 12 14 17 5 21 16"/><path d="M3 17 21 16" opacity="0.45"/>\'),mr={group:"patterns",icon:WN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"}};L({type:"gartley",label:"Gartley",...mr,create:t=>new pC(t)});L({type:"bat",label:"Bat",...mr,create:t=>new dC(t)});L({type:"butterfly",label:"Butterfly",...mr,create:t=>new fC(t)});L({type:"crab",label:"Crab",...mr,create:t=>new mC(t)});L({type:"shark",label:"Shark",...mr,create:t=>new yC(t)});L({type:"cypher",label:"Cypher",...mr,create:t=>new xC(t)});var jN=T(\'<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:jN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new wC(t)});var UN=T(\'<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:UN,defaultStyle:{lineColor:O,lineWidth:1,lineStyle:"solid"},create:t=>new EC(t)});var qN=T(\'<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:qN,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 kC(t)});var zN=T(\'<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:zN,defaultStyle:{lineColor:Wn,lineWidth:2,lineStyle:"solid"},create:t=>new NS(t)});var HN=T(\'<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:HN,defaultStyle:{lineColor:Ft,lineWidth:1,lineStyle:"solid"},create:t=>new RS(t)});function jo(t){let e=t.title.trim().toLowerCase().replace(/\\s+/g,"-");return`${t.instanceId}:${t.kind}:${e}#${t.ordinal}`}var KN=["symbol","timeframes","style","layout","indicators","actions","undo-redo","alerts","panels","screenshot"];var hh=["indicators","screenshot"],Q2=new Set(hh),J2=new Set(KN);var ph=280;var eI=`\n.vela-panel[hidden] { display: none !important; }\n.vela-panel {\n position: relative;\n width: var(--vela-panel-w, ${ph}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 fs=class{constructor(){cl(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),jo({instanceId:e,kind:n,title:r,ordinal:s})}};function yr(t){let e=t.data;if(e.length===0)return[];let n=e[e.length-1]?.value;return Array.isArray(n)?n:[]}function ve(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 ms(t){let e=(z(t)??"").toLowerCase();return e==="bt"||e.includes("time")?"bar_time":"bar_index"}function fh(t){let e=(z(t)??"none").toLowerCase();return e==="b"||e==="both"?"both":e==="l"||e==="left"?"left":e==="r"||e==="right"?"right":"none"}function qo(t){let e=(z(t)??"").toLowerCase();return e.includes("dot")?"dotted":e.includes("dash")?"dashed":"solid"}function mh(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 Uo(t,e){let n=ve(t.x1),r=ve(t.y1),i=ve(t.x2),s=ve(t.y2);if(n===void 0||r===void 0||i===void 0||s===void 0)return null;let a=(z(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}=mh(t.color);return{id:e,paneId:"unrouted",xloc:ms(t.xloc),x1:n,y1:r,x2:i,y2:s,extend:fh(t.extend),color:c,invisible:u,width:Math.max(1,ve(t.width)??1),style:qo(t.style),arrowLeft:o,arrowRight:l,overlay:t.force_overlay===!0}}function yh(t,e,n){let r=[];for(let i of yr(t)){if(i._deleted===!0)continue;let s=Uo(i,n.next(e,"line",String(i.id??r.length)));s&&r.push(s)}return r}function gh(t,e,n){let r=[];for(let i of yr(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=Uo(s,`${o}:a`),c=Uo(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 _h(t){return t<=0?"auto":t<=9?"tiny":t<=12?"small":t<=17?"normal":t<=28?"large":"huge"}function YN(t){if(typeof t=="number"&&Number.isFinite(t))return _h(t);let e=(z(t)??"").toLowerCase();return e==="tiny"||e==="small"||e==="normal"||e==="large"||e==="huge"?e:"auto"}function zo(t){let e=(z(t)??"").toLowerCase();return e==="left"||e==="right"?e:"center"}function xh(t){let e=(z(t)??"").toLowerCase();return e==="top"||e==="bottom"?e:"center"}function Ho(t){return(z(t)??"").toLowerCase().includes("mono")?"monospace":"default"}function bh(t,e,n){let r=[];for(let i of yr(t)){if(i._deleted===!0)continue;let s=ve(i.left),a=ve(i.top),o=ve(i.right),l=ve(i.bottom);if(s===void 0||a===void 0||o===void 0||l===void 0)continue;let c=(z(i.text_formatting)??"").toLowerCase(),u=z(i.text);r.push({id:n.next(e,"box",String(i.id??r.length)),paneId:"unrouted",xloc:ms(i.xloc),left:s,top:a,right:o,bottom:l,extend:fh(i.extend),bgColor:ce(i.bgcolor),borderColor:ce(i.border_color),borderWidth:Math.max(0,ve(i.border_width)??1),borderStyle:qo(i.border_style),text:u&&u.length>0?u:void 0,textColor:ce(i.text_color),textSize:YN(i.text_size),hAlign:zo(i.text_halign),vAlign:xh(i.text_valign),wrap:(z(i.text_wrap)??"").toLowerCase().includes("auto"),fontFamily:Ho(i.text_font_family),bold:c.includes("bold"),italic:c.includes("italic"),overlay:i.force_overlay===!0})}return r}var GN=["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 XN(t){let e=(z(t)??"").toLowerCase().replace(/^style_/,"");return GN.includes(e)?e:"label_down"}function ZN(t){let e=(z(t)??"").toLowerCase();return e==="ab"||e.includes("above")?"abovebar":e==="bl"||e.includes("below")?"belowbar":"price"}function vh(t){if(typeof t=="number"&&Number.isFinite(t))return _h(t);let e=(z(t)??"").toLowerCase();return e==="auto"||e==="tiny"||e==="small"||e==="large"||e==="huge"?e:"normal"}function wh(t,e,n){let r=[];for(let i of yr(t)){if(i._deleted===!0)continue;let s=ve(i.x),a=ZN(i.yloc),o=ve(i.y);if(s===void 0||a==="price"&&o===void 0)continue;let l=z(i.text),c=z(i.tooltip),{color:u,invisible:p}=mh(i.color);r.push({id:n.next(e,"label",String(i.id??r.length)),paneId:"unrouted",xloc:ms(i.xloc),x:s,y:o??0,yloc:a,text:l&&l.length>0?l:void 0,style:XN(i.style),color:u,noFill:p,textColor:ce(i.textcolor),size:vh(i.size),textAlign:zo(i.textalign),tooltip:c&&c.length>0?c:void 0,fontFamily:Ho(i.text_font_family),overlay:i.force_overlay===!0})}return r}function Sh(t,e,n){let r=[];for(let i of yr(t)){if(i._deleted===!0)continue;let s=Array.isArray(i.points)?i.points:[],a=ms(i.xloc),o=[];for(let c of s){let u=ve(c.price),p=ve(c.index),h=ve(c.time),d=a==="bar_time"?h:p,f=a==="bar_time"?p:h,m,x;if(d!==void 0)m=d,x=a;else if(f!==void 0)m=f,x=a==="bar_time"?"bar_index":"bar_time";else continue;u!==void 0&&o.push({xloc:x,x:m,price:u})}if(o.length<2)continue;let l=(z(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,ve(i.line_width)??1),lineStyle:qo(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 QN=["top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"];function JN(t){let e=(z(t)??"").toLowerCase();return QN.includes(e)?e:"top_right"}function e2(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:vh(t)}function dh(t){let e=ve(t);return e!==void 0&&e>0?e:void 0}function t2(t){if(!t||typeof t!="object")return null;let e=t,n=z(e.text),r=z(e.tooltip),i=(z(e.text_formatting)??"").toLowerCase();return{text:n&&n.length>0?n:void 0,textColor:ce(e.text_color),bgColor:ce(e.bgcolor),hAlign:zo(e.text_halign),vAlign:xh(e.text_valign),textSize:e2(e.text_size),fontFamily:Ho(e.text_font_family),tooltip:r&&r.length>0?r:void 0,bold:i.includes("bold"),italic:i.includes("italic"),width:dh(e.width),height:dh(e.height),merged:e._merged===!0}}function n2(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=ve(i.startCol??i.start_column??i.startColumn),a=ve(i.startRow??i.start_row),o=ve(i.endCol??i.end_column??i.endColumn),l=ve(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 Eh(t,e,n){let r=[];for(let i of yr(t)){if(i._deleted===!0)continue;let a=(Array.isArray(i.cells)?i.cells:[]).map(l=>(Array.isArray(l)?l:[]).map(c=>t2(c))),o=n2(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:JN(i.position),columns:Math.max(0,Math.round(ve(i.columns)??0)),rows:Math.max(0,Math.round(ve(i.rows)??0)),bgColor:ce(i.bgcolor),frameColor:ce(i.frame_color),frameWidth:Math.max(0,ve(i.frame_width)??0),borderColor:ce(i.border_color),borderWidth:Math.max(0,ve(i.border_width)??0),cells:a,merges:o,overlay:i.force_overlay===!0})}return r}var Nh=Vn;function Ih(t,e){let n=new fs,r=[],i=[],s=[],a=[],o=[],l=[],c=[],u=[],p=[],h=[],d=[],f=[],m=new Map,x=new Set,b=[];for(let w of t.plots){let S=Ru(w.style),C=w.title??w.key;switch(S){case"skip":break;case"barcolor":{if(!Gr(w.options.display))break;let k=Xr(w.data.length,he(w.options.show_last));for(let B=k;B<w.data.length;B+=1){let P=w.data[B],V=ce(P.options?.color);V&&f.push({time:P.time,color:V})}break}case"fill":Gr(w.options.display)&&b.push(w);break;case"hline":{let k=f2(w,C,e,n);k&&o.push(k);break}case"background":Gr(w.options.display)&&a.push(...m2(w,C,e,n));break;case"drawing_line":l.push(...yh(w,e,n));break;case"drawing_box":c.push(...bh(w,e,n));break;case"label":u.push(...wh(w,e,n));break;case"drawing_polyline":p.push(...Sh(w,e,n));break;case"linefill":h.push(...gh(w,e,n));break;case"table":d.push(...Eh(w,e,n));break;case"markers":Gr(w.options.display)&&u.push(...y2(w,e,n));break;default:{let k=n.next(e,S,C);m.set(w.key,k),w.options.force_overlay===!0&&x.add(w.key),i.push(i2(S,w,k,C));let B=l2(w,C,e,n);B&&o.push(B)}}}for(let w of b){let S=w.plot1?m.get(w.plot1):void 0,C=w.plot2?m.get(w.plot2):void 0;if(!S||!C){r.push(`fill "${w.key}" references unknown plots (${w.plot1??"?"}/${w.plot2??"?"})`);continue}let k=x.has(w.plot1)&&x.has(w.plot2);s.push({id:n.next(e,"fill",w.title??w.key),paneId:"unrouted",fromSeriesId:S,toSeriesId:C,...d2(w),...k?{overlay:!0}:{}})}let v=t.trades?r2(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 r2(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 i2(t,e,n,r){let i=he(e.options.show_last),s=e.options.force_overlay===!0?{overlay:!0}:{},a=kh(e.options.display);if(t==="candle"||t==="bar"){let m={id:n,title:r,paneId:"unrouted",kind:t,bars:p2(e,Xr(e.data.length,i)),visible:a.pane,display:a,...s},x=c2(e);return x&&(m.barColors=x),m}let o=t,l=ce(Mh(e)),c={...a,pane:a.pane&&!!l},u=he(e.options.linewidth)??1,p=o==="line"||o==="step"||o==="area",h=h2(o2(u2(e),i,p),he(e.options.offset)),d={color:l??Nh,width:u,lineStyle:Th(e.options.linestyle)??"solid"},f=he(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 Ch={pane:!0,priceScale:!0,legend:!0,dataWindow:!0},s2={pane:"pane",data_window:"dataWindow",status_line:"legend",price_scale:"priceScale"},a2=["all","none","pane","data_window","status_line","price_scale"];function kh(t){if(typeof t!="string")return{...Ch};let e={pane:!1,priceScale:!1,legend:!1,dataWindow:!1};for(let n=0;n<t.length;){let r=a2.find(i=>t.startsWith(i,n));if(!r||r==="all")return{...Ch};r!=="none"&&(e[s2[r]]=!0),n+=r.length}return e}function Gr(t){return kh(t).pane}function Xr(t,e){return e===void 0||e<=0?0:Math.max(0,t-Math.floor(e))}function o2(t,e,n){let r=Xr(t.length,e);return n&&(r-=1),r<=0?t:t.map((i,s)=>s<r?{...i,value:null}:i)}function l2(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(Mh(t)),lineStyle:"dotted",width:he(t.options.linewidth),title:e}}return null}function c2(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 u2(t){let e=t.data.some(n=>as(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:Ou}:{time:n.time,value:r}})}function Ah(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 h2(t,e){if(!e)return t;let n=e*Ah(t);return n?t.map(r=>({...r,time:r.time+n})):t}function p2(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 Mh(t){for(let e of t.data)if(typeof e.options?.color=="string"&&e.options.color)return e.options.color;return z(t.options.color)}function d2(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=he(o.top_value),c=he(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 f2(t,e,n,r){if(!Gr(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:Th(t.options.linestyle)??"dashed",title:e,width:he(t.options.linewidth)}}function Th(t){let e=z(t)?.replace(/^(hline\\.style_|plot\\.linestyle_|linestyle_|style_)/,"");return e==="solid"||e==="dashed"||e==="dotted"?e:void 0}function m2(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=Xr(a.length,he(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 y2(t,e,n){let r=he(t.options.offset),i=r?r*Ah(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?g2(t):null,l=t.options.force_overlay===!0?{overlay:!0}:{},c=[],u=Xr(t.data.length,he(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,x=m.color!==void 0?m.color:t.options.color;if(x!==void 0&&!as(x))continue;let b=z(m.text)??z(t.options.text),v=b&&b.trim().length>0?b:void 0,E=a?f&&d>0?Ft:tn:void 0,w=ce(m.color)??ce(t.options.color)??E??Nh,S=s?z(m.char)??z(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:x2(z(m.location)??z(t.options.location)),text:S!==void 0?v!==void 0?`${S}\n${v}`:S:v,style:S!==void 0?"none":b2(z(m.shape)??z(t.options.shape)),color:w,textColor:ce(m.textcolor)??ce(t.options.textcolor)??(S!==void 0?w:void 0),size:o!==null&&f?_2(Math.abs(d),o):v2(z(m.size)??z(t.options.size)),textAlign:"center",fontFamily:"default",...l})}return c}function g2(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:he(t.options.minheight)??5,maxH:he(t.options.maxheight)??100}}function _2(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 x2(t){let e=(t??"").toLowerCase();return e==="absolute"?"price":e==="top"?"top":e==="bottom"?"bottom":e.includes("below")?"belowbar":"abovebar"}function b2(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 v2(t){let e=(t??"").toLowerCase();return e==="tiny"||e==="small"||e==="large"||e==="huge"||e==="normal"?e:"small"}function w2(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 S2(t){return t==="int"||t==="float"||t==="price"||t==="time"}var Ph={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 E2(t){let e=t.trim().toLowerCase().replace(/^color\\./,"");return Ph[e]??t}function C2(t){if(typeof t!="string")return;let e=/^color\\.([a-z]+)$/i.exec(t.trim());return e?Ph[e[1].toLowerCase()]:void 0}function N2(t){return(t.type==="string"||t.type==null)&&C2(t.defval)!==void 0}function I2(t,e){if(e==="bool")return!!t;if(S2(e))return typeof t=="number"?t:Number(t)||0;let n=typeof t=="string"?t:t==null?"":String(t);return e==="color"?E2(n):n}function Dh(t){return t.map((e,n)=>{let r=N2(e)?"color":w2(e.type);return{key:e.varId??e.title??`input${n}`,title:e.title??e.varId??`Input ${n+1}`,type:r,defval:I2(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 k2(t){switch(t){case"int":return"int";case"float":return"float";case"bool":return"bool";default:return"string"}}function Ko(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 A2(t){let e=t.replace(/_/g," ");return e.charAt(0).toUpperCase()+e.slice(1)}function Rh(t,e){let n=t.getPropsMeta(),r=t.prop;return n.filter(i=>i.mutable&&i.name).map(i=>{let s=i.name,a=k2(i.type),o=Ko(i.defval,a),l=Ko(r[s]??i.defval,a),c=e?.[s],u=l!==o?l:c!==void 0?Ko(c,a):o;return{key:s,title:A2(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 Oh(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 Lh=!1;function Yo(){if(Lh)return;Lh=!0;let t=ar.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:E,...w}=p;d=E,f=Object.keys(w).length>0?[...h,w]:h}else d=c[13],f=h;let m=l(...f),x=p??{},b=h.length>1?h[1]:x.column??0,v=h.length>2?h[2]:x.row??0;return o(h[0],b,v,d),m})})}var Fh=["plotshape","plotchar","plotarrow"],Bh=!1;function Go(){if(Bh)return;Bh=!0;let t=ar.prototype,e=t.bindContextObject;typeof e=="function"&&(t.bindContextObject=function(n,r,i){if(e.call(this,n,r,i),i!==void 0||!Fh.some(a=>r.includes(a)))return;let s={idx:void 0,n:0,len:0};for(let a of Fh){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 Xo(t,e,n){return t?{getFootprintData:(r,i,s,a,o)=>t(M2(r??e()),i??n(),{from:a,to:o,limit:s})}:{}}function M2(t){return t.split(";")[0]??t}function T2(t,e,n){if(n==="none")return[];if(n==="strategy"&&t.getDeclarationType()!=="strategy")return[];let r=Rh(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 Uh(t,e,n,r="all"){let i=Dn.from(t),s=Dh(i.getInputsMeta()),a=T2(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 Qo(t,e,n,r={}){let i=JSON.stringify([n,r]);if(t.lastKey!==i||!t.lastInd){let s=new Dn(e,n);Oh(s,r),t.lastInd=s,t.lastKey=i}return t.lastInd}async function qh(t){let{ind:e,bars:n,market:r,visibleRange:i,prepared:s,instanceId:a,inputs:o,props:l,fetchSeries:c,footprints:u}=t;Yo(),Go();let p=Jo(n,r.timeframe,r.symbolInfo),h={getMarketData:(x,b,v,E,w)=>Hh(x,b,r)?Promise.resolve(p):Kh(c,x,b,v,E,w,gs(r,x)),getSymbolInfo:async x=>gs(r,x),...Xo(u,()=>r.symbol,()=>r.timeframe)},d=new Sn(h,el(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:Ao(f)?zh(f,a,s,o,l??{},n[0]?.time):null,alerts:(f.alerts??[]).map(Gh),warnings:(f.warnings??[]).map(Xh),reactsToViewport:m,ctx:f}}function zh(t,e,n,r,i,s){let{model:a}=Ih(ss(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={...jh(n.inputs),...r},n.props&&(a.props=n.props,a.propValues={...jh(n.props),...i}),s!=null&&(a.anchorTime=s),a}function Vh(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 Zo=(t,e)=>e.start<=e.end?t>=e.start&&t<e.end:t>=e.start||t<e.end,ys=new Map;function $h(t,e){let n=`${e}:${Math.floor(t/36e5)}`,r=ys.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}ys.size>1e5&&ys.clear(),ys.set(n,r)}return Number.isNaN(r)?null:((Math.floor(t/6e4)+r)%1440+1440)%1440}function P2(t){return t==null?null:/^\\d+$/.test(t)?Number(t):/^1?D$/i.test(t)?1440:null}function D2(t,e,n){let r=typeof n=="object"&&n!=null?n:null,i=P2(e),s=Vh(r?.session),a=typeof r?.timezone=="string"?r.timezone:null;if(i==null||s==null||a==null||t.length===0)return null;let o=Vh(r?.session_extended),l=s;if(o)for(let c of t){let u=$h(c.time,a);if(u!=null&&!Zo(u,s)&&Zo(u,o)){l=o;break}}return c=>{let u=$h(c,a);if(u==null||!Zo(u,l))return null;let p=(l.end-u+1440)%1440||1440;return c+Math.min(i,p)*6e4}}function Jo(t,e,n){let r=D2(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 el(t){return t.chartStyle==="heikinashi"?`${t.symbol};heikinashi`:t.symbol}function Hh(t,e,n){return(t==null||t===el(n))&&(e==null||e===n.timeframe)}async function Kh(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 Jo(o,n,a)}function R2(t,e,n,r){let i="",s=!1;return{...Xo(r,()=>e().symbol,()=>e().timeframe),markDirty:()=>{s=!0},getMarketData:async(a,o,l,c,u)=>{let p=e();if(!Hh(a,o,p))return Kh(n,a,o,l,c,u,gs(p,a));let h=Jo(t(),p.timeframe,p.symbolInfo);if(c==null)return h;let d=h.filter(x=>(x.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=>gs(e(),a)}}function Yh(t){let e=t.bars();Yo(),Go();let n=Qo(t.cache,t.token.source,t.inputs,t.props??{}),r=e[0]?.time,i=Math.max(1,e.length),s=R2(t.bars,t.market,t.fetchSeries,t.footprints),a=new Sn(s,el(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,!!Ao(u)))try{t.onModel(zh(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?.(Gh(u))),o.on("warning",u=>t.onWarning?.(Xh(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 gs(t,e){let n=e&&e.split(";")[0];return n&&n!==t.symbol?Wh({symbol:n,timeframe:t.timeframe}):Wh(t)}function Wh(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 jh(t){let e={};for(let n of t)e[n.key]=n.defval;return e}function Gh(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 Xh(t){return{message:String(t.message??""),method:t.method,bar:Number(t.bar??0)}}var pt=t=>he(t)??0;function Zh(t){if(t==null||typeof t!="object")return;let e=t;return{position:pt(e.position_size),avgPrice:pt(e.position_avg_price),equity:pt(e.equity),openPnl:pt(e.openprofit),netPnl:pt(e.netprofit),grossProfit:pt(e.grossprofit),grossLoss:pt(e.grossloss),wins:pt(e.wintrades),losses:pt(e.losstrades),even:pt(e.eventrades),maxDrawdown:pt(e.max_drawdown),maxRunup:pt(e.max_runup),initialCapital:pt(e.initial_capital)}}var _s=(t,e)=>{let n=he(e);return n===void 0?{}:{[t]:n}};function Qh(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=he(i.entry_price),a=he(i.entry_time),o=he(i.size);if(s===void 0||a===void 0||o===void 0||o===0)continue;let l=he(i.exit_price),c=he(i.exit_time);n.push({id:z(i.id)??`trade_${n.length}`,side:o>0?"long":"short",qty:Math.abs(o),entry:{id:z(i.entry_id)??"",time:a,price:s,...z(i.entry_comment)!==void 0?{comment:z(i.entry_comment)}:{}},...l!==void 0&&c!==void 0?{exit:{id:z(i.exit_id)??"",time:c,price:l,...z(i.exit_comment)!==void 0?{comment:z(i.exit_comment)}:{}}}:{},open:i.status!=="closed",..._s("pnl",i.profit),..._s("commission",i.commission),..._s("maxDrawdown",i.max_drawdown),..._s("maxRunup",i.max_runup)})}return n}function Jh(t){try{return structuredClone(t)}catch{return}}function O2(t){let e=Array.isArray(t)?t:t!=null&&typeof t=="object"&&Array.isArray(t.data)?t.data:null;return Jh(e?e[e.length-1]:t)}function L2(t){return t.replace(/^glb\\d+_/,"")}function tl(t,e){if(t)for(let[n,r]of Object.entries(t)){if(n.startsWith("_"))continue;let i=O2(r);i!==void 0&&(e[L2(n)]=i)}}function ep(t,e,n){let r=t??{},i=r.fullContext??r,s=h=>!n||n.includes(h),a=s("meta")||s("plots")?ss(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:Jh(d.value)??null})));let l={};s("variables")&&(tl(i.const,l),tl(i.var,l),tl(i.let,l));let c=s("strategy")?Zh(i.strategy):void 0,u=s("trades")&&i.strategy?Qh(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 tp=self,$e=t=>tp.postMessage(t),Nn=new Map,rl=new Map,il=new Map,np=0,rp=(t,e,n)=>new Promise((r,i)=>{let s=++np;rl.set(s,{resolve:r,reject:i}),$e({kind:"fetchSeries",reqId:s,symbol:t,timeframe:e,range:n})}),F2=(t,e,n)=>new Promise((r,i)=>{let s=++np;il.set(s,{resolve:r,reject:i}),$e({kind:"fetchFootprints",reqId:s,symbol:t,timeframe:e,range:n})});function xs(t){t.chain=t.chain.then(()=>V2(t))}function B2(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 nl(t){t.stream?.stop(),t.stream=null,!(t.stopped||t.bars.length===0)&&(t.stream=Yh({token:t.prepared.token,cache:t.cache,prepared:t.prepared,inputs:t.inputs,props:t.props,bars:()=>t.bars,market:()=>t.market,fetchSeries:rp,footprints:t.footprints,visibleRange:t.visibleRange,onModel:e=>{t.stopped||$e({kind:"model",sessionId:t.id,model:e})},onAlert:e=>$e({kind:"alert",sessionId:t.id,alert:e}),onWarning:e=>$e({kind:"warning",sessionId:t.id,warning:e}),onError:e=>$e({kind:"error",sessionId:t.id,message:e.message})}))}async function V2(t){if(!t.stopped)try{let e=t.prepared.token,n=await qh({ind:Qo(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:rp,footprints:t.footprints});if(t.stopped)return;$e({kind:"reactsToViewport",sessionId:t.id,value:n.reactsToViewport});for(let r of n.alerts)$e({kind:"alert",sessionId:t.id,alert:r});for(let r of n.warnings)$e({kind:"warning",sessionId:t.id,warning:r});t.lastCtx=n.ctx,n.model&&$e({kind:"model",sessionId:t.id,model:n.model}),$e({kind:"done",sessionId:t.id})}catch(e){$e({kind:"error",sessionId:t.id,message:e instanceof Error?e.message:String(e)})}}tp.addEventListener("message",t=>{let e=t.data;switch(e.kind){case"prepare":try{$e({kind:"prepared",reqId:e.reqId,prepared:Uh(e.source,e.instanceId,e.defaultProps,e.propsVisibility)})}catch(n){$e({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?F2:void 0};if(Nn.set(n.id,n),n.mode==="live"){n.deferred||nl(n);return}n.deferred?$e({kind:"done",sessionId:n.id}):xs(n);return}case"update":{let n=Nn.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||nl(n);return}n.deferred?$e({kind:"done",sessionId:n.id}):xs(n);return}case"setVisibleRange":{let n=Nn.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?$e({kind:"done",sessionId:n.id}):xs(n);return}case"notifyBars":{let n=Nn.get(e.sessionId);if(!n||n.mode==="live")return;n.bars=e.bars,n.deferred=!1,xs(n);return}case"bars":{let n=Nn.get(e.sessionId);if(!n||n.mode!=="live")return;if(e.restart){n.bars=e.bars,n.deferred=!1,nl(n);return}for(let r of e.bars)B2(n,r);return}case"getContext":{let n=Nn.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";$e({kind:"contextResult",reqId:e.reqId,snapshot:r==null?null:ep(r,i,e.select)});return}case"stop":{let n=Nn.get(e.sessionId);n&&(n.stopped=!0,n.stream?.stop()),Nn.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=il.get(e.reqId);if(!n)return;il.delete(e.reqId),e.error?n.reject(new Error(e.error)):n.resolve(e.bars??[]);return}}});})();\n';
|
|
1704
1729
|
|
|
1705
1730
|
// src/pinets-worker/PineWorkerEngine.ts
|
|
1706
1731
|
function spawnWorker(workerUrl) {
|
|
@@ -1717,6 +1742,7 @@ var PineWorkerEngine = class {
|
|
|
1717
1742
|
spawn;
|
|
1718
1743
|
defaultProps;
|
|
1719
1744
|
propsVisibility;
|
|
1745
|
+
footprints;
|
|
1720
1746
|
prepares = /* @__PURE__ */ new Map();
|
|
1721
1747
|
sessions = /* @__PURE__ */ new Map();
|
|
1722
1748
|
reqId = 0;
|
|
@@ -1726,6 +1752,7 @@ var PineWorkerEngine = class {
|
|
|
1726
1752
|
this.spawn = opts.createWorker ?? (() => spawnWorker(opts.workerUrl));
|
|
1727
1753
|
this.defaultProps = opts.defaultProps;
|
|
1728
1754
|
this.propsVisibility = opts.props;
|
|
1755
|
+
this.footprints = opts.footprints;
|
|
1729
1756
|
}
|
|
1730
1757
|
prepare(source, instanceId) {
|
|
1731
1758
|
const reqId = ++this.reqId;
|
|
@@ -1757,7 +1784,8 @@ var PineWorkerEngine = class {
|
|
|
1757
1784
|
...req.props ? { props: { ...req.props } } : {},
|
|
1758
1785
|
visibleRange: req.visibleRange,
|
|
1759
1786
|
mode,
|
|
1760
|
-
historyState: req.historyState
|
|
1787
|
+
historyState: req.historyState,
|
|
1788
|
+
...this.footprints ? { footprints: true } : {}
|
|
1761
1789
|
};
|
|
1762
1790
|
if (mode === "live") this.post(msg);
|
|
1763
1791
|
else this.postRun(entry, msg);
|
|
@@ -1885,6 +1913,9 @@ var PineWorkerEngine = class {
|
|
|
1885
1913
|
case "fetchSeries":
|
|
1886
1914
|
void this.serveFetch(msg.reqId, msg.symbol, msg.timeframe, msg.range);
|
|
1887
1915
|
return;
|
|
1916
|
+
case "fetchFootprints":
|
|
1917
|
+
void this.serveFootprints(msg.reqId, msg.symbol, msg.timeframe, msg.range);
|
|
1918
|
+
return;
|
|
1888
1919
|
case "contextResult": {
|
|
1889
1920
|
const waiter = this.contextWaits.get(msg.reqId);
|
|
1890
1921
|
this.contextWaits.delete(msg.reqId);
|
|
@@ -1910,6 +1941,22 @@ var PineWorkerEngine = class {
|
|
|
1910
1941
|
this.post({ kind: "fetchSeriesResult", reqId, error: err instanceof Error ? err.message : String(err) });
|
|
1911
1942
|
}
|
|
1912
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
|
+
}
|
|
1913
1960
|
};
|
|
1914
1961
|
|
|
1915
1962
|
export { PineEngine, PineWorkerEngine };
|