expression-language
Version:
Javascript implementation of symfony/expression-language
1 lines • 65.6 kB
JavaScript
!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||"default");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,i=[];for(s=0;s<=t.length;s++)i[s]=[s];for(r=0;r<=e.length;r++)void 0===i[0]&&(i[0]=[]),i[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)?i[s][r]=i[s-1][r-1]:i[s][r]=Math.min(i[s-1][r-1]+1,Math.min(i[s][r-1]+1,i[s-1][r]+1));return void 0===i[t.length]&&(i[t.length]=[]),i[t.length][e.length]};class r extends Error{constructor(e,t,s,r,i){super(e),this.name="SyntaxError",this.cursor=t,this.expression=s,this.subject=r,this.proposals=i}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 i=s(this.subject,e);i<t&&(r=e,t=i)}null!==r&&t<3&&(e+=` Did you mean "${r}"?`)}return e}}class i{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 i=this.current;if(!i.test(e,t)){let n="";s&&(n=s+". ");let a="";throw t&&(a=` with value "${t}"`),n+=`Unexpected token "${i.type}" of value "${i.value}" ("${e}" expected${a})`,new r(n,i.cursor,this.expression)}this.next()}),t(this,"isEOF",()=>n.EOF_TYPE===this.current.type),t(this,"isEqualTo",e=>{if(null==e||!e instanceof i)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 i=r.diff(e.current);i.length>0&&t.push({index:s,diff:i}),e.position<e.tokens.length-1&&e.next()}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 n{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 n)&&(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 i=o(e.substr(t));if(null!==i){const e=i.length,r=i.replace(/_/g,"");i=-1===r.indexOf(".")&&-1===r.indexOf("e")&&-1===r.indexOf("E")?parseInt(r,10):parseFloat(r),s.push(new n(n.NUMBER_TYPE,i,t+1)),t+=e}else if("([{".indexOf(e[t])>=0)a.push([e[t],t]),s.push(new n(n.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[i,o]=a.pop(),u=i.replace("(",")").replace("{","}").replace("[","]");if(e[t]!==u)throw new r(`Unclosed "${i}"`,o,e);s.push(new n(n.PUNCTUATION_TYPE,e[t],t+1)),++t}else{let i=c(e.substr(t));if(null!==i)s.push(new n(n.STRING_TYPE,i.captured,t+1)),t+=i.length;else if("\\\\"===e.substr(t,2))s.push(new n(n.PUNCTUATION_TYPE,"\\",t+1)),t+=2;else{const i=s.length>0?s[s.length-1]:null;if(i&&i.type===n.PUNCTUATION_TYPE&&("."===i.value||"?."===i.value)){let i=p(e.substr(t));if(i)s.push(new n(n.NAME_TYPE,i,t+1)),t+=i.length;else{let i=f(e.substr(t));if(i)s.push(new n(n.OPERATOR_TYPE,i,t+1)),t+=i.length;else if("?."===e.substr(t,2)||"??"===e.substr(t,2))s.push(new n(n.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 n(n.PUNCTUATION_TYPE,e[t],t+1)),++t}}}else{let i=f(e.substr(t));if(i)s.push(new n(n.OPERATOR_TYPE,i,t+1)),t+=i.length;else if("?."===e.substr(t,2)||"??"===e.substr(t,2))s.push(new n(n.PUNCTUATION_TYPE,e.substr(t,2),t+1)),t+=2;else if(".,?:".indexOf(e[t])>=0)s.push(new n(n.PUNCTUATION_TYPE,e[t],t+1)),++t;else{let i=p(e.substr(t));if(!i)throw new r(`Unexpected character "${e[t]}"`,t,e);s.push(new n(n.NAME_TYPE,i,t+1)),t+=i.length}}}}}if(s.push(new n(n.EOF_TYPE,null,t+1)),a.length>0){let[t,s]=a.pop();throw new r(`Unclosed "${t}"`,s,e)}return new i(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(n,"EOF_TYPE","end of expression"),t(n,"NAME_TYPE","name"),t(n,"NUMBER_TYPE","number"),t(n,"STRING_TYPE","string"),t(n,"OPERATOR_TYPE","operator"),t(n,"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=[],i=0,n=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(i=0;i<t.length;i++)if(a=t.charAt(i),o=t.charAt(i+1),"\\"===a&&o&&/\d/.test(o)){if(p=i+(f=(u=t.slice(i+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],i+=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(n=l;n<=d;n++)r.push(String.fromCharCode(n));else r.push(".",u,h);i+=h.length+2}else c=String.fromCharCode(parseInt(u,8)),r.push(c);i+=f}else if(o+t.charAt(i+2)===".."){if(l=(u=a).charCodeAt(0),/\\\d/.test(t.charAt(i+3)+t.charAt(i+4)))h=t.slice(i+4).match(/^\d+/)[0],i+=1;else{if(!t.charAt(i+3))throw new Error("Range with no end point");h=t.charAt(i+3)}if((d=h.charCodeAt(0))>l)for(n=l;n<=d;n++)r.push(String.fromCharCode(n));else r.push(".",u,h);i+=h.length+2}else r.push(a);for(i=0;i<e.length;i++)if(a=e.charAt(i),-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;"matches"!==t?"contains"!==t?"starts with"!==t?"ends with"!==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("(").compile(this.nodes.left).raw(".toString().toLowerCase().endsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())"):e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().startsWith(").compile(this.nodes.right).raw(".toString().toLowerCase())"):e.raw("(").compile(this.nodes.left).raw(".toString().toLowerCase().includes(").compile(this.nodes.right).raw(".toString().toLowerCase())"):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 i=this.nodes.right.evaluate(e,t);switch(s){case"not in":return-1===i.indexOf(r);case"in":return i.indexOf(r)>=0;case"..":return function(e,t){let s=[];for(let r=e;r<=t;r++)s.push(r);return s}(r,i);case"**":return Math.pow(r,i)}}let i=null;switch(s){case"or":case"||":return r||(i=this.nodes.right.evaluate(e,t)),r||i;case"and":case"&&":return r&&(i=this.nodes.right.evaluate(e,t)),r&&i;case"xor":return i=this.nodes.right.evaluate(e,t),i&&!r||r&&!i;case"<<":return i=this.nodes.right.evaluate(e,t),r<<i;case">>":return i=this.nodes.right.evaluate(e,t),r>>i}switch(i=this.nodes.right.evaluate(e,t),s){case"|":return r|i;case"^":return r^i;case"&":return r&i;case"==":return r==i;case"===":return r===i;case"!=":return r!=i;case"!==":return r!==i;case"<":return r<i;case">":return r>i;case">=":return r>=i;case"<=":return r<=i;case"not in":return-1===i.indexOf(r);case"in":return i.indexOf(r)>=0;case"+":return r+i;case"-":return r-i;case"~":return r.toString()+i.toString();case"*":return r*i;case"/":return r/i;case"%":return r%i;case"matches":if(null==r)return!1;let e=i.match(w.regex_expression);return new RegExp(e[1],e[2]).test(r);case"contains":return r.toString().toLowerCase().includes(i.toString().toLowerCase());case"starts with":return r.toString().toLowerCase().startsWith(i.toString().toLowerCase());case"ends with":return r.toString().toLowerCase().endsWith(i.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 T 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 E 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=[],i=Object.values(this.nodes);for(e=0,t=i.length;e<t;e+=2)s=i.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 N extends E{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 A extends y{constructor(e,s,r,i){super({node:e,attribute:s,fnArguments:r},{type:i,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 A.PROPERTY_CALL:e.compile(this.nodes.node).raw(t?"?.":".").raw(this.nodes.attribute.attributes.value);break;case A.METHOD_CALL:e.compile(this.nodes.node).raw(t?"?.":".").raw(this.nodes.attribute.attributes.value).raw("(").compile(this.nodes.fnArguments).raw(")");break;case A.ARRAY_CALL:e.compile(this.nodes.node).raw("[").compile(this.nodes.attribute).raw("]")}}),t(this,"evaluate",(e,t)=>{switch(this.attributes.type){case A.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;if("object"!=typeof s)throw new Error(`Unable to get property "${r}" on a non-object: `+typeof s);let r=this.nodes.attribute.attributes.value;return this.attributes.is_null_coalesce?s[r]??null:s[r];case A.METHOD_CALL:let i=this.nodes.node.evaluate(e,t);if(null===i&&this.nodes.attribute.isNullSafe)return this.attributes.is_short_circuited=!0,null;if(null===i&&this.isShortCircuited())return null;let n=this.nodes.attribute.attributes.value;if("object"!=typeof i)throw new Error(`Unable to call method "${n}" on a non-object: `+typeof i);if(void 0===i[n])throw new Error(`Method "${n}" is undefined on object.`);if("function"!=typeof i[n])throw new Error(`Method "${n}" is not a function on object.`);let a=this.nodes.fnArguments.evaluate(e,t);return i[n].apply(null,a);case A.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 A.PROPERTY_CALL:return[this.nodes.node,e?"?.":".",this.nodes.attribute];case A.METHOD_CALL:return[this.nodes.node,e?"?.":".",this.nodes.attribute,"(",this.nodes.fnArguments,")"];case A.ARRAY_CALL:return[this.nodes.node,"[",this.nodes.attribute,"]"]}}),this.name="GetAttrNode"}isShortCircuited(){return this.attributes.is_short_circuited||this.nodes.node instanceof A&&this.nodes.node.isShortCircuited()}}t(A,"PROPERTY_CALL",1),t(A,"METHOD_CALL",2),t(A,"ARRAY_CALL",3);class S 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 A&&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 A)){e.attributes.is_null_coalesce=!0;for(let t of Object.values(e.nodes))this._addNullCoalesceAttributeToGetAttrNodes(t)}}),this.name="NullCoalesceNode"}}class O 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 _{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 i=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 i}),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("Way to many executions on '"+s.toString()+"' of '"+this.tokenStream.toString()+"'");for(;s.test(n.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(n.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(n.PUNCTUATION_TYPE,"(")){this.tokenStream.next();let e=this.parseExpression();return this.tokenStream.expect(n.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(n.PUNCTUATION_TYPE,"[","An array element was expected");let e=new E,t=!0;for(;!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"]")&&(t||(this.tokenStream.expect(n.PUNCTUATION_TYPE,",","An array element must be followed by a comma"),!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"]")));)t=!1,e.addElement(this.parseExpression());return this.tokenStream.expect(n.PUNCTUATION_TYPE,"]","An opened array is not properly closed"),e}),t(this,"parseHashExpression",()=>{this.tokenStream.expect(n.PUNCTUATION_TYPE,"{","A hash element was expected");let e=new E,t=!0;for(;!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"}")&&(t||(this.tokenStream.expect(n.PUNCTUATION_TYPE,",","A hash value must be followed by a comma"),!this.tokenStream.current.test(n.PUNCTUATION_TYPE,"}")));){t=!1;let s=null;if(this.tokenStream.current.test(n.STRING_TYPE)||this.tokenStream.current.test(n.NAME_TYPE)||this.tokenStream.current.test(n.NUMBER_TYPE))s=new x(this.tokenStream.current.value),this.tokenStream.next();else{if(!this.tokenStream.current.test(n.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(n.PUNCTUATION_TYPE,":","A hash key must be followed by a colon (:)");let i=this.parseExpression();e.addElement(i,s)}return this.tokenStream.expect(n.PUNCTUATION_TYPE,"}","An opened hash is not properly closed"),e}),t(this,"parsePostfixExpression",e=>{let t=this.tokenStream.current;for(;n.PUNCTUATION_TYPE===t.type;){if("."===t.value||"?."===t.value){const s="?."===t.value;if(this.tokenStream.next(),t=this.tokenStream.current,this.tokenStream.next(),n.NAME_TYPE!==t.type&&(n.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 i=new x(t.value,!0,s),a=new N,o=null;if(this.tokenStream.current.test(n.PUNCTUATION_TYPE,"(")){o=A.METHOD_CALL;for(let e of Object.values(this.parseArguments().nodes))a.addElement(e)}else o=A.PROPERTY_CALL;e=new A(e,i,a,o)}else{if("["!==t.value)break;{this.tokenStream.next();let t=this.parseExpression();this.tokenStream.expect(n.PUNCTUATION_TYPE,"]"),e=new A(e,t,new N,A.ARRAY_CALL)}}t=this.tokenStream.current}return e}),t(this,"parseArguments",()=>{let e=[];for(this.tokenStream.expect(n.PUNCTUATION_TYPE,"(","A list of arguments must begin with an opening parenthesis");!this.tokenStream.current.test(n.PUNCTUATION_TYPE,")");)0!==e.length&&this.tokenStream.expect(n.PUNCTUATION_TYPE,",","Arguments must be separated by a comma"),e.push(this.parseExpression());return this.tokenStream.expect(n.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(n.PUNCTUATION_TYPE,"??");){this.tokenStream.next();let t=this.parseExpression();e=new S(e,t)}for(;this.tokenStream.current.test(n.PUNCTUATION_TYPE,"?");){let t,s;this.tokenStream.next(),this.tokenStream.current.test(n.PUNCTUATION_TYPE,":")?(this.tokenStream.next(),t=e,s=this.parseExpression()):(t=this.parseExpression(),this.tokenStream.current.test(n.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 n.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(n.PUNCTUATION_TYPE,"??"))return new O(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 T(s)}}break;case n.NUMBER_TYPE:case n.STRING_TYPE:return this.tokenStream.next(),new x(e.value);default:if(e.test(n.PUNCTUATION_TYPE,"["))t=this.parseArrayExpression();else{if(!e.test(n.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("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 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 this.string(e);return this}),this.source="",this.functions=e}}class P{constructor(e){this.expression=e}toString(){return this.expression}}class R extends P{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 T(e.attributes?.name);case"NullCoalescedNameNode":return new O(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 S(s(e.nodes?.expr1),s(e.nodes?.expr2));case"ArgumentsNode":{const t=new N;"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 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"FunctionNode":{const t=s(e.nodes?.arguments);return new k(e.attributes?.name,t)}case"GetAttrNode":{const t=new A(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,i=(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 R(r,i)}}var U;class j{constructor(e=0){t(this,"createCacheItem",(e,t,s)=>{let r=new I;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 i=this.getItem(e);if(!i.isHit){let e=!0;this.save(i.set(t(i,e)))}return i.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]||I.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 I)&&(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)||(I.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]||I.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 i of e){let e=null,n=!!this.expiries[i];n||!(this.expiries[i]>t)&&this.deleteItem(i)?e=this.values[i]:this.values[i]=null,r[i]=s(i,e,n)}return r}),this.defaultLifetime=e,this.values={},this.expiries={}}}class I{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}}U=I,t(I,"METADATA_EXPIRY_OFFSET",1527506807),t(I,"RESERVED_CHARACTERS",["{","}","(",")","/","\\","@",":"]),t(I,"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 U.RESERVED_CHARACTERS)if(e.indexOf(t)>=0)throw new Error(`Cache key "${e}" contains reserved character "${t}".`);return e});class Y extends Error{constructor(e){super(e),this.name="LogicException"}toString(){return`${this.name}: ${this.message}`}}class L{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 i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};for(const e of r){if(null==i)break;i=i[e]}if("function"!=typeof i)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)=>i(...t))}}class ${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 R)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 i=this.cache.getItem(this.fixedEncodeURIComponent(e+"//"+r.join("|"))),n=i.get();if(null===n){let r=this.getParser().parse(this.getLexer().tokenize(e),t,s);n=new R(e,r),i.set(n),this.cache.save(i)}return n}),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 R||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 Y("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 _(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 j,this._registerBuiltinFunctions();for(let e of s)this.registerProvider(e)}_registerBuiltinFunctions(){const e=L.fromJavascript("Math.min","min"),t=L.fromJavascript("Math.max","max");this.addFunction(e),this.addFunction(t),this.addFunction(new L("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 L("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 D{getFunctions(){throw new Error("getFunctions must be implemented by "+this.name)}}const M=new L("isset",function(e){return`isset(${e})`},function(e,t){let s="",r=[],i="",n="";for(let e=0;e<t.length;e++){let a=t[e];if("]"!==a)if("["!==a){if("object"===i&&(!/[A-z0-9_]/.test(a)||e===t.length-1)){let s=!1;if(e===t.length-1&&(n+=a,s=!0),i="",r.push({type:"object",attribute:n}),n="",s)continue}"."!==a?i?n+=a:s+=a:(i="object",n="")}else i="array",n="";else i="",r.push({type:"array",index:n.replace(/"/g,"").replace(/'/g,"")}),n=""}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]});var F,z,H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function B(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}function G(){return z?F:(z=1,F=function(e){var t="undefined"!=typeof window?window:H;t.$locutus=t.$locutus||{};var s=t.$locutus;return s.php=s.php||{},s.php.ini=s.php.ini||{},s.php.ini[e]&&void 0!==s.php.ini[e].local_value?null===s.php.ini[e].local_value?"":s.php.ini[e].local_value:""})}var V,q,K=function(e){var t=e+"";if("off"===((void 0!==B?G()("unicode.semantics"):void 0)||"off"))return t.length;var s=0,r=0,i=function(e,t){var s=e.charCodeAt(t),r="",i="";if(s>=55296&&s<=56319){if(e.length<=t+1)throw new Error("High surrogate without following low surrogate");if((r=e.charCodeAt(t+1))<56320||r>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");if((i=e.charCodeAt(t-1))<55296||i>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!==i(t,s)&&r++;return r};var J=function(e,t,s){var r=function(){if(q)return V;q=1;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};return V=function(t){switch(void 0===t?"undefined":e(t)){case"boolean":return t?"1":"";case"string":return t;case"number":return isNaN(t)?"NAN":isFinite(t)?t+"":(t<0?"-":"")+"INF";case"undefined":return"";case"object":return Array.isArray(t)?"Array":null!==t?"Object":"";default:throw new Error("Unsupported value type")}}}();e=r(e);var i="on"===G()("unicode.semantics");i&&(e=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[\s\S]/g)||[]);var n=e.length,a=n;return t<0&&(t+=a),void 0!==s&&(a=s<0?s+a:s+t),!(t>n||t<0||t>a)&&(i?e.slice(t,a).join(""):e.slice(t,a))};var Z=function(e){var t={},s=arguments.length,r=s-1,i="",n={},a=0,o="";e:for(i in e)t:for(a=1;a<s;a++){for(o in n=arguments[a])if(n[o]===e[i]){a===r&&(t[i]=e[i]);continue t}continue e}return t},X=function e(t,s){var r=void 0,i=0;if(null==t)return 0;if(t.constructor!==Array&&t.constructor!==Object)return 1;for(r in"COUNT_RECURSIVE"===s&&(s=1),1!==s&&(s=0),t)t.hasOwnProperty(r)&&(i++,1!==s||!t[r]||t[r].constructor!==Array&&t[r].constructor!==Object||(i+=e(t[r],1)));return i},Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};const ee=new L("implode",function(e,t){return`implode(${e}, ${t})`},function(e,t,s){return function(e,t){var s="",r="",i="";if(1===arguments.length&&(t=e,e=""),"object"===(void 0===t?"undefined":Q(t))){if("[object Array]"===Object.prototype.toString.call(t))return t.join(e);for(s in t)r+=i+t[s],i=e;return r}return t}(t,s)}),te=new L("count",function(e,t){let s="";return t&&(s=`, ${t}`),`count(${e}${s})`},function(e,t,s){return X(t,s)}),se=new L("array_intersect",function(e,...t){let s="";return t.length>0&&(s=", "+t.join(", ")),`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=Z.apply(null,t);return s?Object.values(r):r});var re="[ \\t]+",ie="[ \\t]*",ne="(?:([ap])\\.?m\\.?([\\t ]|$))",ae="(2[0-4]|[01]?[0-9])",oe="([01][0-9]|2[0-4])",ue="(0?[1-9]|1[0-2])",he="([0-5]?[0-9])",ce="([0-5][0-9])",le="(60|[0-5]?[0-9])",de="(60|[0-5][0-9])",fe="(?:\\.([0-9]+))",pe="sunday|monday|tuesday|wednesday|thursday|friday|saturday",me="sun|mon|tue|wed|thu|fri|sat",ge=pe+"|"+me+"|weekdays?",ye="first|second|third|fourth|fifth|sixth|seventh|eighth?|ninth|tenth|eleventh|twelfth",we="next|last|previous|this",be="(?:second|sec|minute|min|hour|day|fortnight|forthnight|month|year)s?|weeks|"+ge,xe="([0-9]{1,4})",ve="([0-9]{4})",ke="(1[0-2]|0?[0-9])",Te="(0[0-9]|1[0-2])",Ee="(?:(3[01]|[0-2]?[0-9])(?:st|nd|rd|th)?)",Ne="(0[0-9]|[1-2][0-9]|3[01])",Ae="january|february|march|april|may|june|july|august|september|october|november|december",Se="jan|feb|mar|apr|may|jun|jul|aug|sept?|oct|nov|dec",Oe="("+Ae+"|"+Se+"|i[vx]|vi{0,3}|xi{0,2}|i{1,3})",_e="((?:GMT)?([+-])"+ae+":?"+he+"?)",Ce=Oe+"[ .\\t-]*"+Ee+"[,.stndrh\\t ]*";function Pe(e,t){switch(t=t&&t.toLowerCase()){case"a":e+=12===e?-12:0;break;case"p":e+=12!==e?12:0}return e}function Re(e){var t=+e;return e.length<4&&t<100&&(t+=t<70?2e3:1900),t}function Ue(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,dec:11,december:11,xii:11}[e.toLowerCase()]}function je(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return{mon:1,monday:1,tue:2,tuesday:2,wed:3,wednesday:3,thu:4,thursday:4,fri:5,friday:5,sat:6,saturday:6,sun:0,sunday:0}[e.toLowerCase()]||t}function Ie(e,t){if(!(e=e&&e.match(/(?:GMT)?([+-])(\d+)(:?)(\d{0,2})/i)))return t;var s="-"===e[1]?-1:1,r=+e[2],i=+e[4];return e[4]||e[3]||(i=Math.floor(r%100),r=Math.floor(r/100)),s*(60*r+i)*60}var Ye={acdt:37800,acst:34200,addt:-7200,adt:-10800,aedt:39600,aest:36e3,ahdt:-32400,ahst:-36e3,akdt:-28800,akst:-32400,amt:-13840,apt:-10800,ast:-14400,awdt:32400,awst:28800,awt:-10800,bdst:7200,bdt:-36e3,bmt:-14309,bst:3600,cast:34200,cat:7200,cddt:-14400,cdt:-18e3,cemt:10800,cest:7200,cet:3600,cmt:-15408,cpt:-18e3,cst:-21600,cwt:-18e3,chst:36e3,dmt:-1521,eat:10800,eddt:-10800,edt:-14400,eest:10800,eet:7200,emt:-26248,ept:-14400,est:-18e3,ewt:-14400,ffmt:-14660,fmt:-4056,gdt:39600,gmt:0,gst:36e3,hdt:-34200,hkst:32400,hkt:28800,hmt:-19776,hpt:-34200,hst:-36e3,hwt:-34200,iddt:14400,idt:10800,imt:25025,ist:7200,jdt:36e3,jmt:8440,jst:32400,kdt:36e3,kmt:5736,kst:30600,lst:9394,mddt:-18e3,mdst:16279,mdt:-21600,mest:7200,met:3600,mmt:9017,mpt:-21600,msd:14400,msk:10800,mst:-25200,mwt:-21600,nddt:-5400,ndt:-9052,npt:-9e3,nst:-12600,nwt:-9e3,nzdt:46800,nzmt:41400,nzst:43200,pddt:-21600,pdt:-25200,pkst:21600,pkt:18e3,plmt:25590,pmt:-13236,ppmt:-17340,ppt:-25200,pst:-28800,pwt:-25200,qmt:-18840,rmt:5794,sast:7200,sdmt:-16800,sjmt:-20173,smt:-13884,sst:-39600,tbmt:10751,tmt:12344,uct:0,utc:0,wast:7200,wat:3600,wemt:7200,west:3600,wet:0,wib:25200,wita:28800,wit:32400,wmt:5040,yddt:-25200,ydt:-28800,ypt:-28800,yst:-32400,ywt:-28800,a:3600,b:7200,c:10800,d:14400,e:18e3,f:21600,g:25200,h:28800,i:32400,k:36e3,l:39600,m:43200,n:-3600,o:-7200,p:-10800,q:-14400,r:-18e3,s:-21600,t:-25200,u:-28800,v:-32400,w:-36e3,x:-39600,y:-43200,z:0},Le={yesterday:{regex:/^yesterday/i,name:"yesterday",callback:function(){return this.rd-=1,this.resetTime()}},now:{regex:/^now/i,name:"now"},noon:{regex:/^noon/i,name:"noon",callback:function(){return this.resetTime()&&this.time(12,0,0,0)}},midnightOrToday:{regex:/^(midnight|today)/i,name:"midnight | today",callback:function(){return this.resetTime()}},tomorrow:{regex:/^tomorrow/i,name:"tomorrow",callback:function(){return this.rd+=1,this.resetTime()}},timestamp:{regex:/^@(-?\d+)/i,name:"timestamp",callback:function(e,t){return this.rs+=+t,this.y=1970,this.m=0,this.d=1,this.dates=0,this.resetTime()&&this.zone(0)}},firstOrLastDay:{regex:/^(first|last) day of/i,name:"firstdayof | lastdayof",callback:function(e,t){"first"===t.toLowerCase()?this.firstOrLastDayOfMonth=1:this.firstOrLastDayOfMonth=-1}},backOrFrontOf:{regex:RegExp("^(back|front) of "+ae+ie+ne+"?","i"),name:"backof | frontof",callback:function(e,t,s,r){var i=+s,n=15;return"back"===t.toLowerCase()||(i-=1,n=45),i=Pe(i,r),this.resetTime()&&this.time(i,n,0,0)}},weekdayOf:{regex:RegExp("^("+ye+"|"+we+")"+re+"("+pe+"|"+me+")"+re+"of","i"),name:"weekdayof"},mssqltime:{regex:RegExp("^"+ue+":"+ce+":"+de+"[:.]([0-9]+)"+ne,"i"),name:"mssqltime",callback:function(e,t,s,r,i,n){return this.time(Pe(+t,n),+s,+r,+i.substr(0,3))}},oracledate:{regex:/^(\d{2})-([A-Z]{3})-(\d{2})$/i,name:"d-M-y",callback:function(e,t,s,r){var i={JAN:0,FEB:1,MAR:2,APR:3,MAY:4,JUN:5,JUL:6,AUG:7,SEP:8,OCT:9,NOV:10,DEC:11}[s.toUpperCase()];return this.ymd(2e3+parseInt(r,10),i,parseInt(t,10))}},timeLong12:{regex:RegExp("^"+ue+"[:.]"+he+"[:.]"+de+ie+ne,"i"),name:"timelong12",callback:function(e,t,s,r,i){return this.time(Pe(+t,i),+s,+r,0)}},timeShort12:{regex:RegExp("^"+ue+"[:.]"+ce+ie+ne,"i"),name:"timeshort12",callback:function(e,t,s,r){return this.time(Pe(+t,r),+s,0,0)}},timeTiny12:{regex:RegExp("^"+ue+ie+ne,"i"),name:"timetiny12",callback:function(e,t,s){return this.time(Pe(+t,s),0,0,0)}},soap:{regex:RegExp("^"+ve+"-"+Te+"-"+Ne+"T"+oe+":"+ce+":"+de+fe+_e+"?","i"),name:"soap",callback:function(e,t,s,r,i,n,a,o,u){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,+o.substr(0,3))&&this.zone(Ie(u))}},wddx:{regex:RegExp("^"+ve+"-"+ke+"-"+Ee+"T"+ae+":"+he+":"+le),name:"wddx",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},exif:{regex:RegExp("^"+ve+":"+Te+":"+Ne+" "+oe+":"+ce+":"+de,"i"),name:"exif",callback:function(e,t,s,r,i,n,a){return this.ymd(+t,s-1,+r)&&this.time(+i,+n,+a,0)}},xmlRpc:{regex:RegExp("^"+ve+Te+Ne+"T"+ae+":"