(function(x,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(x=typeof globalThis<"u"?globalThis:x||self,D(x.TheFunFramework={}))})(this,function(x){"use strict";function D(i){let e=i;const t=[];return{get value(){return e},set value(r){e=r,t.forEach(n=>n())},listeners:t}}class ue{add(e,t,r){if(typeof arguments[0]!="string")for(let n in arguments[0])this.add(n,arguments[0][n],arguments[1]);else(Array.isArray(e)?e:[e]).forEach(function(n){this[n]=this[n]||[],t&&this[n][r?"unshift":"push"](t)},this)}run(e,t){this[e]=this[e]||[],this[e].forEach(function(r){r.call(t&&t.context?t.context:t,t)})}}class fe{constructor(e){this.jsep=e,this.registered={}}register(...e){e.forEach(t=>{if(typeof t!="object"||!t.name||!t.init)throw new Error("Invalid JSEP plugin format");this.registered[t.name]||(t.init(this.jsep),this.registered[t.name]=t)})}}class s{static get version(){return"1.3.8"}static toString(){return"JavaScript Expression Parser (JSEP) v"+s.version}static addUnaryOp(e){return s.max_unop_len=Math.max(e.length,s.max_unop_len),s.unary_ops[e]=1,s}static addBinaryOp(e,t,r){return s.max_binop_len=Math.max(e.length,s.max_binop_len),s.binary_ops[e]=t,r?s.right_associative.add(e):s.right_associative.delete(e),s}static addIdentifierChar(e){return s.additional_identifier_chars.add(e),s}static addLiteral(e,t){return s.literals[e]=t,s}static removeUnaryOp(e){return delete s.unary_ops[e],e.length===s.max_unop_len&&(s.max_unop_len=s.getMaxKeyLen(s.unary_ops)),s}static removeAllUnaryOps(){return s.unary_ops={},s.max_unop_len=0,s}static removeIdentifierChar(e){return s.additional_identifier_chars.delete(e),s}static removeBinaryOp(e){return delete s.binary_ops[e],e.length===s.max_binop_len&&(s.max_binop_len=s.getMaxKeyLen(s.binary_ops)),s.right_associative.delete(e),s}static removeAllBinaryOps(){return s.binary_ops={},s.max_binop_len=0,s}static removeLiteral(e){return delete s.literals[e],s}static removeAllLiterals(){return s.literals={},s}get char(){return this.expr.charAt(this.index)}get code(){return this.expr.charCodeAt(this.index)}constructor(e){this.expr=e,this.index=0}static parse(e){return new s(e).parse()}static getMaxKeyLen(e){return Math.max(0,...Object.keys(e).map(t=>t.length))}static isDecimalDigit(e){return e>=48&&e<=57}static binaryPrecedence(e){return s.binary_ops[e]||0}static isIdentifierStart(e){return e>=65&&e<=90||e>=97&&e<=122||e>=128&&!s.binary_ops[String.fromCharCode(e)]||s.additional_identifier_chars.has(String.fromCharCode(e))}static isIdentifierPart(e){return s.isIdentifierStart(e)||s.isDecimalDigit(e)}throwError(e){const t=new Error(e+" at character "+this.index);throw t.index=this.index,t.description=e,t}runHook(e,t){if(s.hooks[e]){const r={context:this,node:t};return s.hooks.run(e,r),r.node}return t}searchHook(e){if(s.hooks[e]){const t={context:this};return s.hooks[e].find(function(r){return r.call(t.context,t),t.node}),t.node}}gobbleSpaces(){let e=this.code;for(;e===s.SPACE_CODE||e===s.TAB_CODE||e===s.LF_CODE||e===s.CR_CODE;)e=this.expr.charCodeAt(++this.index);this.runHook("gobble-spaces")}parse(){this.runHook("before-all");const e=this.gobbleExpressions(),t=e.length===1?e[0]:{type:s.COMPOUND,body:e};return this.runHook("after-all",t)}gobbleExpressions(e){let t=[],r,n;for(;this.index0;){if(s.binary_ops.hasOwnProperty(e)&&(!s.isIdentifierStart(this.code)||this.index+e.lengtho.right_a&&g.right_a?r>g.prec:r<=g.prec;for(;n.length>2&&f(n[n.length-2]);)l=n.pop(),t=n.pop().value,a=n.pop(),e={type:s.BINARY_EXP,operator:t,left:a,right:l},n.push(e);e=this.gobbleToken(),e||this.throwError("Expected expression after "+c),n.push(o,e)}for(h=n.length-1,e=n[h];h>1;)e={type:s.BINARY_EXP,operator:n[h-1].value,left:n[h-2],right:e},h-=2;return e}gobbleToken(){let e,t,r,n;if(this.gobbleSpaces(),n=this.searchHook("gobble-token"),n)return this.runHook("after-token",n);if(e=this.code,s.isDecimalDigit(e)||e===s.PERIOD_CODE)return this.gobbleNumericLiteral();if(e===s.SQUOTE_CODE||e===s.DQUOTE_CODE)n=this.gobbleStringLiteral();else if(e===s.OBRACK_CODE)n=this.gobbleArray();else{for(t=this.expr.substr(this.index,s.max_unop_len),r=t.length;r>0;){if(s.unary_ops.hasOwnProperty(t)&&(!s.isIdentifierStart(this.code)||this.index+t.length=t.length&&this.throwError("Unexpected token "+String.fromCharCode(e));break}else if(o===s.COMMA_CODE){if(this.index++,n++,n!==t.length){if(e===s.CPAREN_CODE)this.throwError("Unexpected token ,");else if(e===s.CBRACK_CODE)for(let a=t.length;a":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},right_associative:new Set,additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"}),s.max_unop_len=s.getMaxKeyLen(s.unary_ops),s.max_binop_len=s.getMaxKeyLen(s.binary_ops);const C=i=>new s(i).parse();Object.getOwnPropertyNames(s).forEach(i=>{C[i]===void 0&&i!=="prototype"&&(C[i]=s[i])}),C.Jsep=s;const pe="ConditionalExpression";var Ee={name:"ternary",init(i){i.hooks.add("after-expression",function(t){if(t.node&&this.code===i.QUMARK_CODE){this.index++;const r=t.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===i.COLON_CODE){this.index++;const o=this.gobbleExpression();if(o||this.throwError("Expected expression"),t.node={type:pe,test:r,consequent:n,alternate:o},r.operator&&i.binary_ops[r.operator]<=.9){let a=r;for(;a.right.operator&&i.binary_ops[a.right.operator]<=.9;)a=a.right;t.node.test=a.right,a.right=t.node,t.node=r}}else this.throwError("Expected :")}})}};C.plugins.register(Ee);const B=43,A={name:"assignment",assignmentOperators:new Set(["=","*=","**=","/=","%=","+=","-=","<<=",">>=",">>>=","&=","^=","|="]),updateOperators:[B,45],assignmentPrecedence:.9,init(i){const e=[i.IDENTIFIER,i.MEMBER_EXP];A.assignmentOperators.forEach(r=>i.addBinaryOp(r,A.assignmentPrecedence,!0)),i.hooks.add("gobble-token",function(n){const o=this.code;A.updateOperators.some(a=>a===o&&a===this.expr.charCodeAt(this.index+1))&&(this.index+=2,n.node={type:"UpdateExpression",operator:o===B?"++":"--",argument:this.gobbleTokenProperty(this.gobbleIdentifier()),prefix:!0},(!n.node.argument||!e.includes(n.node.argument.type))&&this.throwError(`Unexpected ${n.node.operator}`))}),i.hooks.add("after-token",function(n){if(n.node){const o=this.code;A.updateOperators.some(a=>a===o&&a===this.expr.charCodeAt(this.index+1))&&(e.includes(n.node.type)||this.throwError(`Unexpected ${n.node.operator}`),this.index+=2,n.node={type:"UpdateExpression",operator:o===B?"++":"--",argument:n.node,prefix:!1})}}),i.hooks.add("after-expression",function(n){n.node&&t(n.node)});function t(r){A.assignmentOperators.has(r.operator)?(r.type="AssignmentExpression",t(r.left),t(r.right)):r.operator||Object.values(r).forEach(n=>{n&&typeof n=="object"&&t(n)})}}};class ${constructor(){this.config={}}unwrapMulti(e){e.maxSep=e.separators?typeof e.maxSep>"u"?1/0:e.maxSep:0}addExtra(e,t,r){return e.extra?typeof e.extra=="function"?e.extra(t,r):Object.assign(Object.assign({},e.extra),t):t}register(){return{}}pre(e){return null}post(e,t){return t}}class ge extends ${constructor(e,t=!1){super(),this.config=e,this.required=t;let r;for(const n in e)r=e[n],r.empty=r.close&&r.empty||!1,r.separators=r.close&&r.separators||"",this.unwrapMulti(r)}register(){return this.config}post(e,t){const r=t.range?t.range[0]:e.i;let n=e.gbOp(this.config);if(this.required&&!n)return e.err(`Expected operator (${Object.keys(this.config).join(",")})`);for(;n;){const o=this.config[n];if(o.ltypes&&o.ltypes.indexOf(t.type)<0)return e.err("Invalid left-hand side");const a=e.parseMulti(o,o.subRules||(o.rasoc?0:1));if(!a.length&&!o.empty)return e.err("Expression expected.");if(delete a.match,o.close&&!e.tyCh(o.close))return e.err("Closing character expected. Found");t=this.addExtra(o,{type:o.type,[o.left||"left"]:t,[o.right||"right"]:o.separators?a:a[0]},e),o.oper&&(t[o.oper]=n),e.config.range&&(t.range=[r,e.ch]),n=o.rasoc?"":e.gbOp(this.config)}return t}}const U="BinaryExpression",be="LogicalExpression",F="ArrayPattern",xe="Literal",me="Identifier",I="MemberExpression",ye="UpdateExpression",Q="UnaryExpression",Oe="RestElement",S="operator",q="prefix",Ce="object",W="property",Ae="expression";function V(i,e,t){const r=e[i].findIndex(n=>n&&n.type===Oe);return r>=0&&r!==e[i].length-1&&t.err("rest element must be the last"),e}const u={type:U,oper:S},G=Object.assign(Object.assign({},u),{space:!0}),Z={type:be,oper:S},_e=Object.assign(Object.assign({},{type:Q,oper:S,prefix:q}),{isPre:!0});Object.assign(Object.assign({},_e),{space:!0}),Object.assign(Object.assign({},{type:ye,oper:S,prefix:q,types:[me,I]}),{isPre:!0}),V.bind(null,"params"),V.bind(null,"elements");const z={type:I,left:Ce,right:W,extra:{computed:!1},subRules:W},Pe=Object.assign(Object.assign({},z),{close:"]",extra:{computed:!0},subRules:Ae});function E(i,e){const t={};Array.isArray(e)||(e=[e]),Array.isArray(i[0])||(i=[i]);for(let r=0;r36)throw new RangeError("Radix out of range");let t=`0-${e.radix<10?e.radix-1:9}`;e.radix>10&&(t+=`A-${String.fromCharCode(64+e.radix-10)}`),e.radix!==10&&(e.decimal=!1,e.exp=!1),this.digits=new RegExp(`[${t}]`,"i"),e.prefix&&(this.prefix=new RegExp(`^${e.prefix}`,"i"))}pre(e){const t=this.config;let r="",n,o="";if(this.prefix){const a=this.prefix.exec(e.rest());if(!a)return null;o=a[0],e.gb(o.length)}for(;this.digits.test(e.gtCh());)r+=e.gbCh();if(t.decimal&&e.gtCh()===".")for(r+=e.gbCh();this.digits.test(e.gtCh());)r+=e.gbCh();if((!r||r===".")&&!o)return e.gb(-r.length),null;if(n=e.gtCh(),t.exp&&(n==="e"||n==="E")){for(r+=e.gbCh(),n=e.gtCh(),(n==="+"||n==="-")&&(r+=e.gbCh());this.digits.test(e.gtCh());)r+=e.gbCh();this.digits.test(e.gtCh(-1))||e.err(`Expected exponent (${r}${e.gtCh()})`)}return r.length?e.teIdSt()?e.err():{type:xe,value:t.decimal?parseFloat(r):parseInt(r,t.radix),raw:o+r}:e.err("Invalid number format")}}E(["==","!=","===","!=="],u),E([["<",">","<=",">="],["instanceof","in"]],[u,G]),E(["<<",">>",">>>"],u),E(["+","-"],u),E(["*","/","%"],u),new T({radix:16,prefix:"0x"}),new T({radix:8,prefix:"0o"}),new T({radix:2,prefix:"0b"}),new T,new ge({".":z,"[":Pe}),E(["==","!=","===","!=="],u),E(["<",">","<=",">="],G),E(["<<",">>",">>>"],u),E(["+","-"],u),E(["*","/","%"],u);class Re{evaluate(e,t){return this._eval(e,t||{})}_eval(e,t){try{if(!(e.type in this))throw new Error(`Unsupported expression type: ${e.type}`);return this[e.type](e,t)}catch(r){throw r.node||(r.node=e),r}}_resolve(e,t,r,...n){const o=n.map(a=>(a||void 0)&&this._eval(a,e));return r(...o)}}function j(i,e){return new Error(`Unsuported ${i}: ${e}`)}const J={"|":(i,e)=>i|e,"^":(i,e)=>i^e,"&":(i,e)=>i&e,"==":(i,e)=>i==e,"!=":(i,e)=>i!=e,"===":(i,e)=>i===e,"!==":(i,e)=>i!==e,"<":(i,e)=>i":(i,e)=>i>e,"<=":(i,e)=>i<=e,">=":(i,e)=>i>=e,instanceof:(i,e)=>i instanceof e,in:(i,e)=>i in e,"<<":(i,e)=>i<>":(i,e)=>i>>e,">>>":(i,e)=>i>>>e,"+":(i,e)=>i+e,"-":(i,e)=>i-e,"*":(i,e)=>i*e,"/":(i,e)=>i/e,"%":(i,e)=>i%e,"**":(i,e)=>i**e},ee={"-":i=>-i,"+":i=>+i,"!":i=>!i,"~":i=>~i,typeof:i=>typeof i,void:i=>{}},_=0,M=1,te=2;class we extends Re{lvalue(e,t){return{o:{},m:""}}Literal(e){return e.value}Identifier(e,t){return t[e.name]}ThisExpression(e,t){return t}ArrayExpression(e,t){return this._resolve(t,0,(...r)=>r,...e.elements)}MemberExpression(e,t){return this._member(e,t,r=>r&&r.o[r.m])}_MemberObject(e,t){return this._member(e,t,r=>r)}_member(e,t,r){const n=e.optional||e.shortCircuited;return this._resolve(t,n?te+M:te,(o,a)=>n?o===null||typeof o>"u"?r(void 0):e.computed?this._resolve(t,_,l=>r({o,m:l}),e.property):r({o,m:e.property.name}):r({o,m:e.computed?a:e.property.name}),e.object,n||!e.computed?void 0:e.property)}CallExpression(e,t){const r=e.optional||e.shortCircuited,n=(o,a,l)=>{if(!(r&&(a===null||typeof a>"u"))){if(typeof a!="function")throw new TypeError("Callee is not a function");return r?this._resolve(t,_,(...h)=>a.apply(o,h),...e.arguments):a.apply(o,l)}};return this._resolve(t,M,(o,...a)=>e.callee.type===I?n(o==null?void 0:o.o,o==null?void 0:o.o[o.m],a):n(t,o,a),e.callee.type===I?Object.assign(Object.assign({},e.callee),{type:"_MemberObject"}):e.callee,...r?[]:e.arguments)}ConditionalExpression(e,t){return this._resolve(t,M,r=>this._eval(r?e.consequent:e.alternate,t),e.test)}SequenceExpression(e,t){return this._resolve(t,_,(...r)=>r.pop(),...e.expressions)}LogicalExpression(e,t){return this._resolve(t,M,r=>{switch(e.operator){case"||":return r||this._eval(e.right,t);case"&&":return r&&this._eval(e.right,t);case"??":return r??this._eval(e.right,t);case"##":return this._eval(e.right,t);default:throw j(U,e.operator)}},e.left)}BinaryExpression(e,t){if(!(e.operator in J))throw j(U,e.operator);return this._resolve(t,_,J[e.operator],e.left,e.right)}UnaryExpression(e,t){if(!(e.operator in ee))throw j(Q,e.operator);return this._resolve(t,_,ee[e.operator],e.argument)}ExpressionStatement(e,t){return this._eval(e.expression,t)}Program(e,t){return this._resolve(t,_,(...r)=>r.pop(),...e.body)}Compound(e,t){return this.Program(e,t)}}class ke{constructor(){this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:()=>this.should_skip=!0,remove:()=>this.should_remove=!0,replace:e=>this.replacement=e}}replace(e,t,r,n){e&&t&&(r!=null?e[t][r]=n:e[t]=n)}remove(e,t,r){e&&t&&(r!=null?e[t].splice(r,1):delete e[t])}}class De extends ke{constructor(e,t){super(),this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:()=>this.should_skip=!0,remove:()=>this.should_remove=!0,replace:r=>this.replacement=r},this.enter=e,this.leave=t}visit(e,t,r,n){if(e){if(this.enter){const a=this.should_skip,l=this.should_remove,h=this.replacement;this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.enter.call(this.context,e,t,r,n),this.replacement&&(e=this.replacement,this.replace(t,r,n,e)),this.should_remove&&this.remove(t,r,n);const c=this.should_skip,f=this.should_remove;if(this.should_skip=a,this.should_remove=l,this.replacement=h,c)return e;if(f)return null}let o;for(o in e){const a=e[o];if(a&&typeof a=="object")if(Array.isArray(a)){const l=a;for(let h=0;h{if(e.includes(r)){if(r.type!=="MemberExpression")return;e.push(r.object),e.push(r.property);return}if(r.type==="MemberExpression"){t.push(r.object),e.push(r.property);return}if(r.type==="Identifier"){t.push(r);return}})}function v(i,e){return Ie.evaluate(i,e)}const L={};function Te(i){L[i.selector]=i}const Y=i=>i.nodeType===i.ELEMENT_NODE,ie=/\{\{(.*?)\}\}/g;function Me(i,e){var t;if(i.nodeType===i.COMMENT_NODE)return!0;if(i.nodeType===i.TEXT_NODE){let r=function(){i.nodeValue=a==null?void 0:a.replace(ie,(h,c)=>{const f=P(c);return v(f,e).toString()})};const n=Object.keys(e),o=[];(t=i.nodeValue)==null||t.replace(ie,(h,c)=>{const f=P(c);return X(f,[],o),h});const a=i.nodeValue,l=[];for(const h of o){const c=h.name;if(l.includes(c)||!n.includes(c))continue;const f=e[c];f.listeners&&(f.listeners.push(r),l.push(c))}return r(),!0}if(Y(i)){const r=Object.keys(i.dataset);for(const n of r){if(n.startsWith("on")){const o=n.replace(/^on([A-Z])/,l=>l[2].toLowerCase()),a=i.dataset[n];i.addEventListener(o,()=>v(P(a),e));continue}if(n.startsWith("for")){let o=function(){const w=[],p=v(c,e);if(!Array.isArray(p))throw"You must bind `data-for` to an array";for(const b of p)w.push({key:v(N,{...e,[f]:b}),val:b});return w},a=function(){const w=o(),p=[],b=[...m.childNodes],ae=b.indexOf(ne),he=b.indexOf(H);for(const{val:k,key:y}of w){let d=b.find((O,ce)=>cehe||!Y(O)?!1:O.dataset.for===l&&O.dataset.key===y?(p.push(O),!0):!1);if(!d){const O=document.createElement("div");O.innerHTML=R,d=O.firstElementChild,d.removeAttribute("data-for"),d.removeAttribute("data-key"),d.setAttribute("data-specific-key",y),K([d],{...e,[f]:k})}p.push(d)}const le=b.slice(ae+1,he).filter(Y),Be=Math.max(le.length,p.length);for(let k=0;k