UNPKG

expression-language

Version:

Javascript implementation of symfony/expression-language

1 lines 75 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ExpressionLanguage={})}(this,function(e){"use strict";function t(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var r=s.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}const s=function(e,t){if(0===e.length)return t.length;if(0===t.length)return e.length;let s,r,n=[];for(s=0;s<=t.length;s++)n[s]=[s];for(r=0;r<=e.length;r++)void 0===n[0]&&(n[0]=[]),n[0][r]=r;for(s=1;s<=t.length;s++)for(r=1;r<=e.length;r++)t.charAt(s-1)===e.charAt(r-1)?n[s][r]=n[s-1][r-1]:n[s][r]=Math.min(n[s-1][r-1]+1,Math.min(n[s][r-1]+1,n[s-1][r]+1));return void 0===n[t.length]&&(n[t.length]=[]),n[t.length][e.length]};class r extends Error{constructor(e,t,s,r,n){super(e),this.name="SyntaxError",this.cursor=t,this.expression=s,this.subject=r,this.proposals=n}toString(){let e=`${this.name}: ${this.message} around position ${this.cursor}`;if(this.expression&&(e+=` for expression \`${this.expression}\``),e+=".",this.subject&&this.proposals){let t=Number.MAX_SAFE_INTEGER,r=null;for(let e of this.proposals){let n=s(this.subject,e);n<t&&(r=e,t=n)}null!==r&&t<3&&(e+=` Did you mean "${r}"?`)}return e}}class n{constructor(e,s){t(this,"next",()=>{if(this.position+=1,void 0===this.tokens[this.position])throw new r("Unexpected end of expression",this.last.cursor,this.expression)}),t(this,"expect",(e,t,s)=>{let n=this.current;if(!n.test(e,t)){let i="";s&&(i=s+". ");let a="";throw t&&(a=` with value "${t}"`),i+=`Unexpected token "${n.type}" of value "${n.value}" ("${e}" expected${a})`,new r(i,n.cursor,this.expression)}this.next()}),t(this,"isEOF",()=>i.EOF_TYPE===this.current.type),t(this,"isEqualTo",e=>{if(null==e||!(e instanceof n))return!1;if(e.tokens.length!==this.tokens.length)return!1;let t=e.position;e.position=0;let s=!0;for(let t of this.tokens){if(!e.current.isEqualTo(t)){s=!1;break}e.position<e.tokens.length-1&&e.next()}return e.position=t,s}),t(this,"diff",e=>{let t=[];if(!this.isEqualTo(e)){let s=0,r=e.position;e.position=0;for(let r of this.tokens){let n=r.diff(e.current);n.length>0&&t.push({index:s,diff:n}),e.position<e.tokens.length-1&&e.next(),s++}e.position=r}return t}),this.expression=e,this.position=0,this.tokens=s}get current(){return this.tokens[this.position]}get last(){return this.tokens[this.position-1]}toString(){return this.tokens.join("\n")}}class i{constructor(e,s,r){t(this,"test",(e,t=null)=>this.type===e&&(null===t||this.value===t)),t(this,"isEqualTo",e=>null!=e&&e instanceof i&&(e.value==this.value&&e.type===this.type&&e.cursor===this.cursor)),t(this,"diff",e=>{let t=[];return this.isEqualTo(e)||(e.value!==this.value&&t.push(`Value: ${e.value} != ${this.value}`),e.cursor!==this.cursor&&t.push(`Cursor: ${e.cursor} != ${this.cursor}`),e.type!==this.type&&t.push(`Type: ${e.type} != ${this.type}`)),t}),this.value=s,this.type=e,this.cursor=r}toString(){return`${this.cursor} [${this.type}] ${this.value}`}}function a(e){let t=0,s=[],a=[],u=(e=e.replace(/\r|\n|\t|\v|\f/g," ")).length;for(;t<u;){if(" "===e[t]){++t;continue}if("/*"===e.substr(t,2)){const s=e.indexOf("*/",t+2);if(-1===s){t=u;break}t=s+2;continue}let n=o(e.substr(t));if(null!==n){const e=n.length,r=n.replace(/_/g,"");n=-1===r.indexOf(".")&&-1===r.indexOf("e")&&-1===r.indexOf("E")?parseInt(r,10):parseFloat(r),s.push(new i(i.NUMBER_TYPE,n,t+1)),t+=e}else if("([{".indexOf(e[t])>=0)a.push([e[t],t]),s.push(new i(i.PUNCTUATION_TYPE,e[t],t+1)),++t;else if(")]}".indexOf(e[t])>=0){if(0===a.length)throw new r(`Unexpected "${e[t]}"`,t,e);let[n,o]=a.pop(),u=n.replace("(",")").replace("{","}").replace("[","]");if(e[t]!==u)throw new r(`Unclosed "${n}"`,o,e);s.push(new i(i.PUNCTUATION_TYPE,e[t],t+1)),++t}else{let n=c(e.substr(t));if(null!==n)s.push(new i(i.STRING_TYPE,n.captured,t+1)),t+=n.length;else if("\\\\"===e.substr(t,2))s.push(new i(i.PUNCTUATION_TYPE,"\\",t+1)),t+=2;else{const n=s.length>0?s[s.length-1]:null;if(n&&n.type===i.PUNCTUATION_TYPE&&("."===n.value||"?."===n.value)){let n=p(e.substr(t));if(n)s.push(new i(i.NAME_TYPE,n,t+1)),t+=n.length;else{let n=f(e.substr(t));if(n)s.push(new i(i.OPERATOR_TYPE,n,t+1)),t+=n.length;else if("?."===e.substr(t,2)||"??"===e.substr(t,2))s.push(new i(i.PUNCTUATION_TYPE,e.substr(t,2),t+1)),t+=2;else{if(!(".,?:".indexOf(e[t])>=0))throw new r(`Unexpected character "${e[t]}"`,t,e);s.push(new i(i.PUNCTUATION_TYPE,e[t],t+1)),++t}}}else{let n=f(e.substr(t));if(n)s.push(new i(i.OPERATOR_TYPE,n,t+1)),t+=n.length;else if("?."===e.substr(t,2)||"??"===e.substr(t,2))s.push(new i(i.PUNCTUATION_TYPE,e.substr(t,2),t+1)),t+=2;else if(".,?:".indexOf(e[t])>=0)s.push(new i(i.PUNCTUATION_TYPE,e[t],t+1)),++t;else{let n=p(e.substr(t));if(!n)throw new r(`Unexpected character "${e[t]}"`,t,e);s.push(new i(i.NAME_TYPE,n,t+1)),t+=n.length}}}}}if(s.push(new i(i.EOF_TYPE,null,t+1)),a.length>0){let[t,s]=a.pop();throw new r(`Unclosed "${t}"`,s,e)}return new n(e,s)}function o(e){let t=null;let s=e.match(/^(?:((?:\d(?:_?\d)*)\.(?:\d(?:_?\d)*)|\.(?:\d(?:_?\d)*)|(?:\d(?:_?\d)*))(?:[eE][+-]?\d(?:_?\d)*)?)/);return s&&s.length>0&&(t=s[0]),t}t(i,"EOF_TYPE","end of expression"),t(i,"NAME_TYPE","name"),t(i,"NUMBER_TYPE","number"),t(i,"STRING_TYPE","string"),t(i,"OPERATOR_TYPE","operator"),t(i,"PUNCTUATION_TYPE","punctuation");const u=/^"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'/s;function h(e,t){return'"'===t?e=e.replace(/\\\"/g,'"'):"'"===t&&(e=e.replace(/\\'/g,"'")),e=e.replace(/\\\\/g,"\\")}function c(e){let t=null;if(-1===["'",'"'].indexOf(e.substr(0,1)))return t;let s=u.exec(e);return null!==s&&s.length>0&&(t=void 0!==s[1]?{captured:h(s[1],'"')}:{captured:h(s[2],"'")},t.length=s[0].length),t}const l=["&&","and","||","or","+","-","**","*","/","%","&","|","^",">>","<<","===","!==","!=","==","<=",">=","<",">","contains","matches","starts with","ends with","not in","in","not","!","xor","~",".."],d=["and","or","matches","contains","starts with","ends with","not in","in","not","xor"];function f(e){let t=null;for(let s of l)if(e.substr(0,s.length)===s){d.indexOf(s)>=0?e.substr(0,s.length+1)===s+" "&&(t=s):t=s;break}return t}function p(e){let t=null,s=e.match(/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/);return s&&s.length>0&&(t=s[0]),t}function m(e){return/boolean|number|string/.test(typeof e)}function g(e,t){var s="",r=[],n=0,i=0,a="",o="",u="",h="",c="",l=0,d=0,f=0,p=0,m=0,g=[],y="",w=/%([\dA-Fa-f]+)/g,b=function(e,t){return(e+="").length<t?new Array(++t-e.length).join("0")+e:e};for(n=0;n<t.length;n++)if(a=t.charAt(n),o=t.charAt(n+1),"\\"===a&&o&&/\d/.test(o)){if(p=n+(f=(u=t.slice(n+1).match(/^\d+/)[0]).length)+1,t.charAt(p)+t.charAt(p+1)===".."){if(l=u.charCodeAt(0),/\\\d/.test(t.charAt(p+2)+t.charAt(p+3)))h=t.slice(p+3).match(/^\d+/)[0],n+=1;else{if(!t.charAt(p+2))throw new Error("Range with no end point");h=t.charAt(p+2)}if((d=h.charCodeAt(0))>l)for(i=l;i<=d;i++)r.push(String.fromCharCode(i));else r.push(".",u,h);n+=h.length+2}else c=String.fromCharCode(parseInt(u,8)),r.push(c);n+=f}else if(o+t.charAt(n+2)===".."){if(l=(u=a).charCodeAt(0),/\\\d/.test(t.charAt(n+3)+t.charAt(n+4)))h=t.slice(n+4).match(/^\d+/)[0],n+=1;else{if(!t.charAt(n+3))throw new Error("Range with no end point");h=t.charAt(n+3)}if((d=h.charCodeAt(0))>l)for(i=l;i<=d;i++)r.push(String.fromCharCode(i));else r.push(".",u,h);n+=h.length+2}else r.push(a);for(n=0;n<e.length;n++)if(a=e.charAt(n),-1!==r.indexOf(a))if(s+="\\",(m=a.charCodeAt(0))<32||m>126)switch(a){case"\n":s+="n";break;case"\t":s+="t";break;case"\r":s+="r";break;case"":s+="a";break;case"\v":s+="v";break;case"\b":s+="b";break;case"\f":s+="f";break;default:for(y=encodeURIComponent(a),null!==(g=w.exec(y))&&(s+=b(parseInt(g[1],16).toString(8),3));null!==(g=w.exec(y));)s+="\\"+b(parseInt(g[1],16).toString(8),3)}else s+=a;else s+=a;return s}class y{constructor(e={},s={}){t(this,"compile",e=>{for(let t of Object.values(this.nodes))t.compile(e)}),t(this,"evaluate",(e,t)=>{let s=[];for(let r of Object.values(this.nodes))s.push(r.evaluate(e,t));return s}),t(this,"toArray",()=>{throw new Error(`Dumping a "${this.name}" instance is not supported yet.`)}),t(this,"dump",()=>{let e="";for(let t of this.toArray())e+=m(t)?t:t.dump();return e}),t(this,"dumpString",e=>`"${g(e,'\0\t"\\')}"`),t(this,"isHash",e=>{let t=0;for(let s of Object.keys(e))if(s=parseInt(s),s!==t++)return!0;return!1}),this.name="Node",this.nodes=e,this.attributes=s}toString(){let e=[];for(let t of Object.keys(this.attributes)){let s="null";this.attributes[t]&&(s=this.attributes[t].toString()),e.push(`${t}: '${s}'`)}let t=[this.name+"("+e.join(", ")];if(this.nodes.length>0){for(let e of Object.values(this.nodes)){let s=e.toString().split("\n");for(let e of s)t.push(" "+e)}t.push(")")}else t[0]+=")";return t.join("\n")}}class w extends y{constructor(e,s,r){super({left:s,right:r},{operator:e}),t(this,"compile",e=>{let t=this.attributes.operator;if("matches"!==t)if("contains"!==t)if("starts with"!==t)if("ends with"!==t){if("in"===t||"not in"===t){let s="not in"===t?"=== -1":">= 0";return void e.raw("(function(__l, __r){return __r.indexOf(__l) "+s+";})(").compile(this.nodes.left).raw(", ").compile(this.nodes.right).raw(")")}".."!==t?void 0===w.functions[t]?(void 0!==w.operators[t]&&(t=w.operators[t]),e.raw("(").compile(this.nodes.left).raw(" ").raw(t).raw(" ").compile(this.nodes.right).raw(")")):e.raw(`${w.functions[t]}(`).compile(this.nodes.left).raw(", ").compile(this.nodes.right).raw(")"):e.raw("(function(__s, __e){var __r=[];for(var __i=__s;__i<=__e;__i++){__r.push(__i);}return __r;})(").compile(this.nodes.left).raw(", ").compile(this.nodes.right).raw(")")}else e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().endsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())");else e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().startsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())");else e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().includes(").compile(this.nodes.right).raw(".toString().toLowerCase())");else e.compile(this.nodes.right).raw(".test(").compile(this.nodes.left).raw(")")}),t(this,"evaluate",(e,t)=>{let s=this.attributes.operator,r=this.nodes.left.evaluate(e,t);if(void 0!==w.functions[s]){let n=this.nodes.right.evaluate(e,t);switch(s){case"not in":return-1===n.indexOf(r);case"in":return n.indexOf(r)>=0;case"..":return function(e,t){let s=[];for(let r=e;r<=t;r++)s.push(r);return s}(r,n);case"**":return Math.pow(r,n)}}let n=null;switch(s){case"or":case"||":return r||(n=this.nodes.right.evaluate(e,t)),r||n;case"and":case"&&":return r&&(n=this.nodes.right.evaluate(e,t)),r&&n;case"xor":return n=this.nodes.right.evaluate(e,t),n&&!r||r&&!n;case"<<":return n=this.nodes.right.evaluate(e,t),r<<n;case">>":return n=this.nodes.right.evaluate(e,t),r>>n}switch(n=this.nodes.right.evaluate(e,t),s){case"|":return r|n;case"^":return r^n;case"&":return r&n;case"==":return r==n;case"===":return r===n;case"!=":return r!=n;case"!==":return r!==n;case"<":return r<n;case">":return r>n;case">=":return r>=n;case"<=":return r<=n;case"not in":return-1===n.indexOf(r);case"in":return n.indexOf(r)>=0;case"+":return r+n;case"-":return r-n;case"~":return r.toString()+n.toString();case"*":return r*n;case"/":return r/n;case"%":return r%n;case"matches":if(null==r)return!1;let e=n.match(w.regex_expression);return new RegExp(e[1],e[2]).test(r);case"contains":return r.toString().toLowerCase().includes(n.toString().toLowerCase());case"starts with":return r.toString().toLowerCase().startsWith(n.toString().toLowerCase());case"ends with":return r.toString().toLowerCase().endsWith(n.toString().toLowerCase())}}),t(this,"toArray",()=>["(",this.nodes.left," "+this.attributes.operator+" ",this.nodes.right,")"]),this.name="BinaryNode"}}t(w,"regex_expression",/\/(.+)\/(.*)/),t(w,"operators",{"~":".",and:"&&",or:"||",xor:"xor","<<":"<<",">>":">>"}),t(w,"functions",{"**":"Math.pow","..":"range",in:"includes","not in":"!includes"});class b extends y{constructor(e,s){super({node:s},{operator:e}),t(this,"compile",e=>{e.raw("(").raw(b.operators[this.attributes.operator]).compile(this.nodes.node).raw(")")}),t(this,"evaluate",(e,t)=>{let s=this.nodes.node.evaluate(e,t);switch(this.attributes.operator){case"not":case"!":return!s;case"-":return-s;case"~":return~s}return s}),t(this,"toArray",()=>["(",this.attributes.operator+" ",this.nodes.node,")"]),this.name="UnaryNode"}}t(b,"operators",{"!":"!",not:"!","+":"+","-":"-","~":"~"});class x extends y{constructor(e,s=!1,r=!1){super({},{value:e}),t(this,"compile",e=>{e.repr(this.attributes.value,this.isIdentifier)}),t(this,"evaluate",(e,t)=>this.attributes.value),t(this,"toArray",()=>{let e=[],t=this.attributes.value;if(this.isIdentifier)e.push(t);else if(!0===t)e.push("true");else if(!1===t)e.push("false");else if(null===t)e.push("null");else if("number"==typeof t)e.push(t);else if("string"==typeof t)e.push(this.dumpString(t));else if(Array.isArray(t)){for(let s of t)e.push(","),e.push(new x(s));e[0]="[",e.push("]")}else if(this.isHash(t)){for(let s of Object.keys(t))e.push(", "),e.push(new x(s)),e.push(": "),e.push(new x(t[s]));e[0]="{",e.push("}")}return e}),this.isIdentifier=s,this.isNullSafe=r,this.name="ConstantNode"}}class v extends y{constructor(e,s,r){super({expr1:e,expr2:s,expr3:r}),t(this,"compile",e=>{e.raw("((").compile(this.nodes.expr1).raw(") ? (").compile(this.nodes.expr2).raw(") : (").compile(this.nodes.expr3).raw("))")}),t(this,"evaluate",(e,t)=>this.nodes.expr1.evaluate(e,t)?this.nodes.expr2.evaluate(e,t):this.nodes.expr3.evaluate(e,t)),t(this,"toArray",()=>["(",this.nodes.expr1," ? ",this.nodes.expr2," : ",this.nodes.expr3,")"]),this.name="ConditionalNode"}}class k extends y{constructor(e,s){super({fnArguments:s},{name:e}),t(this,"compile",e=>{let t=[];for(let s of Object.values(this.nodes.fnArguments.nodes))t.push(e.subcompile(s));let s=e.getFunction(this.attributes.name);e.raw(s.compiler.apply(null,t))}),t(this,"evaluate",(e,t)=>{let s=[t];for(let r of Object.values(this.nodes.fnArguments.nodes))s.push(r.evaluate(e,t));return e[this.attributes.name].evaluator.apply(null,s)}),t(this,"toArray",()=>{let e=[];e.push(this.attributes.name);for(let t of Object.values(this.nodes.fnArguments.nodes))e.push(", "),e.push(t);return e[1]="(",e.push(")"),e}),this.name="FunctionNode"}}class N extends y{constructor(e){super({},{name:e}),t(this,"compile",e=>{e.raw(this.attributes.name)}),t(this,"evaluate",(e,t)=>t[this.attributes.name]),t(this,"toArray",()=>[this.attributes.name]),this.name="NameNode"}}class T extends y{constructor(){super(),t(this,"addElement",(e,t=null)=>{null===t?t=new x(++this.index):"Array"===this.type&&(this.type="Object"),this.nodes[(++this.keyIndex).toString()]=t,this.nodes[(++this.keyIndex).toString()]=e}),t(this,"compile",e=>{"Object"===this.type?e.raw("{"):e.raw("["),this.compileArguments(e,"Array"!==this.type),"Object"===this.type?e.raw("}"):e.raw("]")}),t(this,"evaluate",(e,t)=>{let s;if("Array"===this.type){s=[];for(let r of this.getKeyValuePairs())s.push(r.value.evaluate(e,t))}else{s={};for(let r of this.getKeyValuePairs())s[r.key.evaluate(e,t)]=r.value.evaluate(e,t)}return s}),t(this,"toArray",()=>{let e={};for(let t of this.getKeyValuePairs())e[t.key.attributes.value]=t.value;let t=[];if(this.isHash(e)){for(let s of Object.keys(e))t.push(", "),t.push(new x(s)),t.push(": "),t.push(e[s]);t[0]="{",t.push("}")}else{for(let s of Object.values(e))t.push(", "),t.push(s);t[0]="[",t.push("]")}return t}),t(this,"getKeyValuePairs",()=>{let e,t,s,r=[],n=Object.values(this.nodes);for(e=0,t=n.length;e<t;e+=2)s=n.slice(e,e+2),r.push({key:s[0],value:s[1]});return r}),t(this,"compileArguments",(e,t=!0)=>{let s=!0;for(let r of this.getKeyValuePairs())s||e.raw(", "),s=!1,t&&e.compile(r.key).raw(": "),e.compile(r.value)}),this.name="ArrayNode",this.type="Array",this.index=-1,this.keyIndex=-1}}class E extends T{constructor(){super(),t(this,"compile",e=>{this.compileArguments(e,!1)}),t(this,"toArray",()=>{let e=[];for(let t of this.getKeyValuePairs())e.push(t.value),e.push(", ");return e.pop(),e}),this.name="ArgumentsNode"}}class _ extends y{constructor(e,s,r,n){super({node:e,attribute:s,fnArguments:r},{type:n,is_null_coalesce:!1,is_short_circuited:!1}),t(this,"compile",e=>{const t=this.nodes.attribute instanceof x&&this.nodes.attribute.isNullSafe;switch(this.attributes.type){case _.PROPERTY_CALL:e.compile(this.nodes.node).raw(t?"?.":".").raw(this.nodes.attribute.attributes.value);break;case _.METHOD_CALL:e.compile(this.nodes.node).raw(t?"?.":".").raw(this.nodes.attribute.attributes.value).raw("(").compile(this.nodes.fnArguments).raw(")");break;case _.ARRAY_CALL:e.compile(this.nodes.node).raw("[").compile(this.nodes.attribute).raw("]")}}),t(this,"evaluate",(e,t)=>{switch(this.attributes.type){case _.PROPERTY_CALL:let s=this.nodes.node.evaluate(e,t);if(null===s&&(this.nodes.attribute.isNullSafe||this.attributes.is_null_coalesce))return this.attributes.is_short_circuited=!0,null;if(null===s&&this.isShortCircuited())return null;let r=this.nodes.attribute.attributes.value;if("object"!=typeof s)throw new Error(`Unable to get property "${r}" on a non-object: `+typeof s);return this.attributes.is_null_coalesce?s[r]??null:s[r];case _.METHOD_CALL:let n=this.nodes.node.evaluate(e,t);if(null===n&&this.nodes.attribute.isNullSafe)return this.attributes.is_short_circuited=!0,null;if(null===n&&this.isShortCircuited())return null;let i=this.nodes.attribute.attributes.value;if("object"!=typeof n)throw new Error(`Unable to call method "${i}" on a non-object: `+typeof n);if(void 0===n[i])throw new Error(`Method "${i}" is undefined on object.`);if("function"!=typeof n[i])throw new Error(`Method "${i}" is not a function on object.`);let a=this.nodes.fnArguments.evaluate(e,t);return n[i].apply(null,a);case _.ARRAY_CALL:let o=this.nodes.node.evaluate(e,t);if(null===o&&this.isShortCircuited())return null;if(!(Array.isArray(o)||"object"==typeof o||null===o&&this.attributes.is_null_coalesce))throw new Error("Unable to get an item on a non-array: "+typeof o);return this.attributes.is_null_coalesce?o?o[this.nodes.attribute.evaluate(e,t)]??null:null:o[this.nodes.attribute.evaluate(e,t)]}}),t(this,"toArray",()=>{const e=this.nodes.attribute instanceof x&&this.nodes.attribute.isNullSafe;switch(this.attributes.type){case _.PROPERTY_CALL:return[this.nodes.node,e?"?.":".",this.nodes.attribute];case _.METHOD_CALL:return[this.nodes.node,e?"?.":".",this.nodes.attribute,"(",this.nodes.fnArguments,")"];case _.ARRAY_CALL:return[this.nodes.node,"[",this.nodes.attribute,"]"]}}),this.name="GetAttrNode"}isShortCircuited(){return this.attributes.is_short_circuited||this.nodes.node instanceof _&&this.nodes.node.isShortCircuited()}}t(_,"PROPERTY_CALL",1),t(_,"METHOD_CALL",2),t(_,"ARRAY_CALL",3);class A extends y{constructor(e,s){super({expr1:e,expr2:s}),t(this,"compile",e=>{e.raw("((").compile(this.nodes.expr1).raw(") ?? (").compile(this.nodes.expr2).raw("))")}),t(this,"evaluate",(e,t)=>(this.nodes.expr1 instanceof _&&this._addNullCoalesceAttributeToGetAttrNodes(this.nodes.expr1),this.nodes.expr1.evaluate(e,t)??this.nodes.expr2.evaluate(e,t))),t(this,"toArray",()=>["(",this.nodes.expr1,") ?? (",this.nodes.expr2,")"]),t(this,"_addNullCoalesceAttributeToGetAttrNodes",e=>{if(e instanceof _){e.attributes.is_null_coalesce=!0;for(let t of Object.values(e.nodes))this._addNullCoalesceAttributeToGetAttrNodes(t)}}),this.name="NullCoalesceNode"}}class S extends y{constructor(e){super({},{name:e}),t(this,"compile",e=>{e.raw(this.attributes.name+" ?? null")}),t(this,"evaluate",(e,t)=>null),t(this,"toArray",()=>[this.attributes.name+" ?? null"]),this.name="NullCoalescedNameNode"}}class O{constructor(e={}){t(this,"functions",{}),t(this,"unaryOperators",{not:{precedence:50},"!":{precedence:50},"-":{precedence:500},"+":{precedence:500},"~":{precedence:500}}),t(this,"binaryOperators",{or:{precedence:10,associativity:1},"||":{precedence:10,associativity:1},xor:{precedence:12,associativity:1},and:{precedence:15,associativity:1},"&&":{precedence:15,associativity:1},"|":{precedence:16,associativity:1},"^":{precedence:17,associativity:1},"&":{precedence:18,associativity:1},"==":{precedence:20,associativity:1},"===":{precedence:20,associativity:1},"!=":{precedence:20,associativity:1},"!==":{precedence:20,associativity:1},"<":{precedence:20,associativity:1},">":{precedence:20,associativity:1},">=":{precedence:20,associativity:1},"<=":{precedence:20,associativity:1},"not in":{precedence:20,associativity:1},in:{precedence:20,associativity:1},matches:{precedence:20,associativity:1},contains:{precedence:20,associativity:1},"starts with":{precedence:20,associativity:1},"ends with":{precedence:20,associativity:1},"..":{precedence:25,associativity:1},"<<":{precedence:25,associativity:1},">>":{precedence:25,associativity:1},"+":{precedence:30,associativity:1},"-":{precedence:30,associativity:1},"~":{precedence:40,associativity:1},"*":{precedence:60,associativity:1},"/":{precedence:60,associativity:1},"%":{precedence:60,associativity:1},"**":{precedence:200,associativity:2}}),t(this,"parse",(e,t=[],s=0)=>{this.tokenStream=e,this.names=t,this.objectMatches={},this.cachedNames=null,this.nestedExecutions=0,this.flags=s;let n=this.parseExpression();if(!this.tokenStream.isEOF())throw new r(`Unexpected token "${this.tokenStream.current.type}" of value "${this.tokenStream.current.value}"`,this.tokenStream.current.cursor,this.tokenStream.expression);return n}),t(this,"lint",(e,t=[],s=0)=>{null===t&&(console.log('Deprecated: passing "null" as the second argument of lint is deprecated, pass IGNORE_UNKNOWN_VARIABLES instead as the third argument'),s|=1,t=[]),this.parse(e,t,s)}),t(this,"parseExpression",(e=0)=>{let t=this.getPrimary(),s=this.tokenStream.current;if(this.nestedExecutions++,this.nestedExecutions>1e3)throw new Error("Too many executions on '"+s.toString()+"' of '"+this.tokenStream.toString()+"'");for(;s.test(i.OPERATOR_TYPE)&&void 0!==this.binaryOperators[s.value]&&null!==this.binaryOperators[s.value]&&this.binaryOperators[s.value].precedence>=e;){let e=this.binaryOperators[s.value];this.tokenStream.next();let r=this.parseExpression(1===e.associativity?e.precedence+1:e.precedence);t=new w(s.value,t,r),s=this.tokenStream.current}return 0===e?this.parseConditionalExpression(t):t}),t(this,"getPrimary",()=>{let e=this.tokenStream.current;if(e.test(i.OPERATOR_TYPE)&&void 0!==this.unaryOperators[e.value]&&null!==this.unaryOperators[e.value]){let t=this.unaryOperators[e.value];this.tokenStream.next();let s=this.parseExpression(t.precedence);return this.parsePostfixExpression(new b(e.value,s))}if(e.test(i.PUNCTUATION_TYPE,"(")){this.tokenStream.next();let e=this.parseExpression();return this.tokenStream.expect(i.PUNCTUATION_TYPE,")","An opened parenthesis is not properly closed"),this.parsePostfixExpression(e)}return this.parsePrimaryExpression()}),t(this,"hasVariable",e=>this.getNames().indexOf(e)>=0),t(this,"getNames",()=>{if(null!==this.cachedNames)return this.cachedNames;if(this.names&&this.names.length>0){let e=[],t=0;this.objectMatches={};for(let s of this.names)"object"==typeof s?(this.objectMatches[Object.values(s)[0]]=t,e.push(Object.keys(s)[0]),e.push(Object.values(s)[0])):e.push(s),t++;return this.cachedNames=e,e}return[]}),t(this,"parseArrayExpression",()=>{this.tokenStream.expect(i.PUNCTUATION_TYPE,"[","An array element was expected");let e=new T,t=!0;for(;!this.tokenStream.current.test(i.PUNCTUATION_TYPE,"]")&&(t||(this.tokenStream.expect(i.PUNCTUATION_TYPE,",","An array element must be followed by a comma"),!this.tokenStream.current.test(i.PUNCTUATION_TYPE,"]")));)t=!1,e.addElement(this.parseExpression());return this.tokenStream.expect(i.PUNCTUATION_TYPE,"]","An opened array is not properly closed"),e}),t(this,"parseHashExpression",()=>{this.tokenStream.expect(i.PUNCTUATION_TYPE,"{","A hash element was expected");let e=new T,t=!0;for(;!this.tokenStream.current.test(i.PUNCTUATION_TYPE,"}")&&(t||(this.tokenStream.expect(i.PUNCTUATION_TYPE,",","A hash value must be followed by a comma"),!this.tokenStream.current.test(i.PUNCTUATION_TYPE,"}")));){t=!1;let s=null;if(this.tokenStream.current.test(i.STRING_TYPE)||this.tokenStream.current.test(i.NAME_TYPE)||this.tokenStream.current.test(i.NUMBER_TYPE))s=new x(this.tokenStream.current.value),this.tokenStream.next();else{if(!this.tokenStream.current.test(i.PUNCTUATION_TYPE,"(")){let e=this.tokenStream.current;throw new r(`A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "${e.type}" of value "${e.value}"`,e.cursor,this.tokenStream.expression)}s=this.parseExpression()}this.tokenStream.expect(i.PUNCTUATION_TYPE,":","A hash key must be followed by a colon (:)");let n=this.parseExpression();e.addElement(n,s)}return this.tokenStream.expect(i.PUNCTUATION_TYPE,"}","An opened hash is not properly closed"),e}),t(this,"parsePostfixExpression",e=>{let t=this.tokenStream.current;for(;i.PUNCTUATION_TYPE===t.type;){if("."===t.value||"?."===t.value){const s="?."===t.value;if(this.tokenStream.next(),t=this.tokenStream.current,this.tokenStream.next(),i.NAME_TYPE!==t.type&&(i.OPERATOR_TYPE!==t.type||!/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/.test(t.value)))throw new r("Expected name",t.cursor,this.tokenStream.expression);let n=new x(t.value,!0,s),a=new E,o=null;if(this.tokenStream.current.test(i.PUNCTUATION_TYPE,"(")){o=_.METHOD_CALL;for(let e of Object.values(this.parseArguments().nodes))a.addElement(e)}else o=_.PROPERTY_CALL;e=new _(e,n,a,o)}else{if("["!==t.value)break;{this.tokenStream.next();let t=this.parseExpression();this.tokenStream.expect(i.PUNCTUATION_TYPE,"]"),e=new _(e,t,new E,_.ARRAY_CALL)}}t=this.tokenStream.current}return e}),t(this,"parseArguments",()=>{let e=[];for(this.tokenStream.expect(i.PUNCTUATION_TYPE,"(","A list of arguments must begin with an opening parenthesis");!this.tokenStream.current.test(i.PUNCTUATION_TYPE,")");)0!==e.length&&this.tokenStream.expect(i.PUNCTUATION_TYPE,",","Arguments must be separated by a comma"),e.push(this.parseExpression());return this.tokenStream.expect(i.PUNCTUATION_TYPE,")","A list of arguments must be closed by a parenthesis"),new y(e)}),this.functions=e,this.tokenStream=null,this.names=null,this.objectMatches={},this.cachedNames=null,this.nestedExecutions=0,this.flags=0}parseConditionalExpression(e){for(;this.tokenStream.current.test(i.PUNCTUATION_TYPE,"??");){this.tokenStream.next();let t=this.parseExpression();e=new A(e,t)}for(;this.tokenStream.current.test(i.PUNCTUATION_TYPE,"?");){let t,s;this.tokenStream.next(),this.tokenStream.current.test(i.PUNCTUATION_TYPE,":")?(this.tokenStream.next(),t=e,s=this.parseExpression()):(t=this.parseExpression(),this.tokenStream.current.test(i.PUNCTUATION_TYPE,":")?(this.tokenStream.next(),s=this.parseExpression()):t instanceof x&&"string"==typeof t.attributes?.value?s=new x(""):t instanceof v?(s=t.nodes.expr3,t=t.nodes.expr2):(s=t,t=e)),e=new v(e,t,s)}return e}parsePrimaryExpression(){let e=this.tokenStream.current,t=null;switch(e.type){case i.NAME_TYPE:switch(this.tokenStream.next(),e.value){case"true":case"TRUE":return new x(!0);case"false":case"FALSE":return new x(!1);case"null":case"NULL":return new x(null);default:if("("===this.tokenStream.current.value){if(void 0===this.functions[e.value]&&!(2&this.flags))throw new r(`The function "${e.value}" does not exist`,e.cursor,this.tokenStream.expression,e.values,Object.keys(this.functions));t=new k(e.value,this.parseArguments())}else{let s=null;if(1&this.flags)s=e.value;else{if(!this.hasVariable(e.value)){if(this.tokenStream.current.test(i.PUNCTUATION_TYPE,"??"))return new S(e.value);throw new r(`Variable "${e.value}" is not valid`,e.cursor,this.tokenStream.expression,e.value,this.getNames())}s=e.value,void 0!==this.objectMatches[s]&&(s=this.getNames()[this.objectMatches[s]])}t=new N(s)}}break;case i.NUMBER_TYPE:case i.STRING_TYPE:return this.tokenStream.next(),new x(e.value);default:if(e.test(i.PUNCTUATION_TYPE,"["))t=this.parseArrayExpression();else{if(!e.test(i.PUNCTUATION_TYPE,"{"))throw new r(`Unexpected token "${e.type}" of value "${e.value}"`,e.cursor,this.tokenStream.expression);t=this.parseHashExpression()}}return this.parsePostfixExpression(t)}}class C{constructor(e){t(this,"getFunction",e=>this.functions[e]),t(this,"getSource",()=>this.source),t(this,"reset",()=>(this.source="",this)),t(this,"compile",e=>(e.compile(this),this)),t(this,"subcompile",e=>{let t=this.source;this.source="",e.compile(this);let s=this.source;return this.source=t,s}),t(this,"raw",e=>(this.source+=e,this)),t(this,"string",e=>(this.source+='"'+g(e,'\0\t"$\\')+'"',this)),t(this,"repr",(e,t=!1)=>{if(t)this.raw(e);else if(Number.isInteger(e)||+e===e&&(!isFinite(e)||e%1))this.raw(e);else if(null===e)this.raw("null");else if("boolean"==typeof e)this.raw(e?"true":"false");else if(Array.isArray(e)){this.raw("[");let t=!0;for(let s of e)t||this.raw(", "),t=!1,this.repr(s);this.raw("]")}else if("object"==typeof e){this.raw("{");let t=!0;for(let s of Object.keys(e))t||this.raw(", "),t=!1,this.repr(s),this.raw(":"),this.repr(e[s]);this.raw("}")}else this.string(e);return this}),this.source="",this.functions=e}}class ${constructor(e){this.expression=e}toString(){return this.expression}}class P extends ${constructor(e,s){super(e),t(this,"getNodes",()=>this.nodes),this.nodes=s}static fromJSON(e){const t="string"==typeof e?JSON.parse(e):e,s=e=>{if(null==e)return e;if(e instanceof y)return e;if("object"!=typeof e||!e.name)return e;switch(e.name){case"ConstantNode":return new x(e.attributes?.value,!!e.isIdentifier,!!e.isNullSafe);case"NameNode":return new N(e.attributes?.name);case"NullCoalescedNameNode":return new S(e.attributes?.name);case"UnaryNode":return new b(e.attributes?.operator,s(e.nodes?.node));case"BinaryNode":return new w(e.attributes?.operator,s(e.nodes?.left),s(e.nodes?.right));case"ConditionalNode":return new v(s(e.nodes?.expr1),s(e.nodes?.expr2),s(e.nodes?.expr3));case"NullCoalesceNode":return new A(s(e.nodes?.expr1),s(e.nodes?.expr2));case"ArgumentsNode":{const t=new E;"string"==typeof e.type&&(t.type=e.type),"number"==typeof e.index&&(t.index=e.index),"number"==typeof e.keyIndex&&(t.keyIndex=e.keyIndex),t.nodes={};for(const r of Object.keys(e.nodes||{}))t.nodes[r]=s(e.nodes[r]);return t}case"ArrayNode":{const t=new T;"string"==typeof e.type&&(t.type=e.type),"number"==typeof e.index&&(t.index=e.index),"number"==typeof e.keyIndex&&(t.keyIndex=e.keyIndex),t.nodes={};for(const r of Object.keys(e.nodes||{}))t.nodes[r]=s(e.nodes[r]);return t}case"FunctionNode":{const t=s(e.nodes?.fnArguments);return new k(e.attributes?.name,t)}case"GetAttrNode":{const t=new _(s(e.nodes?.node),s(e.nodes?.attribute),s(e.nodes?.fnArguments),e.attributes?.type);return e.attributes&&"boolean"==typeof e.attributes.is_null_coalesce&&(t.attributes.is_null_coalesce=e.attributes.is_null_coalesce),e.attributes&&"boolean"==typeof e.attributes.is_short_circuited&&(t.attributes.is_short_circuited=e.attributes.is_short_circuited),t}case"Node":{const t=new y;if(Array.isArray(e.nodes))t.nodes=e.nodes.map(s);else{t.nodes={};for(const r of Object.keys(e.nodes||{}))t.nodes[r]=s(e.nodes[r])}return t.attributes=e.attributes||{},t}default:{const t=new y;if(t.name=e.name,Array.isArray(e.nodes))t.nodes=e.nodes.map(s);else{t.nodes={};for(const r of Object.keys(e.nodes||{}))t.nodes[r]=s(e.nodes[r])}return t.attributes=e.attributes||{},t}}},r=t.expression,n=(e=>{if(null==e)return e;if(e.name)return s(e);if(Array.isArray(e))return e.map(s);if("object"==typeof e){const t={};for(const r of Object.keys(e))t[r]=s(e[r]);return t}return e})(t.nodes);return new P(r,n)}}var R;class U{constructor(e=0){t(this,"createCacheItem",(e,t,s)=>{let r=new j;return r.key=e,r.value=t,r.isHit=s,r.defaultLifetime=this.defaultLifetime,r}),t(this,"get",(e,t,s=null,r=null)=>{let n=this.getItem(e);if(!n.isHit){let e=!0;this.save(n.set(t(n,e)))}return n.get()}),t(this,"getItem",e=>{let t=this.hasItem(e),s=null;return t?s=this.values[e]:this.values[e]=null,(0,this.createCacheItem)(e,s,t)}),t(this,"getItems",e=>{for(let t of e)"string"==typeof t||this.expiries[t]||j.validateKey(t);return this.generateItems(e,(new Date).getTime()/1e3,this.createCacheItem)}),t(this,"deleteItems",e=>{for(let t of e)this.deleteItem(t);return!0}),t(this,"save",e=>e instanceof j&&(null!==e.expiry&&e.expiry<=(new Date).getTime()/1e3?(this.deleteItem(e.key),!0):(null===e.expiry&&0<e.defaultLifetime&&(e.expiry=(new Date).getTime()/1e3+e.defaultLifetime),this.values[e.key]=e.value,this.expiries[e.key]=e.expiry||Number.MAX_SAFE_INTEGER,!0))),t(this,"saveDeferred",e=>this.save(e)),t(this,"commit",()=>!0),t(this,"delete",e=>this.deleteItem(e)),t(this,"getValues",()=>this.values),t(this,"hasItem",e=>!!("string"==typeof e&&this.expiries[e]&&this.expiries[e]>(new Date).getTime()/1e3)||(j.validateKey(e),!!this.expiries[e]&&!this.deleteItem(e))),t(this,"clear",()=>(this.values={},this.expiries={},!0)),t(this,"deleteItem",e=>("string"==typeof e&&this.expiries[e]||j.validateKey(e),delete this.values[e],delete this.expiries[e],!0)),t(this,"reset",()=>{this.clear()}),t(this,"generateItems",(e,t,s)=>{let r=[];for(let n of e){let e=null,i=!!this.expiries[n];i||!(this.expiries[n]>t)&&this.deleteItem(n)?e=this.values[n]:this.values[n]=null,r[n]=s(n,e,i)}return r}),this.defaultLifetime=e,this.values={},this.expiries={}}}class j{constructor(){t(this,"getKey",()=>this.key),t(this,"get",()=>this.value),t(this,"set",e=>(this.value=e,this)),t(this,"expiresAt",e=>{if(null===e)this.expiry=this.defaultLifetime>0?Date.now()/1e3+this.defaultLifetime:null;else{if(!(e instanceof Date))throw new Error(`Expiration date must be instance of Date or be null, "${e.name}" given`);this.expiry=e.getTime()/1e3}return this}),t(this,"expiresAfter",e=>{if(null===e)this.expiry=this.defaultLifetime>0?Date.now()/1e3+this.defaultLifetime:null;else{if(!Number.isInteger(e))throw new Error(`Expiration date must be an integer or be null, "${e.name}" given`);this.expiry=(new Date).getTime()/1e3+e}return this}),t(this,"tag",e=>{if(!this.isTaggable)throw new Error(`Cache item "${this.key}" comes from a non tag-aware pool: you cannot tag it.`);Array.isArray(e)||(e=[e]);for(let t of e){if("string"!=typeof t)throw new Error(`Cache tag must by a string, "${typeof t}" given.`);if(this.newMetadata.tags[t]&&""===t)throw new Error("Cache tag length must be greater than zero");this.newMetadata.tags[t]=t}return this}),t(this,"getMetadata",()=>this.metadata),this.key=null,this.value=null,this.isHit=!1,this.expiry=null,this.defaultLifetime=null,this.metadata={},this.newMetadata={},this.innerItem=null,this.poolHash=null,this.isTaggable=!1}}R=j,t(j,"METADATA_EXPIRY_OFFSET",1527506807),t(j,"RESERVED_CHARACTERS",["{","}","(",")","/","\\","@",":"]),t(j,"validateKey",e=>{if("string"!=typeof e)throw new Error(`Cache key must be string, "${typeof e}" given.`);if(""===e)throw new Error("Cache key length must be greater than zero");for(let t of R.RESERVED_CHARACTERS)if(e.indexOf(t)>=0)throw new Error(`Cache key "${e}" contains reserved character "${t}".`);return e});class M extends Error{constructor(e){super(e),this.name="LogicException"}toString(){return`${this.name}: ${this.message}`}}class Y{constructor(e,s,r){t(this,"getName",()=>this.name),t(this,"getCompiler",()=>this.compiler),t(this,"getEvaluator",()=>this.evaluator),this.name=e,this.compiler=s,this.evaluator=r}static fromJavascript(e,t=null){if("string"!=typeof e||0===e.length)throw new TypeError("A JavaScript function name (string) must be provided.");const s=e.replace(/^\/+/,""),r=s.split(".");let n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};for(const e of r){if(null==n)break;n=n[e]}if("function"!=typeof n)throw new Error(`JavaScript function "${s}" does not exist.`);if(!t&&r.length>1)throw new Error(`An expression function name must be defined when JavaScript function "${s}" is namespaced.`);return new this(t||r[r.length-1],(...e)=>`${s}(${e.join(", ")})`,(e,...t)=>n(...t))}}class D{constructor(e=null,s=[]){t(this,"compile",(e,t=[])=>this.getCompiler().compile(this.parse(e,t).getNodes()).getSource()),t(this,"evaluate",(e,t={})=>this.parse(e,Object.keys(t)).getNodes().evaluate(this.functions,t)),t(this,"parse",(e,t=[],s=0)=>{if(e instanceof P)return e;t.sort((e,t)=>{let s=e,r=t;return"object"==typeof e&&(s=Object.values(e)[0]),"object"==typeof t&&(r=Object.values(t)[0]),s.localeCompare(r)});let r=[];for(let e of t){let t=e;if("object"==typeof e){t=Object.keys(e)[0]+":"+Object.values(e)[0]}r.push(t)}let n=this.cache.getItem(this.fixedEncodeURIComponent(e+"//"+r.join("|"))),i=n.get();if(null===i){let r=this.getParser().parse(this.getLexer().tokenize(e),t,s);i=new P(e,r),n.set(i),this.cache.save(n)}return i}),t(this,"lint",(e,t=null,s=0)=>{null===t&&(console.log('Deprecated: passing "null" as the second argument of lint is deprecated, pass IGNORE_UNKNOWN_VARIABLES instead as the third argument'),s|=1,t=[]),e instanceof P||this.getParser().lint(this.getLexer().tokenize(e),t,s)}),t(this,"fixedEncodeURIComponent",e=>encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16)})),t(this,"register",(e,t,s)=>{if(null!==this.parser)throw new M("Registering functions after calling evaluate(), compile(), or parse() is not supported.");this.functions[e]={compiler:t,evaluator:s}}),t(this,"addFunction",e=>{this.register(e.getName(),e.getCompiler(),e.getEvaluator())}),t(this,"registerProvider",e=>{for(let t of e.getFunctions())this.addFunction(t)}),t(this,"getLexer",()=>(null===this.lexer&&(this.lexer={tokenize:a}),this.lexer)),t(this,"getParser",()=>(null===this.parser&&(this.parser=new O(this.functions)),this.parser)),t(this,"getCompiler",()=>(null===this.compiler&&(this.compiler=new C(this.functions)),this.compiler.reset())),this.functions=[],this.lexer=null,this.parser=null,this.compiler=null,this.cache=e||new U,this._registerBuiltinFunctions();for(let e of s)this.registerProvider(e)}_registerBuiltinFunctions(){const e=Y.fromJavascript("Math.min","min"),t=Y.fromJavascript("Math.max","max");this.addFunction(e),this.addFunction(t),this.addFunction(new Y("constant",function(e){return`(function(__n){var __g=(typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:{})));return __n.split('.').reduce(function(o,k){return o==null?undefined:o[k];}, __g)})(${e})`},function(e,t){if("string"!=typeof t||!t)return;let s=(r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},t.split(".").reduce((e,t)=>null==e?void 0:e[t],r));var r;return void 0===s&&e&&Object.prototype.hasOwnProperty.call(e,t)&&(s=e[t]),s})),this.addFunction(new Y("enum",function(e){return`(function(__n){var __g=(typeof globalThis!=='undefined'?globalThis:(typeof window!=='undefined'?window:(typeof global!=='undefined'?global:{})));if(typeof __n!=='string'||!__n)return undefined;var s=String(__n);var keys=[],buf='';for(var i=0;i<s.length;i++){var c=s.charCodeAt(i);if(c===46||c===92){if(buf){keys.push(buf);buf='';}continue;}if(c===58){if(i+1<s.length&&s.charCodeAt(i+1)===58){if(buf){keys.push(buf);buf='';}i++;continue;}}buf+=s[i];}if(buf)keys.push(buf);return keys.reduce(function(o,k){return o==null?undefined:o[k];}, __g)})(${e})`},function(e,t){if("string"!=typeof t||!t)return;const s=String(t).replace(/\\/g,".").replace(/::/g,".");var r;return s?(r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s.split(".").reduce((e,t)=>null==e?void 0:e[t],r)):void 0}))}}class I{getFunctions(){throw new Error("getFunctions must be implemented by "+this.constructor.name)}}const L=new Y("isset",function(e){if(/^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')$/.test(e))throw new Error('isset() does not support compile() when called with a string-literal path (e.g. isset("foo.bar")). Use an expression path instead (e.g. isset(foo.bar) or isset(foo?.bar)), or call evaluate() directly.');return`(function(){try{var __v=(${e});return __v!==null&&__v!==undefined;}catch(e){return false;}})()`},function(e,t){if("string"!=typeof t)return null!=t;if(!(t.split(/[.\[]/)[0]in e))return!0;let s="",r=[],n="",i="";for(let e=0;e<t.length;e++){let a=t[e];if("]"!==a)if("["!==a){if("object"===n&&(!/[A-z0-9_]/.test(a)||e===t.length-1)){let s=!1;if(e===t.length-1&&(i+=a,s=!0),n="",r.push({type:"object",attribute:i}),i="",s)continue}"."!==a?n?i+=a:s+=a:(n="object",i="")}else n="array",i="";else n="",r.push({type:"array",index:i.replace(/"/g,"").replace(/'/g,"")}),i=""}if(r.length>0){if(void 0!==e[s]){let t=e[s];for(let e of r){if("array"===e.type){if(void 0===t[e.index])return!1;t=t[e.index]}if("object"===e.type){if(void 0===t[e.attribute])return!1;t=t[e.attribute]}}return!0}return!1}return void 0!==e[s]});function F(...e){let[t,s,r]=e,n=t;const i=s;if(e.length<2||void 0===n||void 0===i)return null;if(""===n||!1===n||null===n)return!1;if("function"==typeof n||"object"==typeof n||"function"==typeof i||"object"==typeof i)return{0:""};!0===n&&(n="1");const a=n+"",o=(i+"").split(a);return void 0===r?o:(0===r&&(r=1),r>0?r>=o.length?o:o.slice(0,r-1).concat([o.slice(r-1).join(a)]):-r>=o.length?[]:(o.splice(o.length+r),o))}const z=e=>Object.entries(e);function H(e){return"object"==typeof e&&null!==e}function W(e){return H(e)&&!function(e){return Array.isArray(e)}(e)}function B(e){return function(e){return H(e)}(e)?e:{}}const G="object"==typeof window&&null!==window?window:"object"==typeof global&&null!==global?global:{};function V(){const e=(()=>{let e=G.$locutus;"object"==typeof e&&null!==e||(e={},G.$locutus=e);let t=e.php;return"object"==typeof t&&null!==t||(t={},e.php=t),t})(),t=e.ini,s=e.locales,r=e.localeCategories,n=e.pointers,i=W(t)?t:{};const a=(e=>W(e))(s)?s:{},o=(e=>W(e))(r)?r:{},u=Array.isArray(n)?n:[];t!==i&&(e.ini=i),s!==a&&(e.locales=a),r!==o&&(e.localeCategories=o),n!==u&&(e.pointers=u);const h=e.locale_default;return{ini:i,locales:a,localeCategories:o,pointers:u,locale_default:"string"==typeof h?h:void 0}}function J(e){const t=V().ini[e];return t&&void 0!==t.local_value?null===t.local_value?"":String(t.local_value):""}function K(e){if(void 0===e)throw new Error("strlen() expects exactly 1 argument, 0 given");const t=e+"";if("off"===(J("unicode.semantics")||"off"))return t.length;let s=0,r=0;const n=function(e,t){const s=e.charCodeAt(t);if(s>=55296&&s<=56319){if(e.length<=t+1)throw new Error("High surrogate without following low surrogate");const s=e.charCodeAt(t+1);if(s<56320||s>57343)throw new Error("High surrogate without following low surrogate");return e.charAt(t)+e.charAt(t+1)}if(s>=56320&&s<=57343){if(0===t)throw new Error("Low surrogate without preceding high surrogate");const s=e.charCodeAt(t-1);if(s<55296||s>56319)throw new Error("Low surrogate without preceding high surrogate");return!1}return e.charAt(t)};for(s=0,r=0;s<t.length;s++)!1!==n(t,s)&&r++;return r}function q(e){if(void 0===e)throw new Error("strtolower() expects exactly 1 argument, 0 given");return(e+"").toLowerCase()}function Z(e){if(void 0===e)throw new Error("strtoupper() expects exactly 1 argument, 0 given");return(e+"").toUpperCase()}function X(e,t,s){const r=function(e){if("boolean"==typeof e)return e?"1":"";if("string"==typeof e)return e;if("number"==typeof e)return isNaN(e)?"NAN":isFinite(e)?e+"":(e<0?"-":"")+"INF";if(void 0===e)return"";if("object"==typeof e)return Array.isArray(e)?"Array":null!==e?"Object":"";throw new Error("Unsupported value type")}(e),n="on"===J("unicode.semantics")?r.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\s\S]/g)||[]:null,i=n?n.length:r.length;let a=i;return t<0&&(t+=a),void 0!==s&&(a=s<0?s+a:s+t),!(t>i||t<0||t>a)&&(n?n.slice(t,a).join(""):r.slice(t,a))}function Q(e,t,s){let r=0;return r=(e+="").indexOf(t),-1!==r&&(s?e.substr(0,r):e.slice(r))}function ee(e,t,s){let r=0;return r=(e+="").toLowerCase().indexOf((t+"").toLowerCase()),-1!==r&&(s?e.substr(0,r):e.slice(r))}function te(e,...t){const s={};if(t.length<1)return s;const r=B(e);e:for(const[e,n]of z(r)){for(const e of t){const t=B(e);let s=!1;for(const[,e]of z(t))if(e===n){s=!0;break}if(!s)continue e}s[e]=n}return s}const se=e=>{if(!e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return t===Array.prototype||t===Object.prototype};function re(e,t=0){let s=0;if(null==e)return 0;if("object"!=typeof e)return 1;const r=Object.getPrototypeOf(e);if(r!==Array.prototype&&r!==Object.prototype)return 1;const n="COUNT_RECURSIVE"===t||1===t;if(Array.isArray(e)){for(const t of Object.keys(e)){s++;const r=e[Number(t)];n&&se(r)&&(s+=re(r,1))}return s}for(const t of Object.values(e))s++,n&&se(t)&&(s+=re(t,1));return s}function ne(...e){let t,s="",r="",n="";if(1===e.length){const[s]=e;t=s}else{const[s,r]=e;n=String(s??""),t=r}if("object"==typeof t&&null!==t){if(Array.isArray(t))return t.join(n);for(const e in t)s+=r+t[e],r=n;return s}return String(t)}const ie=new Y("implode",function(e,t){return`__runtime.implode(${e}, ${t})`},function(e,t,s){return ne(t,s)}),ae=new Y("count",function(e,t){let s="";return t&&(s=`, ${t}`),`__runtime.count(${e}${s})`},function(e,t,s){return re(t,s)}),oe=new Y("array_intersect",function(e,...t){let s="";return t.length>0&&(s=", "+t.join(", ")),`__runtime.array_intersect(${e}${s})`},function(e){let t=[],s=!0;for(let e=1;e<arguments.length;e++)t.push(arguments[e]),Array.isArray(arguments[e])||(s=!1);let r=te.apply(null,t);return s?Object.values(r):r});function ue(e,t){let s,r=new Date;const n=["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur","January","February","March","April","May","June","July","August","September","October","November","December"],i=/\\?(.?)/gi,a=function(e,t){return r=e,Object.hasOwn(s,r)?String(s[e]()):t;var r},o=function(e,t){let s=String(e);for(;s.length<t;)s="0"+s;return s};s={d:function(){return o(s.j(),2)},D:function(){return String(s.l()).slice(0,3)},j:function(){return r.getDate()},l:function(){return(n[Number(s.w())]??"")+"day"},N:function(){return Number(s.w())||7},S:function(){const e=Number(s.j());let t=e%10;return t<=3&&1===Number.parseInt(String(e%100/10),10)&&(t=0),["st","nd","rd"][t-1]||"th"},w:function(){return r.getDay()},z:function(){const e=new Date(Number(s.Y()),Number(s.n())-1,Number(s.j())),t=new Date(Number(s.Y()),0,1);return Math.round((e.getTime()-t.getTime())/864e5)},W:function(){const e=new Date(Number(s.Y()),Number(s.n())-1,Number(s.j())-Number(s.N())+3),t=new Date(e.getFullYear(),0,4);return o(1+Math.round((e.getTime()-t.getTime())/864e5/7),2)},F:function(){return n[6+Number(s.n())]??""},m:function(){return o(s.n(),2)},M:function(){return String(s.F()).slice(0,3)},n:function(){return r.getMonth()+1},t:function(){return new Date(Number(s.Y()),Number(s.n()),0).getDate()},L:function(){const e=Number(s.Y());return e%4==0&&e%100!=0||e%400==0?1:0},o:function(){const e=Number(s.n()),t=Number(s.W());return Number(s.Y())+(12===e&&t<9?1:1===e&&t>9?-1:0)},Y:function(){return r.getFullYear()},y:function(){return String(s.Y()).slice(-2)},a:function(){return r.getHours()>11?"pm":"am"},A:function(){return String(s.a()).toUpperCase()},B:function(){const e=3600*r.getUTCHours(),t=60*r.getUTCMinutes(),s=r.getUTCSeconds();return o(Math.floor((e+t+s+3600)/86.4)%1e3,3)},g:function(){return Number(s.G())%12||12},G:function(){return r.getHours()},h:function(){return o(s.g(),2)},H:function(){return o(s.G(),2)},i:function(){return o(r.getMinutes(),2)},s:function(){return o(r.getSeconds(),2)},u:function(){return o(1e3*r.getMilliseconds(),6)},e:function(){throw new Error("Not supported (see source code of date() for timezone on how to add support)")},I:function(){const e=new Date(Number(s.Y()),0),t=Date.UTC(Number(s.Y()),0),r=new Date(Number(s.Y()),6),n=Date.UTC(Number(s.Y()),6);return e.getTime()-t!==r.getTime()-n?1:0},O:function(){const e=r.getTimezoneOffset(),t=Math.abs(e);return(e>0?"-":"+")+o(100*Math.floor(t/60)+t%60,4)},P:function(){const e=String(s.O());return e.slice(0,3)+":"+e.slice(3,5)},T:function(){return"UTC"},Z:function(){return 60*-r.getTimezoneOffset()},c:function(){return"Y-m-d\\TH:i:sP".replace(i,a)},r:function(){return"D, d M Y H:i:s O".replace(i,a)},U:function(){return r.getTime()/1e3|0}};return u=e,r=void 0===(h=t)?new Date:h instanceof Date?new Date(h):new Date(1e3*Number(h)),u.replace(i,a);var u,h}const he="[ \\t]+",ce="[ \\t]*",le="(?:([ap])\\.?m\\.?([\\t ]|$))",de="(2[0-4]|[01]?[0-9])",fe="([01][0-9]|2[0-4])",pe="(0?[1-9]|1[0-2])",me="([0-5]?[0-9])",ge="([0-5][0-9])",ye="(60|[0-5]?[0-9])",we="(60|[0-5][0-9])",be="(?:\\.([0-9]+))",xe="sunday|monday|tuesday|wednesday|thursday|friday|saturday|sun|mon|tue|wed|thu|fri|sat|weekdays?",ve="next|last|previous|this",ke="(?:second|sec|minute|min|hour|day|fortnight|forthnight|month|year)s?|weeks|"+xe,Ne="([0-9]{1,4})",Te="([0-9]{4})",Ee="(1[0-2]|0?[0-9])",_e="(0[0-9]|1[0-2])",Ae="(?:(3[01]|[0-2]?[0-9])(?:st|nd|rd|th)?)",Se="(0[0-9]|[1-2][0-9]|3[01])",Oe="january|february|march|april|may|june|july|august|september|october|november|december",Ce="jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec",$e="("+Oe+"|"+Ce+"|i[vx]|vi{0,3}|xi{0,2}|i{1,3})",Pe="((?:GMT)?([+-])"+de+":?"+me+"?)",Re=$e+"[ .\\t-]*"+Ae+"[,.stndrh\\t ]*";function Ue(e,t){const s=t?.toLowerCase();switch(s){case"a":e+=12===e?-12:0;break;case"p":e+=12!==e?12:0}return e}function je(e){let t=+e;return e.length<4&&t<100&&(t+=t<70?2e3:1900),t}function Me(e){return{jan:0,january:0,i:0,feb:1,february:1,ii:1,mar:2,march:2,iii:2,apr:3,april:3,iv:3,may:4,v:4,jun:5,june:5,vi:5,jul:6,july:6,vii:6,aug:7,august:7,viii:7,sep:8,sept:8,september:8,ix:8,oct:9,october:9,x:9,nov:10,november:10,xi:10,