@simahfud/pine-to-kline 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,36 @@
1
- (function(f,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(f=typeof globalThis<"u"?globalThis:f||self,m(f.PineToKline={}))})(this,function(f){"use strict";var $t=Object.defineProperty;var Kt=(f,m,a)=>m in f?$t(f,m,{enumerable:!0,configurable:!0,writable:!0,value:a}):f[m]=a;var p=(f,m,a)=>Kt(f,typeof m!="symbol"?m+"":m,a);/**
1
+ (function(N,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(N=typeof globalThis<"u"?globalThis:N||self,E(N.PineToKline={}))})(this,function(N){"use strict";var $t=Object.defineProperty;var Kt=(N,E,a)=>E in N?$t(N,E,{enumerable:!0,configurable:!0,writable:!0,value:a}):N[E]=a;var p=(N,E,a)=>Kt(N,typeof E!="symbol"?E+"":E,a);/**
2
2
  * pine-to-kline — Token
3
3
  * @license Apache-2.0
4
- */class m{constructor(t,e,s,r){this.type=t,this.value=e,this.line=s,this.column=r}is(t){return this.type===t}isAny(...t){return t.includes(this.type)}toString(){return`Token(${this.type}, ${JSON.stringify(this.value)}, ${this.line}:${this.column})`}}/**
4
+ */class E{constructor(t,e,s,r){this.type=t,this.value=e,this.line=s,this.column=r}is(t){return this.type===t}isAny(...t){return t.includes(this.type)}toString(){return`Token(${this.type}, ${JSON.stringify(this.value)}, ${this.line}:${this.column})`}}/**
5
5
  * pine-to-kline — Token Types
6
6
  * All PineScript v5/v6 token categories
7
7
  * @license Apache-2.0
8
- */var a=(i=>(i.NUMBER="NUMBER",i.STRING="STRING",i.COLOR_LITERAL="COLOR_LITERAL",i.IDENTIFIER="IDENTIFIER",i.IF="IF",i.ELSE="ELSE",i.FOR="FOR",i.TO="TO",i.BY="BY",i.IN="IN",i.WHILE="WHILE",i.SWITCH="SWITCH",i.VAR="VAR",i.VARIP="VARIP",i.TRUE="TRUE",i.FALSE="FALSE",i.NA="NA",i.AND="AND",i.OR="OR",i.NOT="NOT",i.IMPORT="IMPORT",i.EXPORT="EXPORT",i.TYPE="TYPE",i.METHOD="METHOD",i.BREAK="BREAK",i.CONTINUE="CONTINUE",i.RETURN="RETURN",i.INDICATOR="INDICATOR",i.STRATEGY="STRATEGY",i.LIBRARY="LIBRARY",i.PLUS="PLUS",i.MINUS="MINUS",i.STAR="STAR",i.SLASH="SLASH",i.PERCENT="PERCENT",i.POWER="POWER",i.EQ="EQ",i.NEQ="NEQ",i.LT="LT",i.GT="GT",i.LTE="LTE",i.GTE="GTE",i.ASSIGN="ASSIGN",i.REASSIGN="REASSIGN",i.PLUS_ASSIGN="PLUS_ASSIGN",i.MINUS_ASSIGN="MINUS_ASSIGN",i.STAR_ASSIGN="STAR_ASSIGN",i.SLASH_ASSIGN="SLASH_ASSIGN",i.PERCENT_ASSIGN="PERCENT_ASSIGN",i.LPAREN="LPAREN",i.RPAREN="RPAREN",i.LBRACKET="LBRACKET",i.RBRACKET="RBRACKET",i.COMMA="COMMA",i.DOT="DOT",i.COLON="COLON",i.QUESTION="QUESTION",i.ARROW="ARROW",i.NEWLINE="NEWLINE",i.INDENT="INDENT",i.DEDENT="DEDENT",i.EOF="EOF",i.COMMENT="COMMENT",i.COMPILER_ANNOTATION="COMPILER_ANNOTATION",i))(a||{});const W={if:"IF",else:"ELSE",for:"FOR",to:"TO",by:"BY",in:"IN",while:"WHILE",switch:"SWITCH",var:"VAR",varip:"VARIP",true:"TRUE",false:"FALSE",na:"NA",and:"AND",or:"OR",not:"NOT",import:"IMPORT",export:"EXPORT",type:"TYPE",method:"METHOD",break:"BREAK",continue:"CONTINUE",return:"RETURN"};/**
8
+ */var a=(i=>(i.NUMBER="NUMBER",i.STRING="STRING",i.COLOR_LITERAL="COLOR_LITERAL",i.IDENTIFIER="IDENTIFIER",i.IF="IF",i.ELSE="ELSE",i.FOR="FOR",i.TO="TO",i.BY="BY",i.IN="IN",i.WHILE="WHILE",i.SWITCH="SWITCH",i.VAR="VAR",i.VARIP="VARIP",i.TRUE="TRUE",i.FALSE="FALSE",i.NA="NA",i.AND="AND",i.OR="OR",i.NOT="NOT",i.IMPORT="IMPORT",i.EXPORT="EXPORT",i.TYPE="TYPE",i.METHOD="METHOD",i.BREAK="BREAK",i.CONTINUE="CONTINUE",i.RETURN="RETURN",i.INDICATOR="INDICATOR",i.STRATEGY="STRATEGY",i.LIBRARY="LIBRARY",i.PLUS="PLUS",i.MINUS="MINUS",i.STAR="STAR",i.SLASH="SLASH",i.PERCENT="PERCENT",i.POWER="POWER",i.EQ="EQ",i.NEQ="NEQ",i.LT="LT",i.GT="GT",i.LTE="LTE",i.GTE="GTE",i.ASSIGN="ASSIGN",i.REASSIGN="REASSIGN",i.PLUS_ASSIGN="PLUS_ASSIGN",i.MINUS_ASSIGN="MINUS_ASSIGN",i.STAR_ASSIGN="STAR_ASSIGN",i.SLASH_ASSIGN="SLASH_ASSIGN",i.PERCENT_ASSIGN="PERCENT_ASSIGN",i.LPAREN="LPAREN",i.RPAREN="RPAREN",i.LBRACKET="LBRACKET",i.RBRACKET="RBRACKET",i.COMMA="COMMA",i.DOT="DOT",i.COLON="COLON",i.QUESTION="QUESTION",i.ARROW="ARROW",i.NEWLINE="NEWLINE",i.INDENT="INDENT",i.DEDENT="DEDENT",i.EOF="EOF",i.COMMENT="COMMENT",i.COMPILER_ANNOTATION="COMPILER_ANNOTATION",i))(a||{});const V={if:"IF",else:"ELSE",for:"FOR",to:"TO",by:"BY",in:"IN",while:"WHILE",switch:"SWITCH",var:"VAR",varip:"VARIP",true:"TRUE",false:"FALSE",na:"NA",and:"AND",or:"OR",not:"NOT",import:"IMPORT",export:"EXPORT",type:"TYPE",method:"METHOD",break:"BREAK",continue:"CONTINUE",return:"RETURN"};/**
9
9
  * pine-to-kline — Error Classes
10
10
  * @license Apache-2.0
11
- */class S extends Error{constructor(t,e,s,r){super(t),this.line=e,this.column=s,this.source=r,this.name="PineError"}toString(){const t=this.line!=null?` at line ${this.line}`:"",e=this.column!=null?`:${this.column}`:"";return`${this.name}: ${this.message}${t}${e}`}}class R extends S{constructor(t,e,s){super(t,e,s),this.name="LexerError"}}class L extends S{constructor(t,e,s){super(t,e,s),this.name="ParseError"}}class H extends S{constructor(t,e,s){super(t,e,s),this.name="RuntimeError"}}class j extends S{constructor(t){super(t),this.name="AdapterError"}}/**
11
+ */class R extends Error{constructor(t,e,s,r){super(t),this.line=e,this.column=s,this.source=r,this.name="PineError"}toString(){const t=this.line!=null?` at line ${this.line}`:"",e=this.column!=null?`:${this.column}`:"";return`${this.name}: ${this.message}${t}${e}`}}class S extends R{constructor(t,e,s){super(t,e,s),this.name="LexerError"}}class x extends R{constructor(t,e,s){super(t,e,s),this.name="ParseError"}}class W extends R{constructor(t,e,s){super(t,e,s),this.name="RuntimeError"}}class H extends R{constructor(t){super(t),this.name="AdapterError"}}/**
12
12
  * pine-to-kline — Lexer (Tokenizer)
13
13
  * Converts PineScript source code into a stream of tokens.
14
14
  * Handles indentation-significant syntax (INDENT/DEDENT).
15
15
  * @license Apache-2.0
16
- */class b{constructor(t){p(this,"source");p(this,"tokens",[]);p(this,"pos",0);p(this,"line",1);p(this,"column",1);p(this,"indentStack",[0]);p(this,"atLineStart",!0);this.source=t.replace(/\r\n/g,`
16
+ */class P{constructor(t){p(this,"source");p(this,"tokens",[]);p(this,"pos",0);p(this,"line",1);p(this,"column",1);p(this,"indentStack",[0]);p(this,"atLineStart",!0);this.source=t.replace(/\r\n/g,`
17
17
  `).replace(/\r/g,`
18
18
  `)}tokenize(){for(this.tokens=[],this.pos=0,this.line=1,this.column=1,this.indentStack=[0],this.atLineStart=!0;this.pos<this.source.length;){this.atLineStart&&(this.handleIndentation(),this.atLineStart=!1);const t=this.current();if(t===void 0)break;if(t===" "||t===" "){this.advance();continue}if(t===`
19
- `){this.emitNewline();continue}if(t==="/"&&this.peek()==="/"){this.readComment();continue}if(this.isDigit(t)||t==="."&&this.peek()!==void 0&&this.isDigit(this.peek())){this.readNumber();continue}if(t==='"'||t==="'"){this.readString(t);continue}if(t==="#"&&this.isHexDigit(this.peek())){this.readColor();continue}if(this.isAlpha(t)||t==="_"){this.readIdentifier();continue}if(!this.readOperator())throw new R(`Unexpected character: '${t}'`,this.line,this.column)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.tokens.push(new m(a.DEDENT,"",this.line,this.column));return this.tokens.push(new m(a.EOF,"",this.line,this.column)),this.filterTokens(this.tokens)}handleIndentation(){let t=0;for(;this.pos<this.source.length;){const s=this.source[this.pos];if(s===" ")t++,this.pos++,this.column++;else if(s===" ")t+=4,this.pos++,this.column++;else break}if(this.pos<this.source.length&&this.source[this.pos]===`
20
- `||this.pos<this.source.length&&this.source[this.pos]==="/"&&this.pos+1<this.source.length&&this.source[this.pos+1]==="/")return;const e=this.indentStack[this.indentStack.length-1];if(t>e)this.indentStack.push(t),this.tokens.push(new m(a.INDENT,"",this.line,1));else if(t<e)for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>t;)this.indentStack.pop(),this.tokens.push(new m(a.DEDENT,"",this.line,1))}emitNewline(){const t=this.tokens[this.tokens.length-1];(!t||t.type!==a.NEWLINE&&t.type!==a.INDENT)&&this.tokens.push(new m(a.NEWLINE,`
19
+ `){this.emitNewline();continue}if(t==="/"&&this.peek()==="/"){this.readComment();continue}if(this.isDigit(t)||t==="."&&this.peek()!==void 0&&this.isDigit(this.peek())){this.readNumber();continue}if(t==='"'||t==="'"){this.readString(t);continue}if(t==="#"&&this.isHexDigit(this.peek())){this.readColor();continue}if(this.isAlpha(t)||t==="_"){this.readIdentifier();continue}if(!this.readOperator())throw new S(`Unexpected character: '${t}'`,this.line,this.column)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.tokens.push(new E(a.DEDENT,"",this.line,this.column));return this.tokens.push(new E(a.EOF,"",this.line,this.column)),this.filterTokens(this.tokens)}handleIndentation(){let t=0;for(;this.pos<this.source.length;){const s=this.source[this.pos];if(s===" ")t++,this.pos++,this.column++;else if(s===" ")t+=4,this.pos++,this.column++;else break}if(this.pos<this.source.length&&this.source[this.pos]===`
20
+ `||this.pos<this.source.length&&this.source[this.pos]==="/"&&this.pos+1<this.source.length&&this.source[this.pos+1]==="/")return;const e=this.indentStack[this.indentStack.length-1];if(t>e)this.indentStack.push(t),this.tokens.push(new E(a.INDENT,"",this.line,1));else if(t<e)for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>t;)this.indentStack.pop(),this.tokens.push(new E(a.DEDENT,"",this.line,1))}emitNewline(){const t=this.tokens[this.tokens.length-1];(!t||t.type!==a.NEWLINE&&t.type!==a.INDENT)&&this.tokens.push(new E(a.NEWLINE,`
21
21
  `,this.line,this.column)),this.advance(),this.line++,this.column=1,this.atLineStart=!0}readComment(){const t=this.column;let e="";if(this.advance(),this.advance(),this.current()==="@"){for(e="//@",this.advance();this.pos<this.source.length&&this.current()!==`
22
- `;)e+=this.current(),this.advance();this.tokens.push(new m(a.COMPILER_ANNOTATION,e.trim(),this.line,t));return}for(;this.pos<this.source.length&&this.current()!==`
23
- `;)e+=this.current(),this.advance()}readNumber(){const t=this.column;let e="";for(;this.pos<this.source.length&&(this.isDigit(this.current())||this.current()===".");)e+=this.current(),this.advance();if(this.current()==="e"||this.current()==="E")for(e+=this.current(),this.advance(),(this.current()==="+"||this.current()==="-")&&(e+=this.current(),this.advance());this.pos<this.source.length&&this.isDigit(this.current());)e+=this.current(),this.advance();this.tokens.push(new m(a.NUMBER,e,this.line,t))}readString(t){const e=this.column,s=this.line;let r="";for(this.advance();this.pos<this.source.length;){const n=this.current();if(n==="\\"){this.advance();const l=this.current();l==="n"?r+=`
24
- `:l==="t"?r+=" ":l==="\\"?r+="\\":l===t?r+=t:r+="\\"+(l??""),this.advance();continue}if(n===t){this.advance(),this.tokens.push(new m(a.STRING,r,s,e));return}if(n===`
25
- `)throw new R("Unterminated string literal",s,e);r+=n,this.advance()}throw new R("Unterminated string literal",s,e)}readColor(){const t=this.column;let e="#";for(this.advance();this.pos<this.source.length&&this.isHexDigit(this.current());)e+=this.current(),this.advance();if(e.length!==7&&e.length!==9)throw new R(`Invalid color literal: ${e}`,this.line,t);this.tokens.push(new m(a.COLOR_LITERAL,e,this.line,t))}readIdentifier(){const t=this.column;let e="";for(;this.pos<this.source.length&&(this.isAlphaNumeric(this.current())||this.current()==="_");)e+=this.current(),this.advance();const s=W[e];s?this.tokens.push(new m(s,e,this.line,t)):this.tokens.push(new m(a.IDENTIFIER,e,this.line,t))}readOperator(){const t=this.current(),e=this.peek(),s=this.column;if(e!==void 0){const n=t+e,l={"==":a.EQ,"!=":a.NEQ,"<=":a.LTE,">=":a.GTE,":=":a.REASSIGN,"+=":a.PLUS_ASSIGN,"-=":a.MINUS_ASSIGN,"*=":a.STAR_ASSIGN,"/=":a.SLASH_ASSIGN,"%=":a.PERCENT_ASSIGN,"=>":a.ARROW,"**":a.POWER};if(l[n])return this.advance(),this.advance(),this.tokens.push(new m(l[n],n,this.line,s)),!0}const r={"+":a.PLUS,"-":a.MINUS,"*":a.STAR,"/":a.SLASH,"%":a.PERCENT,"<":a.LT,">":a.GT,"=":a.ASSIGN,"(":a.LPAREN,")":a.RPAREN,"[":a.LBRACKET,"]":a.RBRACKET,",":a.COMMA,".":a.DOT,":":a.COLON,"?":a.QUESTION};return r[t]?(this.advance(),this.tokens.push(new m(r[t],t,this.line,s)),!0):!1}filterTokens(t){const e=[],s=new Set([a.PLUS,a.MINUS,a.STAR,a.SLASH,a.PERCENT,a.POWER,a.EQ,a.NEQ,a.LT,a.GT,a.LTE,a.GTE,a.AND,a.OR,a.COMMA,a.ASSIGN,a.REASSIGN,a.PLUS_ASSIGN,a.MINUS_ASSIGN,a.STAR_ASSIGN,a.SLASH_ASSIGN,a.PERCENT_ASSIGN,a.QUESTION,a.COLON,a.ARROW,a.LPAREN,a.LBRACKET]);let r=0,n=0;for(let l=0;l<t.length;l++){const h=t[l];if(h.type===a.LPAREN&&r++,h.type===a.RPAREN&&r--,h.type===a.LBRACKET&&n++,h.type===a.RBRACKET&&n--,!(h.type===a.NEWLINE&&(r>0||n>0))){if(h.type===a.NEWLINE){const c=e[e.length-1];if(c&&s.has(c.type))continue}(h.type===a.INDENT||h.type===a.DEDENT)&&(r>0||n>0)||e.push(h)}}return e}current(){return this.source[this.pos]}peek(t=1){return this.source[this.pos+t]}advance(){this.pos++,this.column++}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"}isAlphaNumeric(t){return this.isAlpha(t)||this.isDigit(t)}isHexDigit(t){return t?t>="0"&&t<="9"||t>="a"&&t<="f"||t>="A"&&t<="F":!1}}/**
22
+ `;)e+=this.current(),this.advance();this.tokens.push(new E(a.COMPILER_ANNOTATION,e.trim(),this.line,t));return}for(;this.pos<this.source.length&&this.current()!==`
23
+ `;)e+=this.current(),this.advance()}readNumber(){const t=this.column;let e="";for(;this.pos<this.source.length&&(this.isDigit(this.current())||this.current()===".");)e+=this.current(),this.advance();if(this.current()==="e"||this.current()==="E")for(e+=this.current(),this.advance(),(this.current()==="+"||this.current()==="-")&&(e+=this.current(),this.advance());this.pos<this.source.length&&this.isDigit(this.current());)e+=this.current(),this.advance();this.tokens.push(new E(a.NUMBER,e,this.line,t))}readString(t){const e=this.column,s=this.line;let r="";for(this.advance();this.pos<this.source.length;){const n=this.current();if(n==="\\"){this.advance();const l=this.current();l==="n"?r+=`
24
+ `:l==="t"?r+=" ":l==="\\"?r+="\\":l===t?r+=t:r+="\\"+(l??""),this.advance();continue}if(n===t){this.advance(),this.tokens.push(new E(a.STRING,r,s,e));return}if(n===`
25
+ `)throw new S("Unterminated string literal",s,e);r+=n,this.advance()}throw new S("Unterminated string literal",s,e)}readColor(){const t=this.column;let e="#";for(this.advance();this.pos<this.source.length&&this.isHexDigit(this.current());)e+=this.current(),this.advance();if(e.length!==7&&e.length!==9)throw new S(`Invalid color literal: ${e}`,this.line,t);this.tokens.push(new E(a.COLOR_LITERAL,e,this.line,t))}readIdentifier(){const t=this.column;let e="";for(;this.pos<this.source.length&&(this.isAlphaNumeric(this.current())||this.current()==="_");)e+=this.current(),this.advance();const s=V[e];s?this.tokens.push(new E(s,e,this.line,t)):this.tokens.push(new E(a.IDENTIFIER,e,this.line,t))}readOperator(){const t=this.current(),e=this.peek(),s=this.column;if(e!==void 0){const n=t+e,l={"==":a.EQ,"!=":a.NEQ,"<=":a.LTE,">=":a.GTE,":=":a.REASSIGN,"+=":a.PLUS_ASSIGN,"-=":a.MINUS_ASSIGN,"*=":a.STAR_ASSIGN,"/=":a.SLASH_ASSIGN,"%=":a.PERCENT_ASSIGN,"=>":a.ARROW,"**":a.POWER};if(l[n])return this.advance(),this.advance(),this.tokens.push(new E(l[n],n,this.line,s)),!0}const r={"+":a.PLUS,"-":a.MINUS,"*":a.STAR,"/":a.SLASH,"%":a.PERCENT,"<":a.LT,">":a.GT,"=":a.ASSIGN,"(":a.LPAREN,")":a.RPAREN,"[":a.LBRACKET,"]":a.RBRACKET,",":a.COMMA,".":a.DOT,":":a.COLON,"?":a.QUESTION};return r[t]?(this.advance(),this.tokens.push(new E(r[t],t,this.line,s)),!0):!1}filterTokens(t){const e=[],s=new Set([a.PLUS,a.MINUS,a.STAR,a.SLASH,a.PERCENT,a.POWER,a.EQ,a.NEQ,a.LT,a.GT,a.LTE,a.GTE,a.AND,a.OR,a.COMMA,a.ASSIGN,a.REASSIGN,a.PLUS_ASSIGN,a.MINUS_ASSIGN,a.STAR_ASSIGN,a.SLASH_ASSIGN,a.PERCENT_ASSIGN,a.QUESTION,a.COLON,a.ARROW,a.LPAREN,a.LBRACKET]);let r=0,n=0;for(let l=0;l<t.length;l++){const h=t[l];if(h.type===a.LPAREN&&r++,h.type===a.RPAREN&&r--,h.type===a.LBRACKET&&n++,h.type===a.RBRACKET&&n--,!(h.type===a.NEWLINE&&(r>0||n>0))){if(h.type===a.NEWLINE){const c=e[e.length-1];if(c&&s.has(c.type))continue}(h.type===a.INDENT||h.type===a.DEDENT)&&(r>0||n>0)||e.push(h)}}return e}current(){return this.source[this.pos]}peek(t=1){return this.source[this.pos+t]}advance(){this.pos++,this.column++}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"}isAlphaNumeric(t){return this.isAlpha(t)||this.isDigit(t)}isHexDigit(t){return t?t>="0"&&t<="9"||t>="a"&&t<="f"||t>="A"&&t<="F":!1}}/**
26
26
  * pine-to-kline — Parser
27
27
  * Recursive descent parser: Token[] → AST (ProgramNode)
28
28
  * @license Apache-2.0
29
- */const $=new Set(["plot","plotshape","plotarrow","plotbar","plotcandle","plotchar","bgcolor","fill"]),D=new Set(["int","float","bool","string","color","label","line","box","table","series","simple"]);class P{constructor(t){p(this,"tokens");p(this,"pos",0);this.tokens=t}parse(){const t=[],e=[];for(this.skipNewlines();!this.isAtEnd()&&(this.skipNewlines(),!this.isAtEnd());){if(this.check(a.COMPILER_ANNOTATION)){e.push({type:"Annotation",value:this.advance().value,line:this.previous().line}),this.skipNewlines();continue}const s=this.parseStatement();s&&t.push(s),this.skipNewlines()}return{type:"Program",body:t,annotations:e}}parseStatement(){if(this.check(a.VAR)||this.check(a.VARIP))return this.parseVarDecl();if(this.check(a.IF))return this.parseIf();if(this.check(a.FOR))return this.parseFor();if(this.check(a.WHILE))return this.parseWhile();if(this.check(a.SWITCH))return this.parseSwitch();if(this.check(a.BREAK))return this.advance(),{type:"Break",line:this.previous().line};if(this.check(a.CONTINUE))return this.advance(),{type:"Continue",line:this.previous().line};if(this.check(a.RETURN))return this.parseReturn();if(this.check(a.IDENTIFIER))return this.parseIdentifierStatement();if(this.check(a.LBRACKET))return this.parseTupleAssign();const t=this.parseExpression();return{type:"ExpressionStatement",expression:t,line:t.line}}parseIdentifierStatement(){var s,r,n,l,h,c;const t=this.peek();if((t.value==="indicator"||t.value==="strategy"||t.value==="library")&&((s=this.peekAt(1))==null?void 0:s.type)===a.LPAREN)return this.parseIndicator();if($.has(t.value)&&((r=this.peekAt(1))==null?void 0:r.type)===a.LPAREN)return this.parsePlotCall();if(t.value==="hline"&&((n=this.peekAt(1))==null?void 0:n.type)===a.LPAREN)return this.parseHlineCall();if(((l=this.peekAt(1))==null?void 0:l.type)===a.LPAREN&&this.isFunctionDef())return this.parseFunctionDef();if(D.has(t.value)&&((h=this.peekAt(1))==null?void 0:h.type)===a.IDENTIFIER)return this.parseTypedDecl();if((c=this.peekAt(1))!=null&&c.isAny(a.ASSIGN,a.REASSIGN,a.PLUS_ASSIGN,a.MINUS_ASSIGN,a.STAR_ASSIGN,a.SLASH_ASSIGN,a.PERCENT_ASSIGN))return this.parseAssignment();const e=this.parseExpression();return{type:"ExpressionStatement",expression:e,line:e.line}}parseIndicator(){const t=this.advance();this.expect(a.LPAREN);const e=this.parseCallArgs();return this.expect(a.RPAREN),{type:"Indicator",name:e.positional[0]??{type:"StringLiteral",value:"Untitled",line:t.line},args:e.named,line:t.line}}parseVarDecl(){const t=this.check(a.VAR),e=this.check(a.VARIP);this.advance();let s=null;this.check(a.IDENTIFIER)&&D.has(this.peek().value)&&(s=this.advance().value);const r=this.expect(a.IDENTIFIER).value;this.expect(a.ASSIGN);const n=this.parseExpression();return{type:"VarDecl",persistent:t,persistentTick:e,name:r,typeAnnotation:s,value:n,line:n.line}}parseTypedDecl(){const t=this.advance().value,e=this.expect(a.IDENTIFIER).value;this.expect(a.ASSIGN);const s=this.parseExpression();return{type:"VarDecl",persistent:!1,persistentTick:!1,name:e,typeAnnotation:t,value:s,line:s.line}}parseAssignment(){const t=this.advance().value,e=this.advance(),s=this.parseExpression();return{type:"Assign",target:t,operator:e.value,value:s,line:e.line}}parseTupleAssign(){this.expect(a.LBRACKET);const t=[];for(t.push(this.expect(a.IDENTIFIER).value);this.match(a.COMMA);)t.push(this.expect(a.IDENTIFIER).value);this.expect(a.RBRACKET),this.expect(a.ASSIGN);const e=this.parseExpression();return{type:"VarDecl",persistent:!1,persistentTick:!1,name:t,typeAnnotation:null,value:e,line:e.line}}parseIf(){const t=this.advance().line,e=this.parseExpression();this.skipNewlines();const s=this.parseBlock(),r=[];let n=null;for(;this.check(a.ELSE);)if(this.advance(),this.check(a.IF)){this.advance();const l=this.parseExpression();this.skipNewlines();const h=this.parseBlock();r.push({condition:l,body:h})}else{this.skipNewlines(),n=this.parseBlock();break}return{type:"If",condition:e,body:s,elseIf:r,elseBody:n,line:t}}parseFor(){const t=this.advance().line,e=this.expect(a.IDENTIFIER).value;if(this.check(a.IN)){this.advance();const h=this.parseExpression();this.skipNewlines();const c=this.parseBlock();return{type:"ForIn",variable:e,iterable:h,body:c,line:t}}this.expect(a.ASSIGN);const s=this.parseExpression();this.expect(a.TO);const r=this.parseExpression();let n=null;this.check(a.BY)&&(this.advance(),n=this.parseExpression()),this.skipNewlines();const l=this.parseBlock();return{type:"For",variable:e,start:s,end:r,step:n,body:l,line:t}}parseWhile(){const t=this.advance().line,e=this.parseExpression();this.skipNewlines();const s=this.parseBlock();return{type:"While",condition:e,body:s,line:t}}parseSwitch(){const t=this.advance().line;let e=null;!this.check(a.NEWLINE)&&!this.check(a.INDENT)&&(e=this.parseExpression()),this.skipNewlines();const s=[];let r=null;if(this.match(a.INDENT)){for(;!this.check(a.DEDENT)&&!this.isAtEnd()&&(this.skipNewlines(),!this.check(a.DEDENT));){if(this.check(a.ARROW))this.advance(),this.skipNewlines(),r=this.parseBlock();else{const n=this.parseExpression();this.expect(a.ARROW),this.skipNewlines();const l=this.parseBlockOrExpr();s.push({condition:n,body:l})}this.skipNewlines()}this.check(a.DEDENT)&&this.advance()}return{type:"Switch",expression:e,cases:s,defaultBody:r,line:t}}parseReturn(){const t=this.advance().line;let e=null;return!this.check(a.NEWLINE)&&!this.check(a.DEDENT)&&!this.isAtEnd()&&(e=this.parseExpression()),{type:"Return",value:e,line:t}}isFunctionDef(){var s;let t=0,e=this.pos+1;for(;e<this.tokens.length;){if(this.tokens[e].type===a.LPAREN&&t++,this.tokens[e].type===a.RPAREN&&(t--,t===0))return((s=this.tokens[e+1])==null?void 0:s.type)===a.ARROW;if(this.tokens[e].type===a.NEWLINE||this.tokens[e].type===a.EOF)return!1;e++}return!1}parseFunctionDef(){const t=this.advance().value;this.expect(a.LPAREN);const e=[];if(!this.check(a.RPAREN))do{const r=this.expect(a.IDENTIFIER).value;let n=null;this.match(a.ASSIGN)&&(n=this.parseExpression()),e.push({name:r,defaultValue:n})}while(this.match(a.COMMA));this.expect(a.RPAREN),this.expect(a.ARROW),this.skipNewlines();const s=this.parseBlock();return{type:"FunctionDef",name:t,params:e,body:s,line:this.previous().line}}parsePlotCall(){const t=this.advance().value;this.expect(a.LPAREN);const{positional:e,named:s}=this.parseCallArgs();return this.expect(a.RPAREN),{type:"PlotCall",function:t,args:e,kwargs:s,line:this.previous().line}}parseHlineCall(){this.advance(),this.expect(a.LPAREN);const{positional:t,named:e}=this.parseCallArgs();return this.expect(a.RPAREN),{type:"HlineCall",price:t[0],args:t.slice(1),kwargs:e,line:this.previous().line}}parseExpression(){return this.parseTernary()}parseTernary(){let t=this.parseOr();if(this.match(a.QUESTION)){const e=this.parseExpression();this.expect(a.COLON);const s=this.parseExpression();t={type:"TernaryExpr",condition:t,consequent:e,alternate:s,line:t.line}}return t}parseOr(){let t=this.parseAnd();for(;this.match(a.OR);){const e=this.parseAnd();t={type:"BinaryExpr",operator:"or",left:t,right:e,line:t.line}}return t}parseAnd(){let t=this.parseComparison();for(;this.match(a.AND);){const e=this.parseComparison();t={type:"BinaryExpr",operator:"and",left:t,right:e,line:t.line}}return t}parseComparison(){let t=this.parseAddition();for(;this.checkAny(a.EQ,a.NEQ,a.LT,a.GT,a.LTE,a.GTE);){const e=this.advance().value,s=this.parseAddition();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parseAddition(){let t=this.parseMultiplication();for(;this.checkAny(a.PLUS,a.MINUS);){const e=this.advance().value,s=this.parseMultiplication();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parseMultiplication(){let t=this.parsePower();for(;this.checkAny(a.STAR,a.SLASH,a.PERCENT);){const e=this.advance().value,s=this.parsePower();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parsePower(){let t=this.parseUnary();if(this.match(a.POWER)){const e=this.parseUnary();t={type:"BinaryExpr",operator:"**",left:t,right:e,line:t.line}}return t}parseUnary(){if(this.match(a.MINUS)){const t=this.parseUnary();return{type:"UnaryExpr",operator:"-",operand:t,line:t.line}}if(this.match(a.NOT)){const t=this.parseUnary();return{type:"UnaryExpr",operator:"not",operand:t,line:t.line}}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();for(;;)if(this.match(a.LBRACKET)){const e=this.parseExpression();this.expect(a.RBRACKET),t={type:"SeriesAccess",series:t,offset:e,line:t.line}}else if(this.match(a.DOT)){const e=this.expect(a.IDENTIFIER).value;if(this.check(a.LPAREN)){const s=this.buildCalleeName(t)+"."+e;this.advance();const{positional:r,named:n}=this.parseCallArgs();this.expect(a.RPAREN),t={type:"FunctionCall",callee:s,args:r,kwargs:n,line:t.line}}else t={type:"MemberExpr",object:t,property:e,line:t.line}}else if(this.check(a.LPAREN)&&t.type==="Identifier"){const e=t.name;this.advance();const{positional:s,named:r}=this.parseCallArgs();this.expect(a.RPAREN),t={type:"FunctionCall",callee:e,args:s,kwargs:r,line:t.line}}else break;return t}parsePrimary(){const t=this.peek();if(this.check(a.NUMBER))return this.advance(),{type:"NumberLiteral",value:parseFloat(t.value),line:t.line};if(this.check(a.STRING))return this.advance(),{type:"StringLiteral",value:t.value,line:t.line};if(this.check(a.TRUE))return this.advance(),{type:"BoolLiteral",value:!0,line:t.line};if(this.check(a.FALSE))return this.advance(),{type:"BoolLiteral",value:!1,line:t.line};if(this.check(a.NA))return this.advance(),{type:"NaLiteral",line:t.line};if(this.check(a.COLOR_LITERAL))return this.advance(),{type:"ColorLiteral",value:t.value,line:t.line};if(this.match(a.LPAREN)){const e=this.parseExpression();return this.expect(a.RPAREN),e}if(this.check(a.IDENTIFIER))return this.advance(),{type:"Identifier",name:t.value,line:t.line};if(this.check(a.IF)){const e=this.parseIf();return{type:"Identifier",name:"__if_expr__",line:e.line,_ifNode:e}}throw new L(`Unexpected token: ${t.type} (${t.value})`,t.line,t.column)}parseCallArgs(){var s;const t=[],e=[];if(this.check(a.RPAREN))return{positional:t,named:e};do{if(this.skipNewlines(),this.check(a.RPAREN))break;if(this.check(a.IDENTIFIER)&&((s=this.peekAt(1))==null?void 0:s.type)===a.ASSIGN){const r=this.advance().value;this.advance();const n=this.parseExpression();e.push({key:r,value:n})}else t.push(this.parseExpression());this.skipNewlines()}while(this.match(a.COMMA));return{positional:t,named:e}}parseBlock(){const t=[];if(this.match(a.INDENT)){for(;!this.check(a.DEDENT)&&!this.isAtEnd()&&(this.skipNewlines(),!this.check(a.DEDENT));){const e=this.parseStatement();e&&t.push(e),this.skipNewlines()}this.check(a.DEDENT)&&this.advance()}else{const e=this.parseStatement();e&&t.push(e)}return t}parseBlockOrExpr(){if(this.check(a.INDENT))return this.parseBlock();const t=this.parseExpression();return[{type:"ExpressionStatement",expression:t,line:t.line}]}buildCalleeName(t){return t.type==="Identifier"?t.name:t.type==="MemberExpr"?this.buildCalleeName(t.object)+"."+t.property:"__unknown__"}peek(){return this.tokens[this.pos]}peekAt(t){return this.tokens[this.pos+t]}previous(){return this.tokens[this.pos-1]}isAtEnd(){return this.pos>=this.tokens.length||this.tokens[this.pos].type===a.EOF}advance(){return this.isAtEnd()||this.pos++,this.previous()}check(t){return!this.isAtEnd()&&this.peek().type===t}checkAny(...t){return!this.isAtEnd()&&t.includes(this.peek().type)}match(t){return this.check(t)?(this.advance(),!0):!1}expect(t){if(this.check(t))return this.advance();const e=this.peek();throw new L(`Expected ${t} but got ${e==null?void 0:e.type} (${e==null?void 0:e.value})`,e==null?void 0:e.line,e==null?void 0:e.column)}skipNewlines(){for(;this.check(a.NEWLINE);)this.advance()}}/**
29
+ */const j=new Set(["plot","plotshape","plotarrow","plotbar","plotcandle","plotchar","bgcolor","fill"]),$=new Set(["int","float","bool","string","color","label","line","box","table","series","simple"]);class C{constructor(t){p(this,"tokens");p(this,"pos",0);this.tokens=t}parse(){const t=[],e=[];for(this.skipNewlines();!this.isAtEnd()&&(this.skipNewlines(),!this.isAtEnd());){if(this.check(a.COMPILER_ANNOTATION)){e.push({type:"Annotation",value:this.advance().value,line:this.previous().line}),this.skipNewlines();continue}const s=this.parseStatement();s&&t.push(s),this.skipNewlines()}return{type:"Program",body:t,annotations:e}}parseStatement(){if(this.check(a.VAR)||this.check(a.VARIP))return this.parseVarDecl();if(this.check(a.IF))return this.parseIf();if(this.check(a.FOR))return this.parseFor();if(this.check(a.WHILE))return this.parseWhile();if(this.check(a.SWITCH))return this.parseSwitch();if(this.check(a.BREAK))return this.advance(),{type:"Break",line:this.previous().line};if(this.check(a.CONTINUE))return this.advance(),{type:"Continue",line:this.previous().line};if(this.check(a.RETURN))return this.parseReturn();if(this.check(a.IMPORT))return this.parseImport();if(this.check(a.EXPORT))return this.parseExport();if(this.check(a.TYPE))return this.parseTypeDef();if(this.check(a.METHOD))return this.parseMethodDef();if(this.check(a.IDENTIFIER))return this.parseIdentifierStatement();if(this.check(a.LBRACKET))return this.parseTupleAssign();const t=this.parseExpression();return{type:"ExpressionStatement",expression:t,line:t.line}}parseIdentifierStatement(){var s,r,n,l,h;const t=this.peek();if((t.value==="indicator"||t.value==="strategy"||t.value==="library")&&((s=this.peekAt(1))==null?void 0:s.type)===a.LPAREN)return this.parseIndicator();if(j.has(t.value)&&((r=this.peekAt(1))==null?void 0:r.type)===a.LPAREN)return this.parsePlotCall();if(t.value==="hline"&&((n=this.peekAt(1))==null?void 0:n.type)===a.LPAREN)return this.parseHlineCall();if(((l=this.peekAt(1))==null?void 0:l.type)===a.LPAREN&&this.isFunctionDef())return this.parseFunctionDef();if(this.isTypeAnnotation())return this.parseTypedDecl();if((h=this.peekAt(1))!=null&&h.isAny(a.ASSIGN,a.REASSIGN,a.PLUS_ASSIGN,a.MINUS_ASSIGN,a.STAR_ASSIGN,a.SLASH_ASSIGN,a.PERCENT_ASSIGN))return this.parseAssignment();const e=this.parseExpression();return{type:"ExpressionStatement",expression:e,line:e.line}}parseIndicator(){const t=this.advance();this.expect(a.LPAREN);const e=this.parseCallArgs();return this.expect(a.RPAREN),{type:"Indicator",name:e.positional[0]??{type:"StringLiteral",value:"Untitled",line:t.line},args:e.named,line:t.line}}parseVarDecl(){const t=this.check(a.VAR),e=this.check(a.VARIP);this.advance();let s=null;this.isTypeAnnotation()&&(s=this.parseTypeAnnotationString());const r=this.expect(a.IDENTIFIER).value;this.expect(a.ASSIGN);const n=this.parseExpression();return{type:"VarDecl",persistent:t,persistentTick:e,name:r,typeAnnotation:s,value:n,line:n.line}}parseTypedDecl(){const t=this.parseTypeAnnotationString(),e=this.expect(a.IDENTIFIER).value;this.expect(a.ASSIGN);const s=this.parseExpression();return{type:"VarDecl",persistent:!1,persistentTick:!1,name:e,typeAnnotation:t,value:s,line:s.line}}parseAssignment(){const t=this.advance().value,e=this.advance(),s=this.parseExpression();return{type:"Assign",target:t,operator:e.value,value:s,line:e.line}}parseTupleAssign(){this.expect(a.LBRACKET);const t=[];for(t.push(this.expect(a.IDENTIFIER).value);this.match(a.COMMA);)t.push(this.expect(a.IDENTIFIER).value);this.expect(a.RBRACKET),this.expect(a.ASSIGN);const e=this.parseExpression();return{type:"VarDecl",persistent:!1,persistentTick:!1,name:t,typeAnnotation:null,value:e,line:e.line}}parseIf(){const t=this.advance().line,e=this.parseExpression();this.skipNewlines();const s=this.parseBlock(),r=[];let n=null;for(;this.check(a.ELSE);)if(this.advance(),this.check(a.IF)){this.advance();const l=this.parseExpression();this.skipNewlines();const h=this.parseBlock();r.push({condition:l,body:h})}else{this.skipNewlines(),n=this.parseBlock();break}return{type:"If",condition:e,body:s,elseIf:r,elseBody:n,line:t}}parseFor(){const t=this.advance().line,e=this.expect(a.IDENTIFIER).value;if(this.check(a.IN)){this.advance();const h=this.parseExpression();this.skipNewlines();const c=this.parseBlock();return{type:"ForIn",variable:e,iterable:h,body:c,line:t}}this.expect(a.ASSIGN);const s=this.parseExpression();this.expect(a.TO);const r=this.parseExpression();let n=null;this.check(a.BY)&&(this.advance(),n=this.parseExpression()),this.skipNewlines();const l=this.parseBlock();return{type:"For",variable:e,start:s,end:r,step:n,body:l,line:t}}parseWhile(){const t=this.advance().line,e=this.parseExpression();this.skipNewlines();const s=this.parseBlock();return{type:"While",condition:e,body:s,line:t}}parseSwitch(){const t=this.advance().line;let e=null;!this.check(a.NEWLINE)&&!this.check(a.INDENT)&&(e=this.parseExpression()),this.skipNewlines();const s=[];let r=null;if(this.match(a.INDENT)){for(;!this.check(a.DEDENT)&&!this.isAtEnd()&&(this.skipNewlines(),!this.check(a.DEDENT));){if(this.check(a.ARROW))this.advance(),this.skipNewlines(),r=this.parseBlock();else{const n=this.parseExpression();this.expect(a.ARROW),this.skipNewlines();const l=this.parseBlockOrExpr();s.push({condition:n,body:l})}this.skipNewlines()}this.check(a.DEDENT)&&this.advance()}return{type:"Switch",expression:e,cases:s,defaultBody:r,line:t}}parseReturn(){const t=this.advance().line;let e=null;return!this.check(a.NEWLINE)&&!this.check(a.DEDENT)&&!this.isAtEnd()&&(e=this.parseExpression()),{type:"Return",value:e,line:t}}parseImport(){const t=this.advance().line,e=[];for(e.push(this.expect(a.IDENTIFIER).value);this.match(a.SLASH);)(this.check(a.IDENTIFIER)||this.check(a.NUMBER))&&e.push(this.advance().value);const s=e.join("/");let r=null;return this.check(a.IDENTIFIER)&&this.peek().value==="as"&&(this.advance(),r=this.expect(a.IDENTIFIER).value),{type:"Import",path:s,alias:r,line:t}}parseExport(){const t=this.advance().line,e=this.parseStatement();if(!e)throw new x("Expected declaration after export",t,0);return{type:"Export",declaration:e,line:t}}parseTypeDef(){const t=this.advance().line,e=this.expect(a.IDENTIFIER).value;this.skipNewlines();const s=[];if(this.match(a.INDENT)){for(;!this.check(a.DEDENT)&&!this.isAtEnd()&&(this.skipNewlines(),!this.check(a.DEDENT));){let r=null;this.isTypeAnnotation()?r=this.parseTypeAnnotationString():r=this.advance().value;const n=this.expect(a.IDENTIFIER).value;let l=null;this.match(a.ASSIGN)&&(l=this.parseExpression()),s.push({name:n,typeAnnotation:r,defaultValue:l}),this.skipNewlines()}this.check(a.DEDENT)&&this.advance()}return{type:"TypeDef",name:e,fields:s,line:t}}parseMethodDef(){const t=this.advance().line,e=this.expect(a.IDENTIFIER).value;this.expect(a.LPAREN);const s=[];if(!this.check(a.RPAREN))do{let n=null;this.isTypeAnnotation()?n=this.parseTypeAnnotationString():$.has(this.peek().value)&&(n=this.advance().value);const l=this.expect(a.IDENTIFIER).value;let h=null;this.match(a.ASSIGN)&&(h=this.parseExpression()),s.push({name:l,typeAnnotation:n,defaultValue:h})}while(this.match(a.COMMA));this.expect(a.RPAREN),this.expect(a.ARROW),this.skipNewlines();const r=this.parseBlock();return{type:"MethodDef",name:e,params:s,body:r,line:t}}isFunctionDef(){var s;let t=0,e=this.pos+1;for(;e<this.tokens.length;){if(this.tokens[e].type===a.LPAREN&&t++,this.tokens[e].type===a.RPAREN&&(t--,t===0))return((s=this.tokens[e+1])==null?void 0:s.type)===a.ARROW;if(this.tokens[e].type===a.NEWLINE||this.tokens[e].type===a.EOF)return!1;e++}return!1}parseFunctionDef(){const t=this.advance().value;this.expect(a.LPAREN);const e=[];if(!this.check(a.RPAREN))do{const r=this.expect(a.IDENTIFIER).value;let n=null;this.match(a.ASSIGN)&&(n=this.parseExpression()),e.push({name:r,defaultValue:n})}while(this.match(a.COMMA));this.expect(a.RPAREN),this.expect(a.ARROW),this.skipNewlines();const s=this.parseBlock();return{type:"FunctionDef",name:t,params:e,body:s,line:this.previous().line}}parsePlotCall(){const t=this.advance().value;this.expect(a.LPAREN);const{positional:e,named:s}=this.parseCallArgs();return this.expect(a.RPAREN),{type:"PlotCall",function:t,args:e,kwargs:s,line:this.previous().line}}parseHlineCall(){this.advance(),this.expect(a.LPAREN);const{positional:t,named:e}=this.parseCallArgs();return this.expect(a.RPAREN),{type:"HlineCall",price:t[0],args:t.slice(1),kwargs:e,line:this.previous().line}}parseExpression(){return this.parseTernary()}parseTernary(){let t=this.parseOr();if(this.match(a.QUESTION)){const e=this.parseExpression();this.expect(a.COLON);const s=this.parseExpression();t={type:"TernaryExpr",condition:t,consequent:e,alternate:s,line:t.line}}return t}parseOr(){let t=this.parseAnd();for(;this.match(a.OR);){const e=this.parseAnd();t={type:"BinaryExpr",operator:"or",left:t,right:e,line:t.line}}return t}parseAnd(){let t=this.parseComparison();for(;this.match(a.AND);){const e=this.parseComparison();t={type:"BinaryExpr",operator:"and",left:t,right:e,line:t.line}}return t}parseComparison(){let t=this.parseAddition();for(;this.checkAny(a.EQ,a.NEQ,a.LT,a.GT,a.LTE,a.GTE);){const e=this.advance().value,s=this.parseAddition();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parseAddition(){let t=this.parseMultiplication();for(;this.checkAny(a.PLUS,a.MINUS);){const e=this.advance().value,s=this.parseMultiplication();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parseMultiplication(){let t=this.parsePower();for(;this.checkAny(a.STAR,a.SLASH,a.PERCENT);){const e=this.advance().value,s=this.parsePower();t={type:"BinaryExpr",operator:e,left:t,right:s,line:t.line}}return t}parsePower(){let t=this.parseUnary();if(this.match(a.POWER)){const e=this.parseUnary();t={type:"BinaryExpr",operator:"**",left:t,right:e,line:t.line}}return t}parseUnary(){if(this.match(a.MINUS)){const t=this.parseUnary();return{type:"UnaryExpr",operator:"-",operand:t,line:t.line}}if(this.match(a.NOT)){const t=this.parseUnary();return{type:"UnaryExpr",operator:"not",operand:t,line:t.line}}return this.parsePostfix()}parsePostfix(){var e,s,r,n,l,h;let t=this.parsePrimary();for(;;)if(this.match(a.LBRACKET)){const c=this.parseExpression();this.expect(a.RBRACKET),t={type:"SeriesAccess",series:t,offset:c,line:t.line}}else if(this.match(a.DOT)){const c=this.expect(a.IDENTIFIER).value;let o=!1;if((this.check(a.LPAREN)||this.check(a.LT)&&((e=this.peekAt(1))==null?void 0:e.type)===a.IDENTIFIER&&((s=this.peekAt(2))==null?void 0:s.type)===a.GT&&((r=this.peekAt(3))==null?void 0:r.type)===a.LPAREN)&&(o=!0),o){const u=this.buildCalleeName(t)+"."+c;this.check(a.LT)&&(this.advance(),this.advance(),this.advance()),this.advance();const{positional:f,named:m}=this.parseCallArgs();this.expect(a.RPAREN),t={type:"FunctionCall",callee:u,args:f,kwargs:m,line:t.line}}else t={type:"MemberExpr",object:t,property:c,line:t.line}}else if((this.check(a.LPAREN)||this.check(a.LT))&&t.type==="Identifier"){const c=t.name;if(this.check(a.LT))if(((n=this.peekAt(1))==null?void 0:n.type)===a.IDENTIFIER&&((l=this.peekAt(2))==null?void 0:l.type)===a.GT&&((h=this.peekAt(3))==null?void 0:h.type)===a.LPAREN)this.advance(),this.advance(),this.advance();else break;if(this.check(a.LPAREN)){this.advance();const{positional:o,named:u}=this.parseCallArgs();this.expect(a.RPAREN),t={type:"FunctionCall",callee:c,args:o,kwargs:u,line:t.line}}else break}else break;return t}parsePrimary(){const t=this.peek();if(this.check(a.NUMBER))return this.advance(),{type:"NumberLiteral",value:parseFloat(t.value),line:t.line};if(this.check(a.STRING))return this.advance(),{type:"StringLiteral",value:t.value,line:t.line};if(this.check(a.TRUE))return this.advance(),{type:"BoolLiteral",value:!0,line:t.line};if(this.check(a.FALSE))return this.advance(),{type:"BoolLiteral",value:!1,line:t.line};if(this.check(a.NA))return this.advance(),{type:"NaLiteral",line:t.line};if(this.check(a.COLOR_LITERAL))return this.advance(),{type:"ColorLiteral",value:t.value,line:t.line};if(this.match(a.LBRACKET)){const e=[];if(!this.check(a.RBRACKET))do e.push(this.parseExpression());while(this.match(a.COMMA));return this.expect(a.RBRACKET),{type:"ArrayLiteral",elements:e,line:t.line}}if(this.match(a.LPAREN)){const e=this.parseExpression();return this.expect(a.RPAREN),e}if(this.check(a.IDENTIFIER))return this.advance(),{type:"Identifier",name:t.value,line:t.line};if(this.check(a.IF)){const e=this.parseIf();return{type:"Identifier",name:"__if_expr__",line:e.line,_ifNode:e}}if(this.check(a.SWITCH)){const e=this.parseSwitch();return{type:"Identifier",name:"__switch_expr__",line:e.line,_switchNode:e}}throw new x(`Unexpected token: ${t.type} (${t.value})`,t.line,t.column)}parseCallArgs(){var s;const t=[],e=[];if(this.check(a.RPAREN))return{positional:t,named:e};do{if(this.skipNewlines(),this.check(a.RPAREN))break;if(this.check(a.IDENTIFIER)&&((s=this.peekAt(1))==null?void 0:s.type)===a.ASSIGN){const r=this.advance().value;this.advance();const n=this.parseExpression();e.push({key:r,value:n})}else t.push(this.parseExpression());this.skipNewlines()}while(this.match(a.COMMA));return{positional:t,named:e}}parseBlock(){const t=[];if(this.match(a.INDENT)){for(;!this.check(a.DEDENT)&&!this.isAtEnd()&&(this.skipNewlines(),!this.check(a.DEDENT));){const e=this.parseStatement();e&&t.push(e),this.skipNewlines()}this.check(a.DEDENT)&&this.advance()}else{const e=this.parseStatement();e&&t.push(e)}return t}parseBlockOrExpr(){if(this.check(a.INDENT))return this.parseBlock();const t=this.parseExpression();return[{type:"ExpressionStatement",expression:t,line:t.line}]}isTypeAnnotation(){var t,e,s,r;return this.check(a.IDENTIFIER)?((t=this.peekAt(1))==null?void 0:t.type)===a.IDENTIFIER||((e=this.peekAt(1))==null?void 0:e.type)===a.LBRACKET&&((s=this.peekAt(2))==null?void 0:s.type)===a.RBRACKET&&((r=this.peekAt(3))==null?void 0:r.type)===a.IDENTIFIER:!1}parseTypeAnnotationString(){let t=this.advance().value;return this.match(a.LBRACKET)&&(this.expect(a.RBRACKET),t+="[]"),t}buildCalleeName(t){return t.type==="Identifier"?t.name:t.type==="MemberExpr"?this.buildCalleeName(t.object)+"."+t.property:"__unknown__"}peek(){return this.tokens[this.pos]}peekAt(t){return this.tokens[this.pos+t]}previous(){return this.tokens[this.pos-1]}isAtEnd(){return this.pos>=this.tokens.length||this.tokens[this.pos].type===a.EOF}advance(){return this.isAtEnd()||this.pos++,this.previous()}check(t){return!this.isAtEnd()&&this.peek().type===t}checkAny(...t){return!this.isAtEnd()&&t.includes(this.peek().type)}match(t){return this.check(t)?(this.advance(),!0):!1}expect(t){if(this.check(t))return this.advance();const e=this.peek();throw new x(`Expected ${t} but got ${e==null?void 0:e.type} (${e==null?void 0:e.value})`,e==null?void 0:e.line,e==null?void 0:e.column)}skipNewlines(){for(;this.check(a.NEWLINE);)this.advance()}}/**
30
30
  * pine-to-kline — Bar Context
31
31
  * Provides per-bar OHLCV data as series for the runtime
32
32
  * @license Apache-2.0
33
- */class C{constructor(t){p(this,"dataList");p(this,"open");p(this,"high");p(this,"low");p(this,"close");p(this,"volume");p(this,"hl2");p(this,"hlc3");p(this,"ohlc4");p(this,"time");p(this,"barCount");this.dataList=t,this.barCount=t.length,this.open=t.map(e=>e.open),this.high=t.map(e=>e.high),this.low=t.map(e=>e.low),this.close=t.map(e=>e.close),this.volume=t.map(e=>e.volume??0),this.hl2=t.map(e=>(e.high+e.low)/2),this.hlc3=t.map(e=>(e.high+e.low+e.close)/3),this.ohlc4=t.map(e=>(e.open+e.high+e.low+e.close)/4),this.time=t.map(e=>e.timestamp)}resolveSource(t){return{open:this.open,high:this.high,low:this.low,close:this.close,volume:this.volume,hl2:this.hl2,hlc3:this.hlc3,ohlc4:this.ohlc4,time:this.time}[t]??this.close}}/**
33
+ */class b{constructor(t){p(this,"dataList");p(this,"open");p(this,"high");p(this,"low");p(this,"close");p(this,"volume");p(this,"hl2");p(this,"hlc3");p(this,"ohlc4");p(this,"time");p(this,"barCount");this.dataList=t,this.barCount=t.length,this.open=t.map(e=>e.open),this.high=t.map(e=>e.high),this.low=t.map(e=>e.low),this.close=t.map(e=>e.close),this.volume=t.map(e=>e.volume??0),this.hl2=t.map(e=>(e.high+e.low)/2),this.hlc3=t.map(e=>(e.high+e.low+e.close)/3),this.ohlc4=t.map(e=>(e.open+e.high+e.low+e.close)/4),this.time=t.map(e=>e.timestamp)}resolveSource(t){return{open:this.open,high:this.high,low:this.low,close:this.close,volume:this.volume,hl2:this.hl2,hlc3:this.hlc3,ohlc4:this.ohlc4,time:this.time}[t]??this.close}}/**
34
34
  * pine-to-kline — Variable Persistence
35
35
  * Emulates Pine's `var` and `varip` semantics
36
36
  * @license Apache-2.0
@@ -38,15 +38,15 @@
38
38
  * pine-to-kline — Moving Average Functions
39
39
  * Implements: sma, ema, rma, wma, hma, vwma, swma, dema, tema
40
40
  * @license Apache-2.0
41
- */function O(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=0;for(let n=s-t+1;n<=s;n++)r+=i[n];return r/t})}function E(i,t){const e=2/(t+1),s=[];for(let r=0;r<i.length;r++){if(r===0){s.push(i[r]);continue}s.push(i[r]*e+s[r-1]*(1-e))}return s}function g(i,t){const e=1/t,s=[];for(let r=0;r<i.length;r++){if(r<t-1){s.push(NaN);continue}if(r===t-1){let n=0;for(let l=0;l<t;l++)n+=i[l];s.push(n/t)}else s.push(e*i[r]+(1-e)*s[r-1])}return s}function x(i,t){const e=t*(t+1)/2;return i.map((s,r)=>{if(r<t-1)return NaN;let n=0;for(let l=0;l<t;l++)n+=i[r-l]*(t-l);return n/e})}function Y(i,t){const e=Math.floor(t/2),s=Math.round(Math.sqrt(t)),r=x(i,e),n=x(i,t),l=r.map((h,c)=>2*h-n[c]);return x(l,s)}function Q(i,t,e){return i.map((s,r)=>{if(r<e-1)return NaN;let n=0,l=0;for(let h=r-e+1;h<=r;h++)n+=i[h]*t[h],l+=t[h];return l===0?NaN:n/l})}function q(i){return i.map((t,e)=>e<3?NaN:i[e]*(1/6)+i[e-1]*(2/6)+i[e-2]*(2/6)+i[e-3]*(1/6))}function z(i,t){const e=E(i,t),s=E(e,t);return e.map((r,n)=>2*r-s[n])}function X(i,t){const e=E(i,t),s=E(e,t),r=E(s,t);return e.map((n,l)=>3*n-3*s[l]+r[l])}/**
41
+ */function T(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=0;for(let n=s-t+1;n<=s;n++)r+=i[n];return r/t})}function d(i,t){const e=2/(t+1),s=[];for(let r=0;r<i.length;r++){if(r===0){s.push(i[r]);continue}s.push(i[r]*e+s[r-1]*(1-e))}return s}function g(i,t){const e=1/t,s=[];for(let r=0;r<i.length;r++){if(r<t-1){s.push(NaN);continue}if(r===t-1){let n=0;for(let l=0;l<t;l++)n+=i[l];s.push(n/t)}else s.push(e*i[r]+(1-e)*s[r-1])}return s}function k(i,t){const e=t*(t+1)/2;return i.map((s,r)=>{if(r<t-1)return NaN;let n=0;for(let l=0;l<t;l++)n+=i[r-l]*(t-l);return n/e})}function Y(i,t){const e=Math.floor(t/2),s=Math.round(Math.sqrt(t)),r=k(i,e),n=k(i,t),l=r.map((h,c)=>2*h-n[c]);return k(l,s)}function Q(i,t,e){return i.map((s,r)=>{if(r<e-1)return NaN;let n=0,l=0;for(let h=r-e+1;h<=r;h++)n+=i[h]*t[h],l+=t[h];return l===0?NaN:n/l})}function q(i){return i.map((t,e)=>e<3?NaN:i[e]*(1/6)+i[e-1]*(2/6)+i[e-2]*(2/6)+i[e-3]*(1/6))}function z(i,t){const e=d(i,t),s=d(e,t);return e.map((r,n)=>2*r-s[n])}function X(i,t){const e=d(i,t),s=d(e,t),r=d(s,t);return e.map((n,l)=>3*n-3*s[l]+r[l])}/**
42
42
  * pine-to-kline — Momentum Indicators
43
43
  * Implements: rsi, macd, stoch, cci, mom, roc
44
44
  * @license Apache-2.0
45
- */function Z(i,t){const e=[0],s=[0];for(let l=1;l<i.length;l++){const h=i[l]-i[l-1];e.push(h>0?h:0),s.push(h<0?Math.abs(h):0)}const r=g(e,t),n=g(s,t);return i.map((l,h)=>isNaN(r[h])||isNaN(n[h])?NaN:n[h]===0?100:100-100/(1+r[h]/n[h]))}function J(i,t=12,e=26,s=9){const r=E(i,t),n=E(i,e),l=r.map((o,u)=>o-n[u]),h=E(l,s),c=l.map((o,u)=>o-h[u]);return{macd:l,signal:h,hist:c}}function tt(i,t,e,s){return i.map((r,n)=>{if(n<s-1)return NaN;let l=-1/0,h=1/0;for(let c=n-s+1;c<=n;c++)t[c]>l&&(l=t[c]),e[c]<h&&(h=e[c]);return l===h?0:(i[n]-h)/(l-h)*100})}function et(i,t){const e=O(i,t);return i.map((s,r)=>{if(r<t-1)return NaN;let n=0;for(let l=r-t+1;l<=r;l++)n+=Math.abs(i[l]-e[r]);return n/=t,n===0?0:(i[r]-e[r])/(.015*n)})}function st(i,t){return i.map((e,s)=>s<t?NaN:e-i[s-t])}function it(i,t){return i.map((e,s)=>{if(s<t)return NaN;const r=i[s-t];return r===0?0:(e-r)/r*100})}/**
45
+ */function Z(i,t){const e=[0],s=[0];for(let l=1;l<i.length;l++){const h=i[l]-i[l-1];e.push(h>0?h:0),s.push(h<0?Math.abs(h):0)}const r=g(e,t),n=g(s,t);return i.map((l,h)=>isNaN(r[h])||isNaN(n[h])?NaN:n[h]===0?100:100-100/(1+r[h]/n[h]))}function J(i,t=12,e=26,s=9){const r=d(i,t),n=d(i,e),l=r.map((o,u)=>o-n[u]),h=d(l,s),c=l.map((o,u)=>o-h[u]);return{macd:l,signal:h,hist:c}}function tt(i,t,e,s){return i.map((r,n)=>{if(n<s-1)return NaN;let l=-1/0,h=1/0;for(let c=n-s+1;c<=n;c++)t[c]>l&&(l=t[c]),e[c]<h&&(h=e[c]);return l===h?0:(i[n]-h)/(l-h)*100})}function et(i,t){const e=T(i,t);return i.map((s,r)=>{if(r<t-1)return NaN;let n=0;for(let l=r-t+1;l<=r;l++)n+=Math.abs(i[l]-e[r]);return n/=t,n===0?0:(i[r]-e[r])/(.015*n)})}function st(i,t){return i.map((e,s)=>s<t?NaN:e-i[s-t])}function it(i,t){return i.map((e,s)=>{if(s<t)return NaN;const r=i[s-t];return r===0?0:(e-r)/r*100})}/**
46
46
  * pine-to-kline — Volatility Indicators
47
47
  * Implements: atr, bb, kc, donchian
48
48
  * @license Apache-2.0
49
- */function T(i,t,e,s){const r=i.map((n,l)=>l===0?n-t[l]:Math.max(n-t[l],Math.abs(n-e[l-1]),Math.abs(t[l]-e[l-1])));return g(r,s)}function rt(i,t,e=2){const s=O(i,t);return i.map((r,n)=>{if(n<t-1)return{upper:NaN,basis:NaN,lower:NaN};let l=0;for(let c=n-t+1;c<=n;c++)l+=Math.pow(i[c]-s[n],2);const h=Math.sqrt(l/t);return{upper:s[n]+e*h,basis:s[n],lower:s[n]-e*h}})}function nt(i,t,e,s,r,n=1.5){const l=E(i,r),h=T(t,e,s,r);return i.map((c,o)=>({upper:l[o]+n*h[o],basis:l[o],lower:l[o]-n*h[o]}))}function at(i,t,e){return i.map((s,r)=>{if(r<e-1)return{upper:NaN,basis:NaN,lower:NaN};let n=-1/0,l=1/0;for(let h=r-e+1;h<=r;h++)i[h]>n&&(n=i[h]),t[h]<l&&(l=t[h]);return{upper:n,basis:(n+l)/2,lower:l}})}function lt(i,t,e){return i.map((s,r)=>r===0?s-t[r]:Math.max(s-t[r],Math.abs(s-e[r-1]),Math.abs(t[r]-e[r-1])))}/**
49
+ */function M(i,t,e,s){const r=i.map((n,l)=>l===0?n-t[l]:Math.max(n-t[l],Math.abs(n-e[l-1]),Math.abs(t[l]-e[l-1])));return g(r,s)}function rt(i,t,e=2){const s=T(i,t);return i.map((r,n)=>{if(n<t-1)return{upper:NaN,basis:NaN,lower:NaN};let l=0;for(let c=n-t+1;c<=n;c++)l+=Math.pow(i[c]-s[n],2);const h=Math.sqrt(l/t);return{upper:s[n]+e*h,basis:s[n],lower:s[n]-e*h}})}function nt(i,t,e,s,r,n=1.5){const l=d(i,r),h=M(t,e,s,r);return i.map((c,o)=>({upper:l[o]+n*h[o],basis:l[o],lower:l[o]-n*h[o]}))}function at(i,t,e){return i.map((s,r)=>{if(r<e-1)return{upper:NaN,basis:NaN,lower:NaN};let n=-1/0,l=1/0;for(let h=r-e+1;h<=r;h++)i[h]>n&&(n=i[h]),t[h]<l&&(l=t[h]);return{upper:n,basis:(n+l)/2,lower:l}})}function lt(i,t,e){return i.map((s,r)=>r===0?s-t[r]:Math.max(s-t[r],Math.abs(s-e[r-1]),Math.abs(t[r]-e[r-1])))}/**
50
50
  * pine-to-kline — Crossover Functions
51
51
  * Implements: crossover, crossunder, cross
52
52
  * @license Apache-2.0
@@ -54,52 +54,52 @@
54
54
  * pine-to-kline — TA Utility Functions
55
55
  * Implements: highest, lowest, highestbars, lowestbars, barssince, valuewhen, pivothigh, pivotlow
56
56
  * @license Apache-2.0
57
- */function Nt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=-1/0;for(let n=s-t+1;n<=s;n++)i[n]>r&&(r=i[n]);return r})}function mt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=1/0;for(let n=s-t+1;n<=s;n++)i[n]<r&&(r=i[n]);return r})}function Et(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=-1/0,n=s;for(let l=s-t+1;l<=s;l++)i[l]>=r&&(r=i[l],n=l);return-(s-n)})}function vt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=1/0,n=s;for(let l=s-t+1;l<=s;l++)i[l]<=r&&(r=i[l],n=l);return-(s-n)})}function dt(i){let t=NaN;return i.map(e=>(e?t=0:isNaN(t)||t++,t))}function At(i,t,e=0){const s=[],r=[];for(let n=0;n<t.length;n++)i[n]&&r.unshift(t[n]),s.push(r[e]??NaN);return s}function It(i,t,e){return i.map((s,r)=>{if(r<t||r+e>=i.length)return NaN;for(let n=r-t;n<r;n++)if(i[n]>s)return NaN;for(let n=r+1;n<=r+e;n++)if(i[n]>s)return NaN;return s})}function St(i,t,e){return i.map((s,r)=>{if(r<t||r+e>=i.length)return NaN;for(let n=r-t;n<r;n++)if(i[n]<s)return NaN;for(let n=r+1;n<=r+e;n++)if(i[n]<s)return NaN;return s})}function Rt(i){let t=0;return i.map(e=>(t+=e,t))}function yt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=0;for(let h=s-t+1;h<=s;h++)r+=i[h];const n=r/t;let l=0;for(let h=s-t+1;h<=s;h++)l+=Math.pow(i[h]-n,2);return Math.sqrt(l/t)})}function wt(i,t){return i.map((e,s)=>{if(s<t)return NaN;let r=0;for(let n=s-t;n<s;n++)i[n]<=e&&r++;return r/t*100})}/**
57
+ */function Nt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=-1/0;for(let n=s-t+1;n<=s;n++)i[n]>r&&(r=i[n]);return r})}function Et(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=1/0;for(let n=s-t+1;n<=s;n++)i[n]<r&&(r=i[n]);return r})}function mt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=-1/0,n=s;for(let l=s-t+1;l<=s;l++)i[l]>=r&&(r=i[l],n=l);return-(s-n)})}function dt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=1/0,n=s;for(let l=s-t+1;l<=s;l++)i[l]<=r&&(r=i[l],n=l);return-(s-n)})}function At(i){let t=NaN;return i.map(e=>(e?t=0:isNaN(t)||t++,t))}function vt(i,t,e=0){const s=[],r=[];for(let n=0;n<t.length;n++)i[n]&&r.unshift(t[n]),s.push(r[e]??NaN);return s}function It(i,t,e){return i.map((s,r)=>{if(r<t||r+e>=i.length)return NaN;for(let n=r-t;n<r;n++)if(i[n]>s)return NaN;for(let n=r+1;n<=r+e;n++)if(i[n]>s)return NaN;return s})}function Rt(i,t,e){return i.map((s,r)=>{if(r<t||r+e>=i.length)return NaN;for(let n=r-t;n<r;n++)if(i[n]<s)return NaN;for(let n=r+1;n<=r+e;n++)if(i[n]<s)return NaN;return s})}function St(i){let t=0;return i.map(e=>(t+=e,t))}function yt(i,t){return i.map((e,s)=>{if(s<t-1)return NaN;let r=0;for(let h=s-t+1;h<=s;h++)r+=i[h];const n=r/t;let l=0;for(let h=s-t+1;h<=s;h++)l+=Math.pow(i[h]-n,2);return Math.sqrt(l/t)})}function wt(i,t){return i.map((e,s)=>{if(s<t)return NaN;let r=0;for(let n=s-t;n<s;n++)i[n]<=e&&r++;return r/t*100})}/**
58
58
  * pine-to-kline — TA Namespace Barrel Export
59
59
  * @license Apache-2.0
60
- */const F={"ta.sma":O,"ta.ema":E,"ta.rma":g,"ta.wma":x,"ta.hma":Y,"ta.vwma":Q,"ta.swma":q,"ta.dema":z,"ta.tema":X,"ta.rsi":Z,"ta.macd":J,"ta.stoch":tt,"ta.cci":et,"ta.mom":st,"ta.roc":it,"ta.atr":T,"ta.bb":rt,"ta.kc":nt,"ta.donchian":at,"ta.tr":lt,"ta.crossover":ht,"ta.crossunder":ct,"ta.cross":ot,"ta.change":ut,"ta.rising":pt,"ta.falling":ft,"ta.highest":Nt,"ta.lowest":mt,"ta.highestbars":Et,"ta.lowestbars":vt,"ta.barssince":dt,"ta.valuewhen":At,"ta.pivothigh":It,"ta.pivotlow":St,"ta.cum":Rt,"ta.stdev":yt,"ta.percentrank":wt};/**
60
+ */const D={"ta.sma":T,"ta.ema":d,"ta.rma":g,"ta.wma":k,"ta.hma":Y,"ta.vwma":Q,"ta.swma":q,"ta.dema":z,"ta.tema":X,"ta.rsi":Z,"ta.macd":J,"ta.stoch":tt,"ta.cci":et,"ta.mom":st,"ta.roc":it,"ta.atr":M,"ta.bb":rt,"ta.kc":nt,"ta.donchian":at,"ta.tr":lt,"ta.crossover":ht,"ta.crossunder":ct,"ta.cross":ot,"ta.change":ut,"ta.rising":pt,"ta.falling":ft,"ta.highest":Nt,"ta.lowest":Et,"ta.highestbars":mt,"ta.lowestbars":dt,"ta.barssince":At,"ta.valuewhen":vt,"ta.pivothigh":It,"ta.pivotlow":Rt,"ta.cum":St,"ta.stdev":yt,"ta.percentrank":wt};/**
61
61
  * pine-to-kline — Math Namespace Functions
62
62
  * Wraps JavaScript Math.* to match Pine's math.* namespace
63
63
  * @license Apache-2.0
64
- */const gt={"math.abs":i=>Math.abs(i),"math.ceil":i=>Math.ceil(i),"math.floor":i=>Math.floor(i),"math.round":(i,t)=>{if(t===void 0)return Math.round(i);const e=Math.pow(10,t);return Math.round(i*e)/e},"math.log":i=>Math.log(i),"math.log10":i=>Math.log10(i),"math.pow":(i,t)=>Math.pow(i,t),"math.sqrt":i=>Math.sqrt(i),"math.exp":i=>Math.exp(i),"math.max":(...i)=>Math.max(...i),"math.min":(...i)=>Math.min(...i),"math.sign":i=>Math.sign(i),"math.avg":(...i)=>i.reduce((t,e)=>t+e,0)/i.length,"math.sum":(i,t)=>{const e=[];for(let s=0;s<i.length;s++){if(s<t-1){e.push(NaN);continue}let r=0;for(let n=s-t+1;n<=s;n++)r+=i[n];e.push(r)}return e},"math.sin":i=>Math.sin(i),"math.cos":i=>Math.cos(i),"math.tan":i=>Math.tan(i),"math.asin":i=>Math.asin(i),"math.acos":i=>Math.acos(i),"math.atan":i=>Math.atan(i),"math.random":()=>Math.random(),"math.todegrees":i=>i*(180/Math.PI),"math.toradians":i=>i*(Math.PI/180)},xt={"math.pi":Math.PI,"math.e":Math.E,"math.phi":1.618033988749895,"math.rphi":.618033988749895};/**
64
+ */const xt={"math.abs":i=>Math.abs(i),"math.ceil":i=>Math.ceil(i),"math.floor":i=>Math.floor(i),"math.round":(i,t)=>{if(t===void 0)return Math.round(i);const e=Math.pow(10,t);return Math.round(i*e)/e},"math.log":i=>Math.log(i),"math.log10":i=>Math.log10(i),"math.pow":(i,t)=>Math.pow(i,t),"math.sqrt":i=>Math.sqrt(i),"math.exp":i=>Math.exp(i),"math.max":(...i)=>Math.max(...i),"math.min":(...i)=>Math.min(...i),"math.sign":i=>Math.sign(i),"math.avg":(...i)=>i.reduce((t,e)=>t+e,0)/i.length,"math.sum":(i,t)=>{const e=[];for(let s=0;s<i.length;s++){if(s<t-1){e.push(NaN);continue}let r=0;for(let n=s-t+1;n<=s;n++)r+=i[n];e.push(r)}return e},"math.sin":i=>Math.sin(i),"math.cos":i=>Math.cos(i),"math.tan":i=>Math.tan(i),"math.asin":i=>Math.asin(i),"math.acos":i=>Math.acos(i),"math.atan":i=>Math.atan(i),"math.random":()=>Math.random(),"math.todegrees":i=>i*(180/Math.PI),"math.toradians":i=>i*(Math.PI/180)},gt={"math.pi":Math.PI,"math.e":Math.E,"math.phi":1.618033988749895,"math.rphi":.618033988749895};/**
65
65
  * pine-to-kline — Color Constants
66
66
  * All Pine color.* constants → hex values
67
67
  * @license Apache-2.0
68
- */const v={"color.aqua":"#00BCD4","color.black":"#000000","color.blue":"#2196F3","color.fuchsia":"#E040FB","color.gray":"#9E9E9E","color.green":"#4CAF50","color.lime":"#00E676","color.maroon":"#880E4F","color.navy":"#0D47A1","color.olive":"#808000","color.orange":"#FF9800","color.purple":"#9C27B0","color.red":"#F44336","color.silver":"#B0BEC5","color.teal":"#009688","color.white":"#FFFFFF","color.yellow":"#FFEB3B"};/**
68
+ */const A={"color.aqua":"#00BCD4","color.black":"#000000","color.blue":"#2196F3","color.fuchsia":"#E040FB","color.gray":"#9E9E9E","color.green":"#4CAF50","color.lime":"#00E676","color.maroon":"#880E4F","color.navy":"#0D47A1","color.olive":"#808000","color.orange":"#FF9800","color.purple":"#9C27B0","color.red":"#F44336","color.silver":"#B0BEC5","color.teal":"#009688","color.white":"#FFFFFF","color.yellow":"#FFEB3B"};/**
69
69
  * pine-to-kline — Color Functions
70
70
  * Implements: color.new(), color.rgb(), color.from_gradient()
71
71
  * @license Apache-2.0
72
- */function kt(i,t){const e=Math.round((1-t/100)*255),s=i.startsWith("#")?i:"#000000";return(s.length===9?s.slice(0,7):s)+e.toString(16).padStart(2,"0")}function B(i,t,e,s=0){const r=l=>Math.max(0,Math.min(255,Math.round(l))),n=Math.round((1-s/100)*255);return"#"+r(i).toString(16).padStart(2,"0")+r(t).toString(16).padStart(2,"0")+r(e).toString(16).padStart(2,"0")+(n<255?n.toString(16).padStart(2,"0"):"")}function Lt(i,t,e,s,r){const n=Math.max(0,Math.min(1,(i-t)/(e-t))),l=u=>{const N=u.replace("#","");return{r:parseInt(N.slice(0,2),16),g:parseInt(N.slice(2,4),16),b:parseInt(N.slice(4,6),16)}},h=l(s),c=l(r),o=(u,N)=>Math.round(u+(N-u)*n);return B(o(h.r,c.r),o(h.g,c.g),o(h.b,c.b))}const bt={"color.new":kt,"color.rgb":B,"color.from_gradient":Lt};/**
72
+ */function kt(i,t){const e=Math.round((1-t/100)*255),s=i.startsWith("#")?i:"#000000";return(s.length===9?s.slice(0,7):s)+e.toString(16).padStart(2,"0")}function F(i,t,e,s=0){const r=l=>Math.max(0,Math.min(255,Math.round(l))),n=Math.round((1-s/100)*255);return"#"+r(i).toString(16).padStart(2,"0")+r(t).toString(16).padStart(2,"0")+r(e).toString(16).padStart(2,"0")+(n<255?n.toString(16).padStart(2,"0"):"")}function Lt(i,t,e,s,r){const n=Math.max(0,Math.min(1,(i-t)/(e-t))),l=u=>{const f=u.replace("#","");return{r:parseInt(f.slice(0,2),16),g:parseInt(f.slice(2,4),16),b:parseInt(f.slice(4,6),16)}},h=l(s),c=l(r),o=(u,f)=>Math.round(u+(f-u)*n);return F(o(h.r,c.r),o(h.g,c.g),o(h.b,c.b))}const Pt={"color.new":kt,"color.rgb":F,"color.from_gradient":Lt};/**
73
73
  * pine-to-kline — Input Functions
74
74
  * Handles input.int(), input.float(), input.bool(), etc.
75
75
  * These extract metadata for KlineChart calcParams.
76
76
  * @license Apache-2.0
77
- */let I=0;function Pt(){I=0}function Ct(i,t,e){return{meta:{id:`input_${I++}`,type:"int",title:t??null,defaultValue:i,minval:e==null?void 0:e.minval,maxval:e==null?void 0:e.maxval,step:(e==null?void 0:e.step)??1},value:i}}function Ot(i,t,e){return{meta:{id:`input_${I++}`,type:"float",title:t??null,defaultValue:i,minval:e==null?void 0:e.minval,maxval:e==null?void 0:e.maxval,step:(e==null?void 0:e.step)??.1},value:i}}function _t(i,t){return{meta:{id:`input_${I++}`,type:"bool",title:t??null,defaultValue:i},value:i}}function Mt(i,t,e){return{meta:{id:`input_${I++}`,type:"string",title:t??null,defaultValue:i,options:e},value:i}}function Dt(i,t){return{meta:{id:`input_${I++}`,type:"color",title:t??null,defaultValue:i},value:i}}function Tt(i,t){return{meta:{id:`input_${I++}`,type:"source",title:t??null,defaultValue:i},value:i}}function Ft(i,t){const e=typeof i=="number"?Number.isInteger(i)?"int":"float":typeof i=="boolean"?"bool":"string";return{meta:{id:`input_${I++}`,type:e,title:t??null,defaultValue:i},value:i}}const Bt={input:Ft,"input.int":Ct,"input.float":Ot,"input.bool":_t,"input.string":Mt,"input.color":Dt,"input.source":Tt};/**
77
+ */let I=0;function Ct(){I=0}function bt(i,t,e){return{meta:{id:`input_${I++}`,type:"int",title:t??null,defaultValue:i,minval:e==null?void 0:e.minval,maxval:e==null?void 0:e.maxval,step:(e==null?void 0:e.step)??1},value:i}}function Tt(i,t,e){return{meta:{id:`input_${I++}`,type:"float",title:t??null,defaultValue:i,minval:e==null?void 0:e.minval,maxval:e==null?void 0:e.maxval,step:(e==null?void 0:e.step)??.1},value:i}}function Ot(i,t){return{meta:{id:`input_${I++}`,type:"bool",title:t??null,defaultValue:i},value:i}}function _t(i,t,e){return{meta:{id:`input_${I++}`,type:"string",title:t??null,defaultValue:i,options:e},value:i}}function Mt(i,t){return{meta:{id:`input_${I++}`,type:"color",title:t??null,defaultValue:i},value:i}}function Dt(i,t){return{meta:{id:`input_${I++}`,type:"source",title:t??null,defaultValue:i},value:i}}function Ft(i,t){const e=typeof i=="number"?Number.isInteger(i)?"int":"float":typeof i=="boolean"?"bool":"string";return{meta:{id:`input_${I++}`,type:e,title:t??null,defaultValue:i},value:i}}const Bt={input:Ft,"input.int":bt,"input.float":Tt,"input.bool":Ot,"input.string":_t,"input.color":Mt,"input.source":Dt};/**
78
78
  * pine-to-kline — Builtins Master Index
79
79
  * Central registry of all built-in functions and constants
80
80
  * @license Apache-2.0
81
- */const k={...F,...gt,...bt,...Bt},y={...xt,...v,na:NaN,true:!0,false:!1};/**
81
+ */const L={...D,...xt,...Pt,...Bt},y={...gt,...A,na:NaN,true:!0,false:!1};/**
82
82
  * pine-to-kline — Pine Runtime
83
83
  * Walks the AST and executes PineScript logic against bar data.
84
84
  * Produces arrays of computed values for each plot.
85
85
  * @license Apache-2.0
86
- */class _{constructor(){p(this,"ctx");p(this,"vars",new K);p(this,"scope",new Map);p(this,"functions",new Map);p(this,"meta",{name:"Untitled",shortName:null,overlay:!1,format:null,precision:null,scale:null,max_bars_back:null});p(this,"inputs",[]);p(this,"plots",[]);p(this,"hlines",[]);p(this,"plotResults",new Map);p(this,"warnings",[]);p(this,"inputIndex",0)}execute(t,e,s){Pt(),this.inputs=[],this.plots=[],this.hlines=[],this.plotResults=new Map,this.warnings=[],this.functions=new Map,this.inputIndex=0,this.ctx=new C(e);const r=[];this.scope=new Map,this.vars.reset(),this.firstPass(t,s);const n=(l,h)=>this.runCalc(t,l,h);return{meta:this.meta,inputs:this.inputs,plots:this.plots,hlines:this.hlines,calcFn:n,warnings:this.warnings,errors:r}}firstPass(t,e){for(const s of t.body)s.type==="Indicator"?this.evalIndicator(s):s.type==="FunctionDef"&&this.functions.set(s.name,{params:s.params.map(r=>({name:r.name,defaultValue:r.defaultValue?this.evalExpr(r.defaultValue):null})),body:s.body});this.runOnce(t,this.ctx.dataList,e??[])}runCalc(t,e,s){return this.runOnce(t,e,s)}runOnce(t,e,s){this.ctx=new C(e),this.scope=new Map,this.vars.reset(),this.plotResults=new Map,this.inputIndex=0;const r=[],n=[],l=[],h={open:this.ctx.open,high:this.ctx.high,low:this.ctx.low,close:this.ctx.close,volume:this.ctx.volume,hl2:this.ctx.hl2,hlc3:this.ctx.hlc3,ohlc4:this.ctx.ohlc4};for(const u of t.body)u.type==="FunctionDef"&&this.functions.set(u.name,{params:u.params.map(N=>({name:N.name,defaultValue:N.defaultValue?this.evalExpr(N.defaultValue):null})),body:u.body});for(const u of t.body)if(!(u.type==="Indicator"||u.type==="FunctionDef"))try{this.evalNode(u,h,s,r,n,l)}catch(N){this.warnings.push(`Runtime warning at line ${u.line}: ${N.message}`)}r.length>0&&(this.inputs=r),n.length>0&&(this.plots=n),l.length>0&&(this.hlines=l);const c=e.length,o=[];for(let u=0;u<c;u++){const N={};for(const[d,A]of this.plotResults)N[d]=A[u]??NaN;o.push(N)}return o}evalNode(t,e,s,r,n,l){switch(t.type){case"VarDecl":return this.evalVarDecl(t,e,s,r);case"Assign":return this.evalAssign(t,e,s,r);case"If":return this.evalIf(t,e,s,r,n,l);case"For":return this.evalFor(t,e,s,r,n,l);case"While":return this.evalWhile(t,e,s,r,n,l);case"PlotCall":return this.evalPlot(t,e,s,r,n);case"HlineCall":return this.evalHline(t,l);case"ExpressionStatement":return this.evalExpr(t.expression,e,s,r);case"Return":return t.value?this.evalExpr(t.value,e,s,r):void 0;default:return}}evalIndicator(t){var e,s,r,n,l;((e=t.name)==null?void 0:e.type)==="StringLiteral"&&(this.meta.name=t.name.value);for(const h of t.args)h.key==="overlay"&&((s=h.value)==null?void 0:s.type)==="BoolLiteral"&&(this.meta.overlay=h.value.value),h.key==="shorttitle"&&((r=h.value)==null?void 0:r.type)==="StringLiteral"&&(this.meta.shortName=h.value.value),h.key==="format"&&((n=h.value)==null?void 0:n.type)==="StringLiteral"&&(this.meta.format=h.value.value),h.key==="precision"&&((l=h.value)==null?void 0:l.type)==="NumberLiteral"&&(this.meta.precision=h.value.value)}evalVarDecl(t,e,s,r){const n=this.evalExpr(t.value,e,s,r);if(Array.isArray(t.name)){const l=t.name;if(n&&typeof n=="object"){const h=Object.values(n);l.forEach((c,o)=>this.scope.set(c,h[o]))}}else t.persistent?(this.vars.initVar(t.name,n),this.scope.set(t.name,this.vars.getVar(t.name))):t.persistentTick?(this.vars.initVarip(t.name,n),this.scope.set(t.name,this.vars.getVarip(t.name))):this.scope.set(t.name,n)}evalAssign(t,e,s,r){const n=this.evalExpr(t.value,e,s,r),l=this.scope.get(t.target);switch(t.operator){case":=":case"=":this.scope.set(t.target,n);break;case"+=":this.scope.set(t.target,(l??0)+n);break;case"-=":this.scope.set(t.target,(l??0)-n);break;case"*=":this.scope.set(t.target,(l??0)*n);break;case"/=":this.scope.set(t.target,(l??0)/n);break;case"%=":this.scope.set(t.target,(l??0)%n);break}this.vars.hasVar(t.target)&&this.vars.setVar(t.target,this.scope.get(t.target))}evalIf(t,e,s,r,n,l){if(this.evalExpr(t.condition,e,s,r))for(const c of t.body)this.evalNode(c,e,s,r,n,l);else{let c=!1;for(const o of t.elseIf)if(this.evalExpr(o.condition,e,s,r)){for(const u of o.body)this.evalNode(u,e,s,r,n,l);c=!0;break}if(!c&&t.elseBody)for(const o of t.elseBody)this.evalNode(o,e,s,r,n,l)}}evalFor(t,e,s,r,n,l){const h=this.evalExpr(t.start,e,s,r),c=this.evalExpr(t.end,e,s,r),o=t.step?this.evalExpr(t.step,e,s,r):1;for(let u=h;o>0?u<=c:u>=c;u+=o){this.scope.set(t.variable,u);for(const N of t.body)this.evalNode(N,e,s,r,n,l)}}evalWhile(t,e,s,r,n,l){let h=0;for(;this.evalExpr(t.condition,e,s,r)&&h++<1e4;)for(const c of t.body)this.evalNode(c,e,s,r,n,l)}evalPlot(t,e,s,r,n){const l=this.evalExpr(t.args[0],e,s,r),h=Object.fromEntries(t.kwargs.map(u=>[u.key,this.evalExpr(u.value,e,s,r)])),o=(h.title??`plot_${n.length}`).toString().toLowerCase().replace(/\s+/g,"_");n.push({id:o,title:h.title??null,color:this.resolveColor(h.color),linewidth:h.linewidth??1,style:h.style??null}),Array.isArray(l)?this.plotResults.set(o,l):typeof l=="number"&&this.plotResults.set(o,new Array(this.ctx.barCount).fill(l))}evalHline(t,e){const s=this.evalExpr(t.price),r=Object.fromEntries(t.kwargs.map(n=>[n.key,this.evalExpr(n.value)]));e.push({price:typeof s=="number"?s:NaN,title:r.title??null,color:this.resolveColor(r.color),linestyle:r.linestyle??null,linewidth:r.linewidth??1})}evalExpr(t,e,s,r){if(t)switch(t.type){case"NumberLiteral":return t.value;case"StringLiteral":return t.value;case"BoolLiteral":return t.value;case"ColorLiteral":return t.value;case"NaLiteral":return NaN;case"Identifier":{const n=t.name;return this.scope.has(n)?this.scope.get(n):e&&n in e?e[n]:y[n]!==void 0?y[n]:v[n]?v[n]:n==="bar_index"?Array.from({length:this.ctx.barCount},(l,h)=>h):void 0}case"BinaryExpr":{const n=this.evalExpr(t.left,e,s,r),l=this.evalExpr(t.right,e,s,r);return this.evalBinary(t.operator,n,l)}case"UnaryExpr":{const n=this.evalExpr(t.operand,e,s,r);return t.operator==="-"?Array.isArray(n)?n.map(l=>-l):-n:t.operator==="not"?Array.isArray(n)?n.map(l=>!l):!n:n}case"TernaryExpr":{const n=this.evalExpr(t.condition,e,s,r);if(Array.isArray(n)){const l=this.evalExpr(t.consequent,e,s,r),h=this.evalExpr(t.alternate,e,s,r);return n.map((c,o)=>c?Array.isArray(l)?l[o]:l:Array.isArray(h)?h[o]:h)}return n?this.evalExpr(t.consequent,e,s,r):this.evalExpr(t.alternate,e,s,r)}case"FunctionCall":return this.evalFunctionCall(t,e,s,r);case"SeriesAccess":{const n=this.evalExpr(t.series,e,s,r),l=this.evalExpr(t.offset,e,s,r);return Array.isArray(n)&&typeof l=="number"?n.map((h,c)=>c-l>=0?n[c-l]:NaN):NaN}case"MemberExpr":{const n=this.buildMemberName(t);return y[n]!==void 0?y[n]:v[n]?v[n]:e&&n in e?e[n]:n}default:return}}evalFunctionCall(t,e,s,r){const n=t.args.map(c=>this.evalExpr(c,e,s,r)),l=Object.fromEntries(t.kwargs.map(c=>[c.key,this.evalExpr(c.value,e,s,r)])),h=t.callee;if(h.startsWith("input")){const c=k[h];if(c){const o=c(n[0],l.title??n[1],l);r&&r.push(o.meta);const u=this.inputIndex++,N=s&&s[u]!==void 0?s[u]:o.value;return o.meta.type==="source"&&e?e[N]??e.close:N}}if(k[h])return k[h](...n);if(this.functions.has(h))return this.callUserFunction(h,n,e,s,r);if(h==="nz"){const c=n[0],o=n[1]??0;return Array.isArray(c)?c.map(u=>u===void 0||isNaN(u)?o:u):c===void 0||typeof c=="number"&&isNaN(c)?o:c}if(h==="na"){const c=n[0];return Array.isArray(c)?c.map(o=>o===void 0||typeof o=="number"&&isNaN(o)):c===void 0||typeof c=="number"&&isNaN(c)}if(h==="fixnan"){const c=n[0];if(Array.isArray(c)){let o=NaN;return c.map(u=>(isNaN(u)||(o=u),o))}return c}return h==="str.tostring"?String(n[0]):(this.warnings.push(`Unknown function: ${h}`),NaN)}callUserFunction(t,e,s,r,n){const l=this.functions.get(t),h=new Map(this.scope);l.params.forEach((o,u)=>{this.scope.set(o.name,e[u]??o.defaultValue)});let c;for(const o of l.body){if(o.type==="Return"){c=o.value?this.evalExpr(o.value,s,r,n):void 0;break}o.type==="ExpressionStatement"?c=this.evalExpr(o.expression,s,r,n):this.evalNode(o,s??{},r??[],n??[],[],[])}return this.scope=h,c}evalBinary(t,e,s){const r=Array.isArray(e),n=Array.isArray(s);if(r||n){const l=r?e.length:s.length;return Array.from({length:l},(h,c)=>{const o=r?e[c]:e,u=n?s[c]:s;return this.scalarBinary(t,o,u)})}return this.scalarBinary(t,e,s)}scalarBinary(t,e,s){switch(t){case"+":return e+s;case"-":return e-s;case"*":return e*s;case"/":return s===0?NaN:e/s;case"%":return e%s;case"**":return Math.pow(e,s);case"==":return e===s;case"!=":return e!==s;case"<":return e<s;case">":return e>s;case"<=":return e<=s;case">=":return e>=s;case"and":return e&&s;case"or":return e||s;default:return NaN}}resolveColor(t){return t&&typeof t=="string"?t.startsWith("#")?t:v[t]?v[t]:t:null}buildMemberName(t){return t.type==="Identifier"?t.name:t.type==="MemberExpr"?this.buildMemberName(t.object)+"."+t.property:""}}/**
86
+ */class O{constructor(){p(this,"ctx");p(this,"vars",new K);p(this,"scope",new Map);p(this,"functions",new Map);p(this,"meta",{name:"Untitled",shortName:null,overlay:!1,format:null,precision:null,scale:null,max_bars_back:null});p(this,"inputs",[]);p(this,"plots",[]);p(this,"hlines",[]);p(this,"plotResults",new Map);p(this,"warnings",[]);p(this,"inputIndex",0)}execute(t,e,s){Ct(),this.inputs=[],this.plots=[],this.hlines=[],this.plotResults=new Map,this.warnings=[],this.functions=new Map,this.inputIndex=0,this.ctx=new b(e);const r=[];this.scope=new Map,this.vars.reset(),this.firstPass(t,s);const n=(l,h)=>this.runCalc(t,l,h);return{meta:this.meta,inputs:this.inputs,plots:this.plots,hlines:this.hlines,calcFn:n,warnings:this.warnings,errors:r}}firstPass(t,e){for(const s of t.body)s.type==="Indicator"?this.evalIndicator(s):s.type==="FunctionDef"&&this.functions.set(s.name,{params:s.params.map(r=>({name:r.name,defaultValue:r.defaultValue?this.evalExpr(r.defaultValue):null})),body:s.body});this.runOnce(t,this.ctx.dataList,e??[])}runCalc(t,e,s){return this.runOnce(t,e,s)}runOnce(t,e,s){this.ctx=new b(e),this.scope=new Map,this.vars.reset(),this.plotResults=new Map,this.inputIndex=0;const r=[],n=[],l=[],h={open:this.ctx.open,high:this.ctx.high,low:this.ctx.low,close:this.ctx.close,volume:this.ctx.volume,hl2:this.ctx.hl2,hlc3:this.ctx.hlc3,ohlc4:this.ctx.ohlc4};for(const u of t.body)u.type==="FunctionDef"&&this.functions.set(u.name,{params:u.params.map(f=>({name:f.name,defaultValue:f.defaultValue?this.evalExpr(f.defaultValue):null})),body:u.body});for(const u of t.body)if(!(u.type==="Indicator"||u.type==="FunctionDef"))try{this.evalNode(u,h,s,r,n,l)}catch(f){this.warnings.push(`Runtime warning at line ${u.line}: ${f.message}`)}r.length>0&&(this.inputs=r),n.length>0&&(this.plots=n),l.length>0&&(this.hlines=l);const c=e.length,o=[];for(let u=0;u<c;u++){const f={};for(const[m,v]of this.plotResults)f[m]=v[u]??NaN;o.push(f)}return o}evalNode(t,e,s,r,n,l){switch(t.type){case"VarDecl":return this.evalVarDecl(t,e,s,r);case"Assign":return this.evalAssign(t,e,s,r);case"If":return this.evalIf(t,e,s,r,n,l);case"For":return this.evalFor(t,e,s,r,n,l);case"While":return this.evalWhile(t,e,s,r,n,l);case"PlotCall":return this.evalPlot(t,e,s,r,n);case"HlineCall":return this.evalHline(t,l);case"ExpressionStatement":return this.evalExpr(t.expression,e,s,r);case"Return":return t.value?this.evalExpr(t.value,e,s,r):void 0;default:return}}evalIndicator(t){var e,s,r,n,l;((e=t.name)==null?void 0:e.type)==="StringLiteral"&&(this.meta.name=t.name.value);for(const h of t.args)h.key==="overlay"&&((s=h.value)==null?void 0:s.type)==="BoolLiteral"&&(this.meta.overlay=h.value.value),h.key==="shorttitle"&&((r=h.value)==null?void 0:r.type)==="StringLiteral"&&(this.meta.shortName=h.value.value),h.key==="format"&&((n=h.value)==null?void 0:n.type)==="StringLiteral"&&(this.meta.format=h.value.value),h.key==="precision"&&((l=h.value)==null?void 0:l.type)==="NumberLiteral"&&(this.meta.precision=h.value.value)}evalVarDecl(t,e,s,r){const n=this.evalExpr(t.value,e,s,r);if(Array.isArray(t.name)){const l=t.name;if(n&&typeof n=="object"){const h=Object.values(n);l.forEach((c,o)=>this.scope.set(c,h[o]))}}else t.persistent?(this.vars.initVar(t.name,n),this.scope.set(t.name,this.vars.getVar(t.name))):t.persistentTick?(this.vars.initVarip(t.name,n),this.scope.set(t.name,this.vars.getVarip(t.name))):this.scope.set(t.name,n)}evalAssign(t,e,s,r){const n=this.evalExpr(t.value,e,s,r),l=this.scope.get(t.target);switch(t.operator){case":=":case"=":this.scope.set(t.target,n);break;case"+=":this.scope.set(t.target,(l??0)+n);break;case"-=":this.scope.set(t.target,(l??0)-n);break;case"*=":this.scope.set(t.target,(l??0)*n);break;case"/=":this.scope.set(t.target,(l??0)/n);break;case"%=":this.scope.set(t.target,(l??0)%n);break}this.vars.hasVar(t.target)&&this.vars.setVar(t.target,this.scope.get(t.target))}evalIf(t,e,s,r,n,l){if(this.evalExpr(t.condition,e,s,r))for(const c of t.body)this.evalNode(c,e,s,r,n,l);else{let c=!1;for(const o of t.elseIf)if(this.evalExpr(o.condition,e,s,r)){for(const u of o.body)this.evalNode(u,e,s,r,n,l);c=!0;break}if(!c&&t.elseBody)for(const o of t.elseBody)this.evalNode(o,e,s,r,n,l)}}evalFor(t,e,s,r,n,l){const h=this.evalExpr(t.start,e,s,r),c=this.evalExpr(t.end,e,s,r),o=t.step?this.evalExpr(t.step,e,s,r):1;for(let u=h;o>0?u<=c:u>=c;u+=o){this.scope.set(t.variable,u);for(const f of t.body)this.evalNode(f,e,s,r,n,l)}}evalWhile(t,e,s,r,n,l){let h=0;for(;this.evalExpr(t.condition,e,s,r)&&h++<1e4;)for(const c of t.body)this.evalNode(c,e,s,r,n,l)}evalPlot(t,e,s,r,n){const l=this.evalExpr(t.args[0],e,s,r),h=Object.fromEntries(t.kwargs.map(u=>[u.key,this.evalExpr(u.value,e,s,r)])),o=(h.title??`plot_${n.length}`).toString().toLowerCase().replace(/\s+/g,"_");n.push({id:o,title:h.title??null,color:this.resolveColor(h.color),linewidth:h.linewidth??1,style:h.style??null}),Array.isArray(l)?this.plotResults.set(o,l):typeof l=="number"&&this.plotResults.set(o,new Array(this.ctx.barCount).fill(l))}evalHline(t,e){const s=this.evalExpr(t.price),r=Object.fromEntries(t.kwargs.map(n=>[n.key,this.evalExpr(n.value)]));e.push({price:typeof s=="number"?s:NaN,title:r.title??null,color:this.resolveColor(r.color),linestyle:r.linestyle??null,linewidth:r.linewidth??1})}evalExpr(t,e,s,r){if(t)switch(t.type){case"NumberLiteral":return t.value;case"StringLiteral":return t.value;case"BoolLiteral":return t.value;case"ColorLiteral":return t.value;case"NaLiteral":return NaN;case"Identifier":{const n=t.name;return this.scope.has(n)?this.scope.get(n):e&&n in e?e[n]:y[n]!==void 0?y[n]:A[n]?A[n]:n==="bar_index"?Array.from({length:this.ctx.barCount},(l,h)=>h):void 0}case"BinaryExpr":{const n=this.evalExpr(t.left,e,s,r),l=this.evalExpr(t.right,e,s,r);return this.evalBinary(t.operator,n,l)}case"UnaryExpr":{const n=this.evalExpr(t.operand,e,s,r);return t.operator==="-"?Array.isArray(n)?n.map(l=>-l):-n:t.operator==="not"?Array.isArray(n)?n.map(l=>!l):!n:n}case"TernaryExpr":{const n=this.evalExpr(t.condition,e,s,r);if(Array.isArray(n)){const l=this.evalExpr(t.consequent,e,s,r),h=this.evalExpr(t.alternate,e,s,r);return n.map((c,o)=>c?Array.isArray(l)?l[o]:l:Array.isArray(h)?h[o]:h)}return n?this.evalExpr(t.consequent,e,s,r):this.evalExpr(t.alternate,e,s,r)}case"FunctionCall":return this.evalFunctionCall(t,e,s,r);case"SeriesAccess":{const n=this.evalExpr(t.series,e,s,r),l=this.evalExpr(t.offset,e,s,r);return Array.isArray(n)&&typeof l=="number"?n.map((h,c)=>c-l>=0?n[c-l]:NaN):NaN}case"MemberExpr":{const n=this.buildMemberName(t);return y[n]!==void 0?y[n]:A[n]?A[n]:e&&n in e?e[n]:n}default:return}}evalFunctionCall(t,e,s,r){const n=t.args.map(c=>this.evalExpr(c,e,s,r)),l=Object.fromEntries(t.kwargs.map(c=>[c.key,this.evalExpr(c.value,e,s,r)])),h=t.callee;if(h.startsWith("input")){const c=L[h];if(c){const o=c(n[0],l.title??n[1],l);r&&r.push(o.meta);const u=this.inputIndex++,f=s&&s[u]!==void 0?s[u]:o.value;return o.meta.type==="source"&&e?e[f]??e.close:f}}if(L[h])return L[h](...n);if(this.functions.has(h))return this.callUserFunction(h,n,e,s,r);if(h==="nz"){const c=n[0],o=n[1]??0;return Array.isArray(c)?c.map(u=>u===void 0||isNaN(u)?o:u):c===void 0||typeof c=="number"&&isNaN(c)?o:c}if(h==="na"){const c=n[0];return Array.isArray(c)?c.map(o=>o===void 0||typeof o=="number"&&isNaN(o)):c===void 0||typeof c=="number"&&isNaN(c)}if(h==="fixnan"){const c=n[0];if(Array.isArray(c)){let o=NaN;return c.map(u=>(isNaN(u)||(o=u),o))}return c}return h==="str.tostring"?String(n[0]):(this.warnings.push(`Unknown function: ${h}`),NaN)}callUserFunction(t,e,s,r,n){const l=this.functions.get(t),h=new Map(this.scope);l.params.forEach((o,u)=>{this.scope.set(o.name,e[u]??o.defaultValue)});let c;for(const o of l.body){if(o.type==="Return"){c=o.value?this.evalExpr(o.value,s,r,n):void 0;break}o.type==="ExpressionStatement"?c=this.evalExpr(o.expression,s,r,n):this.evalNode(o,s??{},r??[],n??[],[],[])}return this.scope=h,c}evalBinary(t,e,s){const r=Array.isArray(e),n=Array.isArray(s);if(r||n){const l=r?e.length:s.length;return Array.from({length:l},(h,c)=>{const o=r?e[c]:e,u=n?s[c]:s;return this.scalarBinary(t,o,u)})}return this.scalarBinary(t,e,s)}scalarBinary(t,e,s){switch(t){case"+":return e+s;case"-":return e-s;case"*":return e*s;case"/":return s===0?NaN:e/s;case"%":return e%s;case"**":return Math.pow(e,s);case"==":return e===s;case"!=":return e!==s;case"<":return e<s;case">":return e>s;case"<=":return e<=s;case">=":return e>=s;case"and":return e&&s;case"or":return e||s;default:return NaN}}resolveColor(t){return t&&typeof t=="string"?t.startsWith("#")?t:A[t]?A[t]:t:null}buildMemberName(t){return t.type==="Identifier"?t.name:t.type==="MemberExpr"?this.buildMemberName(t.object)+"."+t.property:""}}/**
87
87
  * pine-to-kline — Figure Mapper
88
88
  * Maps Pine plot styles to KlineChart figure types
89
89
  * @license Apache-2.0
90
- */const Ut={"plot.style_line":"line","plot.style_linebr":"line","plot.style_stepline":"line","plot.style_area":"line","plot.style_areabr":"line","plot.style_columns":"bar","plot.style_histogram":"bar","plot.style_circles":"circle","plot.style_cross":"circle"};function Gt(i){return i?Ut[i]??"line":"line"}/**
90
+ */const Gt={"plot.style_line":"line","plot.style_linebr":"line","plot.style_stepline":"line","plot.style_area":"line","plot.style_areabr":"line","plot.style_columns":"bar","plot.style_histogram":"bar","plot.style_circles":"circle","plot.style_cross":"circle"};function Ut(i){return i?Gt[i]??"line":"line"}/**
91
91
  * pine-to-kline — Style Mapper
92
92
  * Converts Pine style values to KlineChart-compatible CSS
93
93
  * @license Apache-2.0
94
- */function M(i){if(!i)return"#2196F3";if(typeof i=="string"){if(i.startsWith("#"))return i;if(v[i])return v[i]}return"#2196F3"}function Vt(i){switch(i){case"hline.style_dashed":return[6,3];case"hline.style_dotted":return[2,2];case"hline.style_solid":default:return[]}}/**
94
+ */function _(i){if(!i)return"#2196F3";if(typeof i=="string"){if(i.startsWith("#"))return i;if(A[i])return A[i]}return"#2196F3"}function Vt(i){switch(i){case"hline.style_dashed":return[6,3];case"hline.style_dotted":return[2,2];case"hline.style_solid":default:return[]}}/**
95
95
  * pine-to-kline — KlineChart Adapter
96
96
  * Converts PineRuntime IR → KlineChart IndicatorTemplate
97
97
  * @license Apache-2.0
98
- */class U{toIndicatorTemplate(t){const{meta:e,inputs:s,plots:r,hlines:n,calcFn:l}=t;return{name:e.name.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),shortName:e.shortName??e.name,series:e.overlay?"price":"normal",calcParams:s.map(c=>c.defaultValue),extendData:{pineInputs:s.map(c=>c.title||c.id||"Param")},figures:this.mapFigures(r),regenerateFigures:s.length>0?c=>this.mapFigures(r):void 0,calc:(c,o)=>{const u=o.calcParams??s.map(N=>N.defaultValue);return l(c,u)},...n.length>0&&{draw:c=>{const{ctx:o,bounding:u,indicator:N,yAxis:d}=c;if(!o||!d)return!1;for(const A of n){const w=d.convertToPixel(A.price);if(w<u.top||w>u.top+u.height)continue;o.save(),o.strokeStyle=M(A.color),o.lineWidth=A.linewidth??1;const V=Vt(A.linestyle);V.length&&o.setLineDash(V),o.beginPath(),o.moveTo(u.left,w),o.lineTo(u.left+u.width,w),o.stroke(),A.title&&(o.fillStyle=M(A.color),o.font="10px sans-serif",o.textAlign="right",o.fillText(A.title,u.left+u.width-4,w-4)),o.restore()}return!1}},createTooltipDataSource:c=>{const{indicator:o}=c,u=(o==null?void 0:o.result)??[],N=u[u.length-1];return{name:e.name,calcParamsText:s.length>0?`(${((o==null?void 0:o.calcParams)??[]).join(", ")})`:"",values:r.map(d=>({title:`${d.title??d.id}: `,value:(N==null?void 0:N[d.id])??"--"}))}}}}mapFigures(t){return t.map(e=>({key:e.id,title:`${e.title??e.id}: `,type:Gt(e.style),styles:(s,r,n)=>({color:M(e.color)})}))}}/**
98
+ */class B{toIndicatorTemplate(t){const{meta:e,inputs:s,plots:r,hlines:n,calcFn:l}=t;return{name:e.name.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),shortName:e.shortName??e.name,series:e.overlay?"price":"normal",calcParams:s.map(c=>c.defaultValue),extendData:{pineInputs:s.map(c=>c.title||c.id||"Param")},figures:this.mapFigures(r),regenerateFigures:s.length>0?c=>this.mapFigures(r):void 0,calc:(c,o)=>{const u=o.calcParams??s.map(f=>f.defaultValue);return l(c,u)},...n.length>0&&{draw:c=>{const{ctx:o,bounding:u,indicator:f,yAxis:m}=c;if(!o||!m)return!1;for(const v of n){const w=m.convertToPixel(v.price);if(w<u.top||w>u.top+u.height)continue;o.save(),o.strokeStyle=_(v.color),o.lineWidth=v.linewidth??1;const U=Vt(v.linestyle);U.length&&o.setLineDash(U),o.beginPath(),o.moveTo(u.left,w),o.lineTo(u.left+u.width,w),o.stroke(),v.title&&(o.fillStyle=_(v.color),o.font="10px sans-serif",o.textAlign="right",o.fillText(v.title,u.left+u.width-4,w-4)),o.restore()}return!1}},createTooltipDataSource:c=>{const{indicator:o}=c,u=(o==null?void 0:o.result)??[],f=u[u.length-1];return{name:e.name,calcParamsText:s.length>0?`(${((o==null?void 0:o.calcParams)??[]).join(", ")})`:"",values:r.map(m=>({title:`${m.title??m.id}: `,value:(f==null?void 0:f[m.id])??"--"}))}}}}mapFigures(t){return t.map(e=>({key:e.id,title:`${e.title??e.id}: `,type:Ut(e.style),styles:(s,r,n)=>({color:_(e.color)})}))}}/**
99
99
  * pine-to-kline — PineInterpreter
100
100
  * Main entry point class for the library
101
101
  * @license Apache-2.0
102
- */const Wt={version:"v5",strict:!1,sandbox:!0,onWarning:console.warn,onError:console.error};class G{constructor(t={}){p(this,"options");this.options={...Wt,...t}}compile(t){try{const e=new b(t).tokenize(),s=new P(e).parse(),r=new _,n=[{timestamp:0,open:0,high:0,low:0,close:0}],l=r.execute(s,n),h={...l,calcFn:(u,N)=>new _().execute(s,u,N).calcFn(u,N)},o=new U().toIndicatorTemplate(h);return{success:!0,indicatorConfig:o,name:o.name,warnings:l.warnings,errors:[]}}catch(e){return this.options.onError(e),{success:!1,indicatorConfig:{},name:"",warnings:[],errors:[e]}}}validate(t){try{const e=new b(t).tokenize();return new P(e).parse(),{valid:!0,errors:[]}}catch(e){return{valid:!1,errors:[e]}}}register(t,e){const s=this.compile(t);if(!s.success)throw s.errors[0];return e&&e(s.indicatorConfig),s.name}execute(t,e,s){const r=this.compile(t);if(!r.success)throw r.errors[0];return r.indicatorConfig.calc(e,{calcParams:s??r.indicatorConfig.calcParams})}}/**
102
+ */const Wt={version:"v5",strict:!1,sandbox:!0,onWarning:console.warn,onError:console.error};class G{constructor(t={}){p(this,"options");this.options={...Wt,...t}}compile(t){try{const e=new P(t).tokenize(),s=new C(e).parse(),r=new O,n=[{timestamp:0,open:0,high:0,low:0,close:0}],l=r.execute(s,n),h={...l,calcFn:(u,f)=>new O().execute(s,u,f).calcFn(u,f)},o=new B().toIndicatorTemplate(h);return{success:!0,indicatorConfig:o,name:o.name,warnings:l.warnings,errors:[]}}catch(e){return this.options.onError(e),{success:!1,indicatorConfig:{},name:"",warnings:[],errors:[e]}}}validate(t){try{const e=new P(t).tokenize();return new C(e).parse(),{valid:!0,errors:[]}}catch(e){return{valid:!1,errors:[e]}}}register(t,e){const s=this.compile(t);if(!s.success)throw s.errors[0];return e&&e(s.indicatorConfig),s.name}execute(t,e,s){const r=this.compile(t);if(!r.success)throw r.errors[0];return r.indicatorConfig.calc(e,{calcParams:s??r.indicatorConfig.calcParams})}}/**
103
103
  * pine-to-kline — KlineChartPro Plugin
104
104
  * Plugin adapter for @simahfud/klinecharts-pro integration
105
105
  * @license Apache-2.0
@@ -107,5 +107,5 @@
107
107
  * pine-to-kline — Series Emulator
108
108
  * Emulates Pine's bar-by-bar series model using cursor-indexed arrays
109
109
  * @license Apache-2.0
110
- */class jt{constructor(t){p(this,"_data");p(this,"_cursor",0);this._data=t}setCursor(t){this._cursor=t}get(t=0){const e=this._cursor-t;return e<0?NaN:this._data[e]}set(t){this._data[this._cursor]=t}get length(){return this._data.length}get current(){return this.get(0)}get all(){return this._data}toArray(){return[...this._data]}}f.ALL_BUILTINS=k,f.ALL_CONSTANTS=y,f.AdapterError=j,f.BarContext=C,f.KlineAdapter=U,f.Lexer=b,f.LexerError=R,f.ParseError=L,f.Parser=P,f.PineError=S,f.PineInterpreter=G,f.PineRuntime=_,f.RuntimeError=H,f.SeriesEmulator=jt,f.TA_REGISTRY=F,f.Token=m,f.TokenType=a,f.createPinePlugin=Ht,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
110
+ */class jt{constructor(t){p(this,"_data");p(this,"_cursor",0);this._data=t}setCursor(t){this._cursor=t}get(t=0){const e=this._cursor-t;return e<0?NaN:this._data[e]}set(t){this._data[this._cursor]=t}get length(){return this._data.length}get current(){return this.get(0)}get all(){return this._data}toArray(){return[...this._data]}}N.ALL_BUILTINS=L,N.ALL_CONSTANTS=y,N.AdapterError=H,N.BarContext=b,N.KlineAdapter=B,N.Lexer=P,N.LexerError=S,N.ParseError=x,N.Parser=C,N.PineError=R,N.PineInterpreter=G,N.PineRuntime=O,N.RuntimeError=W,N.SeriesEmulator=jt,N.TA_REGISTRY=D,N.Token=E,N.TokenType=a,N.createPinePlugin=Ht,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
111
111
  //# sourceMappingURL=pine-to-kline.umd.js.map