create-prisma-php-app 4.1.0-alpha.4 → 4.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ Defaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=1
13
13
  ⚠️ Failed to extract mustache expression - unclosed braces`),console.warn(` Content: ${e}`),console.warn(` Starting at position: ${s}
14
14
  `),{endIndex:-1,expression:""}}static checkForMismatchedQuotes(e){let s=0,i=0,n=!1;for(let r=0;r<e.length;r++){if(n){n=!1;continue}if(e[r]==="\\"){n=!0;continue}e[r]==="'"&&s++,e[r]==='"'&&i++}return s%2!==0?{hasIssue:!0,message:`Unmatched single quotes (found ${s})`}:i%2!==0?{hasIssue:!0,message:`Unmatched double quotes (found ${i})`}:{hasIssue:!1,message:""}}static isSingleExpression(e){const s=_.decodeEntities(e),i=_.parseContentWithNesting(s);return i.length===1&&i[0].type==="expression"?i[0].expression:null}static extractExpressions(e){const s=_.decodeEntities(e),i=_.parseContentWithNesting(s),n=i.filter(r=>r.type==="expression").map(r=>r.expression).filter(r=>r);return i.some(r=>r.type==="expression")&&n.length===0&&(console.error(`
15
15
  ❌ Failed to extract expressions from content:`),console.error(` Content: ${e}`),console.error(` Parsed ${i.length} parts, but extracted 0 expressions`),console.error(` This usually means malformed mustache syntax
16
- `)),n}}class _s{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,s){this.expressionEvaluator=e,this.stateManager=s,this.cleanupObserver=new MutationObserver(i=>{this.cleanupDetachedNodes(i)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){for(const i of e)i.type==="childList"&&i.removedNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE)this.cleanupTextNode(n);else if(n.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)this.cleanupTextNode(a)}});const s=[];for(const[i]of this.textNodeBindings)document.contains(i)||s.push(i);s.forEach(i=>this.cleanupTextNode(i))}processTextNode(e,s){if(this.textNodeBindings.has(e)||y.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const i=e.parentElement,n=i?y.getContextComponent(i):s,r=e.textContent||"",a=_.parse(r);if(!a.some(l=>l.type==="expression"))return;const c={originalContent:r,expressions:a,subscriptionIds:[]};a.filter(l=>l.type==="expression").forEach(l=>{if(!l.expression)return;const h=`text_${Date.now()}_${Math.random()}`,p=this.expressionEvaluator.extractDependencies(l.expression,n,this.stateManager),f={id:h,selector:"",dependencies:new Set(p),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:n};this.stateManager.addSubscription(f),c.subscriptionIds.push(h)}),this.textNodeBindings.set(e,c),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let s=e.parentElement;for(;s&&s!==document.body;){const i=s.previousSibling;if(i&&i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:"))return!0;let n=s.parentElement?.firstChild||null;for(;n;){if(n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:")&&n!==s)return!0;n=n.nextSibling}s=s.parentElement}return!1}updateTextNode(e){const s=this.textNodeBindings.get(e);if(!s||!e.parentElement)return;const i=e.parentElement,n=y.getContextComponent(i),r=this.resolveComponentRootForElement(e,n),a=this.getContextForComponent(n,r);let o="";for(const c of s.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,n);o+=ie(l)}catch(l){const h=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.warn(`Text binding evaluation warning for "${c.expression}": ${h}`),o+=""}e.textContent!==o&&(e.textContent=o)}resolveComponentRootForElement(e,s){let i=e.parentElement;for(;i&&i.nodeType===Node.ELEMENT_NODE;){const n=i;if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;i=i.parentElement}}getContextForComponent(e,s){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,s):{}}cleanupTextNode(e){const s=this.textNodeBindings.get(e);s&&(s.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)}),this.textNodeBindings.delete(e),this.bindingCount=Math.max(0,this.bindingCount-1))}getBindingCount(){return this.textNodeBindings.size}getAllBindings(){return new Map(this.textNodeBindings)}clearAllBindings(){for(const[e]of this.textNodeBindings)this.cleanupTextNode(e)}destroy(){this.cleanupObserver.disconnect(),this.clearAllBindings()}}class ks{listeners=new Map;on(e,s){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(s),()=>this.off(e,s)}off(e,s){this.listeners.get(e)?.delete(s)}emit(e,...s){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(...s)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Is{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new ks;contextCache=new Map;previousValues=new Map;_subscriptionManager=new Ts;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const s=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,s.forEach(i=>{try{i()}catch(n){console.error("DOM update callback error:",n)}})})}))}setInitialState(e,s){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=s,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const s=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=s,!this.isUpdating&&this.updateQueue.size>0&&this.scheduleFlush()}}invalidateContextCache(){this.contextCache.clear()}setupGlobalStateProxy(){this.originalStateStore=this.stateStore,this.stateStore=new Proxy(this.stateStore,{set:(e,s,i,n)=>{const r=e[s],a=Reflect.set(e,s,i,n);return r!==i&&this.notifySubscribers(s),a},get:(e,s)=>Reflect.get(e,s)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const s=e.split(".")[0];this.updateQueue.add(s)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const s=this.stateStore[e],i=this.previousValues?.get(e);for(const[n,r]of this.subscriptions)for(const a of r.dependencies)if(this.isPathDependency(a)&&a.startsWith(e+".")){const o=a.substring(e.length+1),c=this.getPathValue(i,o),l=this.getPathValue(s,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,s){if(!e||typeof e!="object")return;const i=s.split(".");let n=e;for(const r of i){if(n==null)return;if(Array.isArray(n))return r==="length"?n.length:n.map(a=>a?.[r]).filter(a=>a!==void 0);n=n[r]}return n}deepEqual(e,s){if(e===s)return!0;if(e==null||s==null)return!1;if(Array.isArray(e)&&Array.isArray(s))return e.length!==s.length?!1:e.every((i,n)=>this.deepEqual(i,s[n]));if(typeof e=="object"&&typeof s=="object"){const i=Object.keys(e),n=Object.keys(s);return i.length!==n.length?!1:i.every(r=>this.deepEqual(e[r],s[r]))}return!1}scheduleFlush=As(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,s=this.subscriptionManager.getSubscriptionsForKey("*");if(s&&s.size>0&&this.updateQueue.size>0)for(const i of s){const n=this.subscriptionManager.getSubscription(i);if(!n)continue;if(n.element&&!document.contains(n.element)){this.subscriptionManager.removeSubscription(i);continue}const r=n.element??document.body;try{const a=Array.from(this.updateQueue)[0];n.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const i of this.updateQueue){if(e.has(i))continue;e.add(i);const n=this.subscriptionManager.getSubscriptionsForKey(i);if(n)for(const r of n){const a=this.subscriptionManager.getSubscription(r);if(!a)continue;if(a.element&&!document.contains(a.element)){this.subscriptionManager.removeSubscription(r);continue}const o=a.element??document.body;try{a.callback(o,{key:i})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,s){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=s,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}hasState(e){return e in this.originalStateStore}addSubscription(e){this._subscriptionManager.addSubscription(e)}removeSubscription(e){this._subscriptionManager.removeSubscription(e)}onStateChange(e){return this.eventBus.on("stateChanged",e)}batch(e){const s=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=s,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,s=this.subscriptionManager.getAllSubscriptions();for(const[i,n]of s)for(const r of n.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(i);return e}}class ce{expressionCache=new $(d.MAX_CACHE_SIZE);dependencyCache=new $(d.MAX_CACHE_SIZE);commonExpressionsCache=new $(100);dependencyParser=new Ns;static CACHE_KEYS={EXPRESSION:(e,s)=>`expr:${e}:${s}`,DEPENDENCY:(e,s)=>`deps:${e}:${s}`,COMMON:e=>`common:${e}`};constructor(){this.precompileCommonExpressions()}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}precompileCommonExpressions(){["true","false","null","undefined"].forEach(s=>{const i={fn:new Function("return "+s),contextMap:new Map,dependencies:[s],timestamp:Date.now(),hitCount:0},n=ce.CACHE_KEYS.COMMON(s);this.commonExpressionsCache.set(n,i)})}extractDependencies(e,s,i){const n=this.normalizeExpression(e),r=ce.CACHE_KEYS.DEPENDENCY(s,n);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(n,s,i),this.dependencyCache.set(r,a),a)}evaluateExpression(e,s,i){const n=this.normalizeExpression(e),r=ce.CACHE_KEYS.COMMON(n);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${n}"`,c);return}}const o=ce.CACHE_KEYS.EXPRESSION(i,n);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(n,s,i),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,s);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${n}"`,c),console.error("Available context:",Object.keys(s));return}}compileExpression(e,s,i){const n=this.prepareSafeContext(s),r=new Map,a=[];Object.keys(n).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,i);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,s){const i=new Array(e.size);for(const[n,r]of e)i[r]=s[n];return i}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const s={};for(const[i,n]of Object.entries(e))xe.has(i)||!this.isValidJavaScriptIdentifier(i)||(s[i]=n);return s}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!xe.has(e)}invalidateCache(e){switch(e){case"expressions":this.expressionCache.clear();break;case"dependencies":this.dependencyCache.clear();break;case"common":this.commonExpressionsCache.clear(),this.precompileCommonExpressions();break;case"parser":this.dependencyParser.clearCache();break;default:this.clearAllCaches()}}invalidateByComponent(e){this.expressionCache.deleteByPrefix(`expr:${e}:`),this.dependencyCache.deleteByPrefix(`deps:${e}:`)}clearAllCaches(){this.expressionCache.clear(),this.dependencyCache.clear(),this.commonExpressionsCache.clear(),this.dependencyParser.clearCache(),this.precompileCommonExpressions()}getCacheStats(){return{expressions:this.expressionCache.getStats(),dependencies:this.dependencyCache.getStats(),commonExpressions:this.commonExpressionsCache.getStats(),dependencyParser:this.getDependencyParserStats()}}getDependencyParserStats(){return this.dependencyParser.getCacheSize?{size:this.dependencyParser.getCacheSize(),maxSize:500,hitRate:0,hits:0,misses:0}:{size:0,maxSize:0,hitRate:0,hits:0,misses:0}}cleanupStaleExpressions(){let e=0;return this.expressionCache.keys().forEach(i=>{const n=this.expressionCache.get(i);n&&this.isStale(n)&&(this.expressionCache.delete(i),e++)}),e}}class Ns{parseCache=new $(500);extract(e,s,i){const n=this.normalizeExpression(e),r=`${s}:${n}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(n,s,i);return this.parseCache.set(r,a),a}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}parseExpression(e,s,i){const n=this.extractIdentifiers(e),r=[],a=i?.getState()||{};for(const c of n){if(xe.has(c))continue;const l=c.indexOf("."),h=l===-1?c:c.substring(0,l),p=Be.findExistingStateKey(h,s,a);if(p)r.push(p);else{const f=s==="app"?[`app.${h}`]:[`${s}.${h}`,`app.${h}`];r.push(...f)}if(l!==-1){const f=s==="app"?[`app.${h}`]:[`${s}.${h}`,`app.${h}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const s=[];let i=0;for(;i<e.length;){const n=e[i];if(n==="'"){i=this.skipString(e,i,"'");continue}if(n==='"'){i=this.skipString(e,i,'"');continue}if(n==="`"){i=this.skipTemplateLiteral(e,i,s);continue}if(this.isIdentifierStart(n)){const r=this.extractIdentifier(e,i);s.push(r.value),i=r.endIndex;continue}i++}return s}skipString(e,s,i){let n=s+1;for(;n<e.length&&e[n]!==i;)e[n]==="\\"&&n++,n++;return n+1}skipTemplateLiteral(e,s,i){let n=s+1;for(;n<e.length&&e[n]!=="`";){if(e[n]==="$"&&n+1<e.length&&e[n+1]==="{"){n+=2;let r=1;for(;n<e.length&&r>0;){const a=e[n];if(a==='"'||a==="'"){n=this.skipString(e,n,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,n);i.push(o.value),n=o.endIndex-1}n++}continue}e[n]==="\\"&&n++,n++}return n+1}extractIdentifier(e,s){let i=s;for(;i<e.length&&(this.isIdentifierPart(e[i])||e[i]===".");)i++;return{value:e.substring(s,i),endIndex:i}}isIdentifierStart(e){return/[a-zA-Z_$]/.test(e)}isIdentifierPart(e){return/[a-zA-Z0-9_$]/.test(e)}clearCache(){this.parseCache.clear()}getCacheSize(){return this.parseCache.cache.size}}class Ms{componentStack=["app"];elementProps=new WeakMap;contextCache=new $(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new et;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new et,this.stateManager.onStateChange(s=>this.invalidateContextCache(s))}getPropDependencies(e,s){const i=this.findElementWithProps(s);if(!i)return[];const n=this.elementProps.get(i);if(!n||!n.has(e))return[];const r=n.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,s=!1){const i={};window[e]&&Object.assign(i,window[e]);const n=this.componentFunctions.get(e);if(n)for(const[a,o]of n)i[a]=o;const r=this.stateManager.getState();for(const a of Object.keys(r))if(a.startsWith(e+".")){const o=a.substring(e.length+1);o in i||(i[o]=r[a])}if(s){if(window.app)for(const[o,c]of Object.entries(window.app))o in i||(i[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in i||(i[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in i||(i[c]=r[o])}}return i}getComponentPropDependencies(e,s){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const i=[],n=this.elementProps.get(e);n&&this.templateRenderer&&n.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);i.push(...o??[])});const r=Array.from(new Set(i));return this.propDependencyCache.set(e,r),r}setDOMBindingManager(e){this.domBindingManager=e,this.updateBatcher.setManagers(this,e)}hasStoredProps(e){return this.elementProps.has(e)&&this.elementProps.get(e).size>0}setExpressionEvaluator(e){this.expressionEvaluator=e,this.templateRenderer=new Ke(e),this.loopManager=new Ft(this.stateManager,e)}extractProps(e,s){const i=new Map,n=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=s;r&&(r==="app"?o="app":r==="parent"?o=y.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<n.length;c++){const l=n[c];if(!(l.name===d.ATTR_PREFIXES.COMPONENT||l.name===d.ATTR_PREFIXES.CONTEXT||l.name===d.ATTR_PREFIXES.SPREAD||l.name===d.ATTR_PREFIXES.LOOP)&&!oe.isEventAttribute(l.name)&&l.value&&Ps.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const h=this.attributeToPropName(l.name),p={name:h,expression:l.value,component:o,subscriptionIds:[]};i.set(h,p)}}return i}mightReferenceSelfProps(e,s){const i=this.elementProps.get(s);return i?Array.from(i.keys()).some(r=>e.includes(r)&&r!=="dataState"):!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(s,i)=>i.toUpperCase())}setupProps(e,s){const i=this.extractProps(e,s);i.size!==0&&(this.elementProps.set(e,i),this.expressionEvaluator&&i.forEach((n,r)=>{this.setupPropBinding(e,n)}))}setupPropBinding(e,s){if(!this.expressionEvaluator)return;const i=`prop_${Date.now()}_${Math.random()}`,n=this.templateRenderer?.dependencies(s.expression,s.component,this.stateManager)||[],r={id:i,selector:"",dependencies:new Set(n),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:s.component};this.stateManager.addSubscription(r),s.subscriptionIds.push(i)}refreshComponentBindings(e,s){this.contextInvalidated.add(s),this.contextCache.delete(s),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,s)}evaluateProps(e){const s={},i=this.elementProps.get(e);if(!i||!this.expressionEvaluator)return s;const n=i.values().next().value;if(!n)return s;const r=this.buildComponentContext(n.component);return i.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?s[o]=(...l)=>c.apply(this,l):s[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),s[o]=void 0}}),s}cleanupProps(e){const s=this.elementProps.get(e);s&&(s.forEach(i=>{i.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,s){const i=this.buildComponentContext(e);let n=this.findElementWithProps(e);if(s&&this.elementProps.has(s)&&(n=s),n)try{const r=this.evaluatePropsWithContext(n,e,s);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{i[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return i}evaluatePropsWithContext(e,s,i){const n={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return n;const a=r.values().next().value;if(!a)return n;let o;const c=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),l=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(c)if(c==="app")o=this.buildComponentContext("app");else if(c==="parent"){const C=y.getParentOfComponent(l||"app",e);o=this.buildComponentContext(C)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const h=this.loopManager?.getLoopContextForElement(e);h&&(o={...o,...h});const p=new Map,f=new Map,m=Array.from(r.keys());r.forEach((C,v)=>{m.some(I=>I!==v&&C.expression.includes(I))?f.set(v,C):p.set(v,C)}),p.forEach((C,v)=>{try{const A=this.templateRenderer?.render(C.expression,o,c||C.component);typeof A=="function"?this.isFunctionExplicitlyPassed(C.expression)?n[v]=(...fe)=>A.apply(this,fe):(console.warn(`⚠️ Function "${v}" not passed - not from shared namespace or explicitly passed`),n[v]=void 0):n[v]=A}catch(A){console.error(`❌ Failed to evaluate simple prop "${v}":`,A),console.error("Expression:",C.expression),console.error("Available context keys:",Object.keys(o)),n[v]=void 0}});const x={...o,...n};return f.forEach((C,v)=>{try{const A=this.templateRenderer?.render(C.expression,x,c||C.component);typeof A=="function"?this.isFunctionExplicitlyPassed(C.expression)?n[v]=(...fe)=>A.apply(this,fe):(console.warn(`⚠️ Function "${v}" not passed - not from shared namespace or explicitly passed`),n[v]=void 0):n[v]=A}catch(A){console.error(`❌ Failed to evaluate complex prop "${v}":`,A),console.error("Expression:",C.expression),console.error("Available context keys:",Object.keys(x)),n[v]=void 0}}),n}isFunctionExplicitlyPassed(e){const s=_.isSingleExpression(e);return s?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s.trim()):!1}findElementWithProps(e){const s=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const i of s){const n=this.elementProps.get(i);if(n&&n.size>0)return i}return null}pushComponent(e){this.componentStack.push(e)}popComponent(){return this.componentStack.pop()}getCurrentComponent(){return this.componentStack[this.componentStack.length-1]}buildComponentContext(e){if(!this.contextInvalidated.has(e)&&this.contextCache.has(e))return this.contextCache.get(e);const s=this.computeComponentContext(e);return this.contextCache.set(e,s),this.contextInvalidated.delete(e),s}computeComponentContext(e){const s={};e!=="app"&&window[e]&&Object.assign(s,window[e]),e==="app"&&window.app&&Object.assign(s,window.app);const i=this.componentFunctions.get(e);if(i)for(const[r,a]of i)s[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in s||(s[a]=o)}const n=this.stateManager.getState();for(const r of Object.keys(n))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in s||(s[a]=n[r])}if(e!=="app"){for(const r of Object.keys(n))if(r.startsWith("app.")){const a=r.substring(4);a in s||(s[a]=n[r])}}return s}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const i of this.contextInvalidated.keys())this.contextInvalidated.add(i);return}const s=e.indexOf(".");if(s!==-1){const i=e.slice(0,s);this.invalidateComponent(i)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const s=this.componentStack.length,i=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),n=e===document.body;if(i||n){if(i){this.pushComponent(i);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,n).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==i?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>s;)this.popComponent()}getParentComponent(e){let s=e.parentElement;for(;s;){const i=s.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(i)return i;s=s.parentElement}return"app"}getRelevantScripts(e,s){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(i=>{if(this.processedScripts.has(i))return!1;if(s)return i.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!i.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let n=i.parentElement;for(;n&&n!==e;){if(n.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;n=n.parentElement}return n===e||e.contains(i)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const s=this.getCurrentComponent(),i=e.textContent||"",n=_.decodeEntities(i);try{const r=this.findComponentElementForScript(e,s);if(r===e){const o=this.getParentComponent(e);this.setupProps(e,o)}const a=this.buildComponentContextWithProps(s,r);window[s]||(window[s]={}),this.executeScriptFunctions(n,s,a)}catch(r){console.error(`Script execution failed in component ${s}:`,r),console.error("Script content:",n)}}findComponentElementForScript(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let i=e.parentElement;for(;i;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return i;i=i.parentElement}const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const r of n)if(this.elementProps.has(r))return r;return n[0]||void 0}executeScriptFunctions(e,s,i){const n=this.extractFunctionNames(e),r=this.findElementWithProps(s),a=this.extractVariableDeclarations(e);let o={...i};if(a.forEach(x=>{delete o[x];const C=`set${Vt(x)}`,v=`${x}Getter`;delete o[C],delete o[v]}),r){const x=this.evaluateProps(r);Object.assign(o,x)}o.getContext=()=>this.buildComponentContextWithProps(s),o.withContext=x=>{const C=this.buildComponentContextWithProps(s);return x.call(C,C)},o.__getProp=x=>{if(r)return this.evaluateProps(r)[x]};let l=q.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,s,r||void 0);const h=`
16
+ `)),n}}class _s{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,s){this.expressionEvaluator=e,this.stateManager=s,this.cleanupObserver=new MutationObserver(i=>{this.cleanupDetachedNodes(i)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){const s=[];for(const i of e)i.type==="childList"&&i.removedNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE)s.push(n);else if(n.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)s.push(a)}});Promise.resolve().then(()=>{s.forEach(i=>{document.contains(i)||this.cleanupTextNode(i)})})}processTextNode(e,s){if(this.textNodeBindings.has(e)||y.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const i=e.parentElement,n=i?y.getContextComponent(i):s,r=e.textContent||"",a=_.parse(r);if(!a.some(l=>l.type==="expression"))return;const c={originalContent:r,expressions:a,subscriptionIds:[]};a.filter(l=>l.type==="expression").forEach(l=>{if(!l.expression)return;const h=`text_${Date.now()}_${Math.random()}`,p=this.expressionEvaluator.extractDependencies(l.expression,n,this.stateManager),f={id:h,selector:"",dependencies:new Set(p),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:n};this.stateManager.addSubscription(f),c.subscriptionIds.push(h)}),this.textNodeBindings.set(e,c),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let s=e.parentElement;for(;s&&s!==document.body;){const i=s.previousSibling;if(i&&i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:"))return!0;let n=s.parentElement?.firstChild||null;for(;n;){if(n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:")&&n!==s)return!0;n=n.nextSibling}s=s.parentElement}return!1}updateTextNode(e){const s=this.textNodeBindings.get(e);if(!s||!e.parentElement)return;const i=e.parentElement,n=y.getContextComponent(i),r=this.resolveComponentRootForElement(e,n),a=this.getContextForComponent(n,r);let o="";for(const c of s.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,n);o+=ie(l)}catch(l){const h=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.warn(`Text binding evaluation warning for "${c.expression}": ${h}`),o+=""}e.textContent!==o&&(e.textContent=o)}resolveComponentRootForElement(e,s){let i=e.parentElement;for(;i&&i.nodeType===Node.ELEMENT_NODE;){const n=i;if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;i=i.parentElement}}getContextForComponent(e,s){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,s):{}}cleanupTextNode(e){const s=this.textNodeBindings.get(e);s&&(s.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)}),this.textNodeBindings.delete(e),this.bindingCount=Math.max(0,this.bindingCount-1))}getBindingCount(){return this.textNodeBindings.size}getAllBindings(){return new Map(this.textNodeBindings)}clearAllBindings(){for(const[e]of this.textNodeBindings)this.cleanupTextNode(e)}destroy(){this.cleanupObserver.disconnect(),this.clearAllBindings()}}class ks{listeners=new Map;on(e,s){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(s),()=>this.off(e,s)}off(e,s){this.listeners.get(e)?.delete(s)}emit(e,...s){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(...s)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Is{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new ks;contextCache=new Map;previousValues=new Map;_subscriptionManager=new Ts;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const s=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,s.forEach(i=>{try{i()}catch(n){console.error("DOM update callback error:",n)}})})}))}setInitialState(e,s){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=s,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const s=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=s,!this.isUpdating&&this.updateQueue.size>0&&this.scheduleFlush()}}invalidateContextCache(){this.contextCache.clear()}setupGlobalStateProxy(){this.originalStateStore=this.stateStore,this.stateStore=new Proxy(this.stateStore,{set:(e,s,i,n)=>{const r=e[s],a=Reflect.set(e,s,i,n);return r!==i&&this.notifySubscribers(s),a},get:(e,s)=>Reflect.get(e,s)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const s=e.split(".")[0];this.updateQueue.add(s)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const s=this.stateStore[e],i=this.previousValues?.get(e);for(const[n,r]of this.subscriptions)for(const a of r.dependencies)if(this.isPathDependency(a)&&a.startsWith(e+".")){const o=a.substring(e.length+1),c=this.getPathValue(i,o),l=this.getPathValue(s,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,s){if(!e||typeof e!="object")return;const i=s.split(".");let n=e;for(const r of i){if(n==null)return;if(Array.isArray(n))return r==="length"?n.length:n.map(a=>a?.[r]).filter(a=>a!==void 0);n=n[r]}return n}deepEqual(e,s){if(e===s)return!0;if(e==null||s==null)return!1;if(Array.isArray(e)&&Array.isArray(s))return e.length!==s.length?!1:e.every((i,n)=>this.deepEqual(i,s[n]));if(typeof e=="object"&&typeof s=="object"){const i=Object.keys(e),n=Object.keys(s);return i.length!==n.length?!1:i.every(r=>this.deepEqual(e[r],s[r]))}return!1}scheduleFlush=As(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,s=this.subscriptionManager.getSubscriptionsForKey("*");if(s&&s.size>0&&this.updateQueue.size>0)for(const i of s){const n=this.subscriptionManager.getSubscription(i);if(!n)continue;if(n.element&&!document.contains(n.element)){this.subscriptionManager.removeSubscription(i);continue}const r=n.element??document.body;try{const a=Array.from(this.updateQueue)[0];n.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const i of this.updateQueue){if(e.has(i))continue;e.add(i);const n=this.subscriptionManager.getSubscriptionsForKey(i);if(n)for(const r of n){const a=this.subscriptionManager.getSubscription(r);if(!a)continue;if(a.element&&!document.contains(a.element)){this.subscriptionManager.removeSubscription(r);continue}const o=a.element??document.body;try{a.callback(o,{key:i})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,s){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=s,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}hasState(e){return e in this.originalStateStore}addSubscription(e){this._subscriptionManager.addSubscription(e)}removeSubscription(e){this._subscriptionManager.removeSubscription(e)}onStateChange(e){return this.eventBus.on("stateChanged",e)}batch(e){const s=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=s,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,s=this.subscriptionManager.getAllSubscriptions();for(const[i,n]of s)for(const r of n.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(i);return e}}class ce{expressionCache=new $(d.MAX_CACHE_SIZE);dependencyCache=new $(d.MAX_CACHE_SIZE);commonExpressionsCache=new $(100);dependencyParser=new Ns;static CACHE_KEYS={EXPRESSION:(e,s)=>`expr:${e}:${s}`,DEPENDENCY:(e,s)=>`deps:${e}:${s}`,COMMON:e=>`common:${e}`};constructor(){this.precompileCommonExpressions()}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}precompileCommonExpressions(){["true","false","null","undefined"].forEach(s=>{const i={fn:new Function("return "+s),contextMap:new Map,dependencies:[s],timestamp:Date.now(),hitCount:0},n=ce.CACHE_KEYS.COMMON(s);this.commonExpressionsCache.set(n,i)})}extractDependencies(e,s,i){const n=this.normalizeExpression(e),r=ce.CACHE_KEYS.DEPENDENCY(s,n);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(n,s,i),this.dependencyCache.set(r,a),a)}evaluateExpression(e,s,i){const n=this.normalizeExpression(e),r=ce.CACHE_KEYS.COMMON(n);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${n}"`,c);return}}const o=ce.CACHE_KEYS.EXPRESSION(i,n);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(n,s,i),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,s);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${n}"`,c),console.error("Available context:",Object.keys(s));return}}compileExpression(e,s,i){const n=this.prepareSafeContext(s),r=new Map,a=[];Object.keys(n).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,i);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,s){const i=new Array(e.size);for(const[n,r]of e)i[r]=s[n];return i}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const s={};for(const[i,n]of Object.entries(e))xe.has(i)||!this.isValidJavaScriptIdentifier(i)||(s[i]=n);return s}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!xe.has(e)}invalidateCache(e){switch(e){case"expressions":this.expressionCache.clear();break;case"dependencies":this.dependencyCache.clear();break;case"common":this.commonExpressionsCache.clear(),this.precompileCommonExpressions();break;case"parser":this.dependencyParser.clearCache();break;default:this.clearAllCaches()}}invalidateByComponent(e){this.expressionCache.deleteByPrefix(`expr:${e}:`),this.dependencyCache.deleteByPrefix(`deps:${e}:`)}clearAllCaches(){this.expressionCache.clear(),this.dependencyCache.clear(),this.commonExpressionsCache.clear(),this.dependencyParser.clearCache(),this.precompileCommonExpressions()}getCacheStats(){return{expressions:this.expressionCache.getStats(),dependencies:this.dependencyCache.getStats(),commonExpressions:this.commonExpressionsCache.getStats(),dependencyParser:this.getDependencyParserStats()}}getDependencyParserStats(){return this.dependencyParser.getCacheSize?{size:this.dependencyParser.getCacheSize(),maxSize:500,hitRate:0,hits:0,misses:0}:{size:0,maxSize:0,hitRate:0,hits:0,misses:0}}cleanupStaleExpressions(){let e=0;return this.expressionCache.keys().forEach(i=>{const n=this.expressionCache.get(i);n&&this.isStale(n)&&(this.expressionCache.delete(i),e++)}),e}}class Ns{parseCache=new $(500);extract(e,s,i){const n=this.normalizeExpression(e),r=`${s}:${n}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(n,s,i);return this.parseCache.set(r,a),a}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}parseExpression(e,s,i){const n=this.extractIdentifiers(e),r=[],a=i?.getState()||{};for(const c of n){if(xe.has(c))continue;const l=c.indexOf("."),h=l===-1?c:c.substring(0,l),p=Be.findExistingStateKey(h,s,a);if(p)r.push(p);else{const f=s==="app"?[`app.${h}`]:[`${s}.${h}`,`app.${h}`];r.push(...f)}if(l!==-1){const f=s==="app"?[`app.${h}`]:[`${s}.${h}`,`app.${h}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const s=[];let i=0;for(;i<e.length;){const n=e[i];if(n==="'"){i=this.skipString(e,i,"'");continue}if(n==='"'){i=this.skipString(e,i,'"');continue}if(n==="`"){i=this.skipTemplateLiteral(e,i,s);continue}if(this.isIdentifierStart(n)){const r=this.extractIdentifier(e,i);s.push(r.value),i=r.endIndex;continue}i++}return s}skipString(e,s,i){let n=s+1;for(;n<e.length&&e[n]!==i;)e[n]==="\\"&&n++,n++;return n+1}skipTemplateLiteral(e,s,i){let n=s+1;for(;n<e.length&&e[n]!=="`";){if(e[n]==="$"&&n+1<e.length&&e[n+1]==="{"){n+=2;let r=1;for(;n<e.length&&r>0;){const a=e[n];if(a==='"'||a==="'"){n=this.skipString(e,n,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,n);i.push(o.value),n=o.endIndex-1}n++}continue}e[n]==="\\"&&n++,n++}return n+1}extractIdentifier(e,s){let i=s;for(;i<e.length&&(this.isIdentifierPart(e[i])||e[i]===".");)i++;return{value:e.substring(s,i),endIndex:i}}isIdentifierStart(e){return/[a-zA-Z_$]/.test(e)}isIdentifierPart(e){return/[a-zA-Z0-9_$]/.test(e)}clearCache(){this.parseCache.clear()}getCacheSize(){return this.parseCache.cache.size}}class Ms{componentStack=["app"];elementProps=new WeakMap;contextCache=new $(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new et;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new et,this.stateManager.onStateChange(s=>this.invalidateContextCache(s))}getPropDependencies(e,s){const i=this.findElementWithProps(s);if(!i)return[];const n=this.elementProps.get(i);if(!n||!n.has(e))return[];const r=n.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,s=!1){const i={};window[e]&&Object.assign(i,window[e]);const n=this.componentFunctions.get(e);if(n)for(const[a,o]of n)i[a]=o;const r=this.stateManager.getState();for(const a of Object.keys(r))if(a.startsWith(e+".")){const o=a.substring(e.length+1);o in i||(i[o]=r[a])}if(s){if(window.app)for(const[o,c]of Object.entries(window.app))o in i||(i[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in i||(i[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in i||(i[c]=r[o])}}return i}getComponentPropDependencies(e,s){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const i=[],n=this.elementProps.get(e);n&&this.templateRenderer&&n.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);i.push(...o??[])});const r=Array.from(new Set(i));return this.propDependencyCache.set(e,r),r}setDOMBindingManager(e){this.domBindingManager=e,this.updateBatcher.setManagers(this,e)}hasStoredProps(e){return this.elementProps.has(e)&&this.elementProps.get(e).size>0}setExpressionEvaluator(e){this.expressionEvaluator=e,this.templateRenderer=new Ke(e),this.loopManager=new Ft(this.stateManager,e)}extractProps(e,s){const i=new Map,n=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=s;r&&(r==="app"?o="app":r==="parent"?o=y.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<n.length;c++){const l=n[c];if(!(l.name===d.ATTR_PREFIXES.COMPONENT||l.name===d.ATTR_PREFIXES.CONTEXT||l.name===d.ATTR_PREFIXES.SPREAD||l.name===d.ATTR_PREFIXES.LOOP)&&!oe.isEventAttribute(l.name)&&l.value&&Ps.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const h=this.attributeToPropName(l.name),p={name:h,expression:l.value,component:o,subscriptionIds:[]};i.set(h,p)}}return i}mightReferenceSelfProps(e,s){const i=this.elementProps.get(s);return i?Array.from(i.keys()).some(r=>e.includes(r)&&r!=="dataState"):!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(s,i)=>i.toUpperCase())}setupProps(e,s){const i=this.extractProps(e,s);i.size!==0&&(this.elementProps.set(e,i),this.expressionEvaluator&&i.forEach((n,r)=>{this.setupPropBinding(e,n)}))}setupPropBinding(e,s){if(!this.expressionEvaluator)return;const i=`prop_${Date.now()}_${Math.random()}`,n=this.templateRenderer?.dependencies(s.expression,s.component,this.stateManager)||[],r={id:i,selector:"",dependencies:new Set(n),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:s.component};this.stateManager.addSubscription(r),s.subscriptionIds.push(i)}refreshComponentBindings(e,s){this.contextInvalidated.add(s),this.contextCache.delete(s),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,s)}evaluateProps(e){const s={},i=this.elementProps.get(e);if(!i||!this.expressionEvaluator)return s;const n=i.values().next().value;if(!n)return s;const r=this.buildComponentContext(n.component);return i.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?s[o]=(...l)=>c.apply(this,l):s[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),s[o]=void 0}}),s}cleanupProps(e){const s=this.elementProps.get(e);s&&(s.forEach(i=>{i.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,s){const i=this.buildComponentContext(e);let n=this.findElementWithProps(e);if(s&&this.elementProps.has(s)&&(n=s),n)try{const r=this.evaluatePropsWithContext(n,e,s);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{i[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return i}evaluatePropsWithContext(e,s,i){const n={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return n;const a=r.values().next().value;if(!a)return n;let o;const c=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),l=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(c)if(c==="app")o=this.buildComponentContext("app");else if(c==="parent"){const C=y.getParentOfComponent(l||"app",e);o=this.buildComponentContext(C)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const h=this.loopManager?.getLoopContextForElement(e);h&&(o={...o,...h});const p=new Map,f=new Map,m=Array.from(r.keys());r.forEach((C,v)=>{m.some(I=>I!==v&&C.expression.includes(I))?f.set(v,C):p.set(v,C)}),p.forEach((C,v)=>{try{const A=this.templateRenderer?.render(C.expression,o,c||C.component);typeof A=="function"?this.isFunctionExplicitlyPassed(C.expression)?n[v]=(...fe)=>A.apply(this,fe):(console.warn(`⚠️ Function "${v}" not passed - not from shared namespace or explicitly passed`),n[v]=void 0):n[v]=A}catch(A){console.error(`❌ Failed to evaluate simple prop "${v}":`,A),console.error("Expression:",C.expression),console.error("Available context keys:",Object.keys(o)),n[v]=void 0}});const x={...o,...n};return f.forEach((C,v)=>{try{const A=this.templateRenderer?.render(C.expression,x,c||C.component);typeof A=="function"?this.isFunctionExplicitlyPassed(C.expression)?n[v]=(...fe)=>A.apply(this,fe):(console.warn(`⚠️ Function "${v}" not passed - not from shared namespace or explicitly passed`),n[v]=void 0):n[v]=A}catch(A){console.error(`❌ Failed to evaluate complex prop "${v}":`,A),console.error("Expression:",C.expression),console.error("Available context keys:",Object.keys(x)),n[v]=void 0}}),n}isFunctionExplicitlyPassed(e){const s=_.isSingleExpression(e);return s?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s.trim()):!1}findElementWithProps(e){const s=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const i of s){const n=this.elementProps.get(i);if(n&&n.size>0)return i}return null}pushComponent(e){this.componentStack.push(e)}popComponent(){return this.componentStack.pop()}getCurrentComponent(){return this.componentStack[this.componentStack.length-1]}buildComponentContext(e){if(!this.contextInvalidated.has(e)&&this.contextCache.has(e))return this.contextCache.get(e);const s=this.computeComponentContext(e);return this.contextCache.set(e,s),this.contextInvalidated.delete(e),s}computeComponentContext(e){const s={};e!=="app"&&window[e]&&Object.assign(s,window[e]),e==="app"&&window.app&&Object.assign(s,window.app);const i=this.componentFunctions.get(e);if(i)for(const[r,a]of i)s[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in s||(s[a]=o)}const n=this.stateManager.getState();for(const r of Object.keys(n))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in s||(s[a]=n[r])}if(e!=="app"){for(const r of Object.keys(n))if(r.startsWith("app.")){const a=r.substring(4);a in s||(s[a]=n[r])}}return s}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const i of this.contextInvalidated.keys())this.contextInvalidated.add(i);return}const s=e.indexOf(".");if(s!==-1){const i=e.slice(0,s);this.invalidateComponent(i)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const s=this.componentStack.length,i=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),n=e===document.body;if(i||n){if(i){this.pushComponent(i);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,n).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==i?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>s;)this.popComponent()}getParentComponent(e){let s=e.parentElement;for(;s;){const i=s.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(i)return i;s=s.parentElement}return"app"}getRelevantScripts(e,s){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(i=>{if(this.processedScripts.has(i))return!1;if(s)return i.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!i.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let n=i.parentElement;for(;n&&n!==e;){if(n.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;n=n.parentElement}return n===e||e.contains(i)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const s=this.getCurrentComponent(),i=e.textContent||"",n=_.decodeEntities(i);try{const r=this.findComponentElementForScript(e,s);if(r===e){const o=this.getParentComponent(e);this.setupProps(e,o)}const a=this.buildComponentContextWithProps(s,r);window[s]||(window[s]={}),this.executeScriptFunctions(n,s,a)}catch(r){console.error(`Script execution failed in component ${s}:`,r),console.error("Script content:",n)}}findComponentElementForScript(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let i=e.parentElement;for(;i;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return i;i=i.parentElement}const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const r of n)if(this.elementProps.has(r))return r;return n[0]||void 0}executeScriptFunctions(e,s,i){const n=this.extractFunctionNames(e),r=this.findElementWithProps(s),a=this.extractVariableDeclarations(e);let o={...i};if(a.forEach(x=>{delete o[x];const C=`set${Vt(x)}`,v=`${x}Getter`;delete o[C],delete o[v]}),r){const x=this.evaluateProps(r);Object.assign(o,x)}o.getContext=()=>this.buildComponentContextWithProps(s),o.withContext=x=>{const C=this.buildComponentContextWithProps(s);return x.call(C,C)},o.__getProp=x=>{if(r)return this.evaluateProps(r)[x]};let l=q.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,s,r||void 0);const h=`
17
17
  ${l}
18
18
 
19
19
  ${n.map(x=>`
@@ -28,7 +28,7 @@ Defaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=1
28
28
  `),o||c&&y.shouldBeDirectBinding(e,h.name)?s.set(h.name,f):c||s.set(h.name,f);continue}for(const v of x){const A=ws.validate(v,C);A.valid||(console.error(`
29
29
  ❌ Invalid expression in attribute "${h.name}":`),console.error(` Expression: ${v}`),console.error(` Original HTML: ${h.value}`),console.error(` Decoded: ${f}`),console.error(" Element:",e),console.error(` Component: ${C}`),A.errors.forEach(I=>{console.error(` ⚠️ ${I}`)}),console.error(" 💡 Hint: Check your quotes and syntax in conditional expressions"),console.error(` 💡 Example: class="{isActive ? 'text-blue-500' : 'text-gray-500'}"
30
30
  `)),A.warnings.length>0&&(console.warn(`
31
- ⚠️ Expression warnings in attribute "${h.name}":`),console.warn(` Expression: ${v}`),console.warn(" Element:",e),A.warnings.forEach(I=>{console.warn(` • ${I}`)}))}o||c&&y.shouldBeDirectBinding(e,h.name)?s.set(h.name,f):c||s.set(h.name,f)}}}return s}applyBindings(e,s,i,n){s.forEach((r,a)=>{this.createMustacheBinding(e,a,r)}),this.setupEventBindings(e,n)}applyBindingsFromCache(e,s,i){s.bindings.forEach((n,r)=>{try{const a=this.componentManager.buildComponentContextWithProps(s.component,e),o=this.templateRenderer.render(n,a,s.component);this.updateElementProperty(e,r,o)}catch(a){console.error(`Cached binding evaluation error for "${n}":`,a)}})}createMustacheBinding(e,s,i){const n=`mustache_${Date.now()}_${Math.random()}`;let r;const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(a&&this.componentManager?.hasStoredProps(e)){const f=this.componentManager.elementProps.get(e);(f?Array.from(f.keys()):[]).some(C=>i.includes(C))?r=a:r=y.getContextComponent(e)}else r=y.getContextComponent(e);e.removeAttribute(s);const o=new Set;this.templateRenderer.dependencies(i,r,this.stateManager).forEach(f=>o.add(f));const l=this.findComponentElementForMustacheBinding(e,r);l&&this.componentManager&&this.componentManager.getComponentPropDependencies(l,r).forEach(m=>o.add(m));const h=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const f=r===a?e:l||void 0,m=this.componentManager.buildComponentContextWithProps(r,f),x=this.templateRenderer.render(i,m,r);this.scheduleElementUpdate(e,s,x)}catch(f){console.error(`Mustache binding evaluation error for "${i}":`,f)}},p={id:n,selector:"",dependencies:o,callback:h,element:e,component:r};this.stateManager.addSubscription(p),h()}findComponentElementForMustacheBinding(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;n=n.parentElement}const r=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const a of r)if(this.componentManager&&this.componentManager.hasStoredProps(a))return a;return r[0]||null}setupEventBindings(e,s){for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];if(oe.isEventAttribute(n.name)){const r=n.name.substring(2),a=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,r,n.value,a),e.removeAttribute(n.name)}}}scheduleElementUpdate(e,s,i){if(this.isCriticalProperty(s)){this.updateElementProperty(e,s,i);return}this.updateQueue.has(e)||(this.updateQueue.set(e,new Set),this.batchedUpdates.add(e)),this.updateQueue.get(e).add(s),this.processingRAF||(this.processingRAF=requestAnimationFrame(()=>{this.processBatchedElementUpdates()})),e[`__pending_${s}`]=i}isCriticalProperty(e){return["textContent","innerHTML","value","checked","selected","disabled","class","className","style","hidden","display"].includes(e)}processBatchedElementUpdates(){this.applyingUpdates=!0;try{for(const e of this.batchedUpdates){const s=this.updateQueue.get(e);if(s)for(const i of s){const n=e[`__pending_${i}`];this.updateElementProperty(e,i,n),delete e[`__pending_${i}`]}}}finally{this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF=null,this.applyingUpdates=!1}}updateElementProperty(e,s,i){const n=this.lastValueCache.get(e);if(n&&this.isSameValue(n.get(s),i))return;const r=this.applyingUpdates;this.applyingUpdates=!0;try{switch(s){case"textContent":const a=this.cachedValueToString(i);e.textContent!==a&&(e.textContent=a);break;case"innerHTML":const o=this.cachedValueToString(i);e.innerHTML!==o&&(e.innerHTML=o);break;case"value":const c=this.cachedValueToString(i);e instanceof HTMLOptionElement?e.value!==c&&(e.value=c,e.setAttribute("value",c)):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.value!==c&&(e.value=c);break;case"selectedIndex":if(e instanceof HTMLSelectElement){const h=Number(i);e.selectedIndex!==h&&(e.selectedIndex=h)}break;case"checked":case"disabled":case"hidden":case"readonly":case"required":case"multiple":case"selected":case"autofocus":case"autoplay":case"controls":case"defer":case"loop":case"muted":case"open":case"reversed":case"async":case"default":case"formnovalidate":case"novalidate":case"allowfullscreen":case"capture":case"itemscope":this.setBooleanProperty(e,s,i);break;case"indeterminate":if(e instanceof HTMLInputElement&&e.type==="checkbox"){const h=!!i;e.indeterminate!==h&&(e.indeterminate=h)}break;case"class":case"className":const l=this.cachedValueToString(i);e instanceof SVGElement?e.getAttribute("class")!==l&&e.setAttribute("class",l):e.className!==l&&(e.className=l);break;case"htmlFor":case"for":if(e instanceof HTMLLabelElement){const h=this.cachedValueToString(i);e.htmlFor!==h&&(e.htmlFor=h)}break;case"style":if(e instanceof HTMLElement)if(typeof i=="object"&&i&&!Array.isArray(i))this.updateStyleObject(e,i);else{const h=this.cachedValueToString(i);e.style.cssText!==h&&(e.style.cssText=h)}break;case"tabIndex":if(e instanceof HTMLElement){const h=i==null?-1:Number(i);e.tabIndex!==h&&(e.tabIndex=h)}break;case"contentEditable":if(e instanceof HTMLElement){const h=i===!0?"true":i===!1?"false":String(i);e.contentEditable!==h&&(e.contentEditable=h)}break;case"draggable":if(e instanceof HTMLElement){const h=i===!0,p=h?"true":"false";e.draggable!==h&&(e.draggable=h,e.setAttribute("draggable",p))}break;case"spellcheck":if(e instanceof HTMLElement){const h=!!i,p=h?"true":"false";e.spellcheck!==h&&(e.spellcheck=h,e.setAttribute("spellcheck",p))}break;case"src":case"href":case"action":case"alt":case"title":case"placeholder":case"id":case"name":case"type":case"method":case"target":case"rel":case"pattern":case"accept":case"autocomplete":case"enctype":case"wrap":case"download":case"ping":case"referrerpolicy":case"crossorigin":case"integrity":case"loading":case"decoding":case"srcset":case"sizes":case"dir":case"lang":case"translate":case"role":this.setStringAttribute(e,s,i);break;case"min":case"max":case"step":case"maxLength":case"minLength":case"size":case"rows":case"cols":case"rowSpan":case"colSpan":this.setNumericAttribute(e,s,i);break;default:s.startsWith("aria-")?this.setAriaAttribute(e,s,i):s.startsWith("data-")?this.setDataAttribute(e,s,i):this.setGenericAttribute(e,s,i);break}this.updateValueCache(e,s,i)}catch(a){console.error(`Failed to update property "${s}" on element:`,e,a)}finally{this.applyingUpdates=r}}looksLikeSerializedObject(e){if(!e.startsWith("{")||!e.endsWith("}"))return!1;try{const s=JSON.parse(e);return typeof s=="object"&&s!==null&&!Array.isArray(s)&&Object.keys(s).length>0}catch{return!1}}cachedValueToString(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(e==null)return"";if(typeof e=="boolean")return e?"true":"false";if(this.stringValueCache.has(e))return this.stringValueCache.get(e);const s=ie(e);return this.stringValueCache.set(e,s),s}isSameValue(e,s){if(e===s)return!0;if(typeof e=="object"&&typeof s=="object"){if(e===null||s===null)return e===s;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((i,n)=>i===s[n]);if(this.isStyleObject(e)&&this.isStyleObject(s)){const i=Object.keys(e),n=Object.keys(s);return i.length===n.length&&i.every(r=>e[r]===s[r])}}return!1}isStyleObject(e){return e&&typeof e=="object"&&!Array.isArray(e)}setBooleanProperty(e,s,i){const n=!!i;this.setBooleanProp(e,s,i)||(n&&!e.hasAttribute(s)?e.setAttribute(s,""):!n&&e.hasAttribute(s)&&e.removeAttribute(s))}updateStyleObject(e,s){const i=this.lastValueCache.get(e)?.get("style"),n=i&&typeof i=="object"?i:{};for(const[r,a]of Object.entries(s))n[r]!==a&&(e.style[r]=a)}setStringAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setNumericAttribute(e,s,i){const n=String(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setAriaAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}setDataAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setGenericAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}updateValueCache(e,s,i){this.lastValueCache.has(e)||this.lastValueCache.set(e,new Map),this.lastValueCache.get(e).set(s,i)}setBooleanProp(e,s,i){const n=this.BOOL_REFLECTED[s];if(!n)return!1;const r=!!i;return e instanceof HTMLElement&&n in e?(e[n]!==r&&(e[n]=r),!0):(r?e.hasAttribute(s)||e.setAttribute(s,""):e.hasAttribute(s)&&e.removeAttribute(s),!0)}processPendingBindings(){const e=[...this.pendingBindings];this.pendingBindings=[];const s=new Map;for(const i of e)s.has(i.component)||s.set(i.component,[]),s.get(i.component).push(i);for(const[i,n]of s){const r=[...this.componentManager.componentStack];i!=="app"?this.componentManager.componentStack=["app",i]:this.componentManager.componentStack=["app"];for(const a of n)try{if(!document.contains(a.element))continue;this.createMustacheBinding(a.element,a.property,a.expression)}catch(o){console.error(`❌ Failed to create binding for ${i}:`,o)}this.componentManager.componentStack=r}this.processTextNodesPending()}processTextNodesPending(){const e=new Map;for(const s of this.pendingTextNodes)e.has(s.component)||e.set(s.component,[]),e.get(s.component).push(s);this.pendingTextNodes=[];for(const[s,i]of e){const n=[...this.componentManager.componentStack];s!=="app"?this.componentManager.componentStack=["app",s]:this.componentManager.componentStack=["app"];for(const{textNode:r,component:a}of i)if(document.contains(r))try{this.textNodeManager.processTextNode(r,a)}catch(o){console.error(`❌ Failed to process text node for ${a}:`,o)}this.componentManager.componentStack=n}}processMutationsBatch(e){const s=new Set,i=new Set,n=new Set,r=new Set;for(const a of e)if(a.type==="childList"&&(a.addedNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE)s.add(o);else if(o.nodeType===Node.TEXT_NODE){const c=o;c.textContent&&d.MUSTACHE_PATTERN.test(c.textContent)&&r.add(c)}}),a.removedNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE?i.add(o):o.nodeType===Node.TEXT_NODE&&this.textNodeManager.cleanupTextNode(o)})),a.type==="attributes"&&a.target&&n.add(a.target),a.type==="characterData"&&a.target){const o=a.target;o.textContent&&d.MUSTACHE_PATTERN.test(o.textContent)&&r.add(o)}i.size>0&&this.cleanupElementsBatch(Array.from(i)),s.size>0&&this.processElementsBatch(Array.from(s)),r.size>0&&this.processTextNodesBatch(Array.from(r)),n.size>0&&this.rebindChangedElements(Array.from(n))}processTextNodesBatch(e){const s=new Map;for(const i of e){const n=y.getComponentForNode(i);s.has(n)||s.set(n,[]),s.get(n).push(i)}for(const[i,n]of s)n.forEach(r=>{this.textNodeManager.processTextNode(r,i)})}rebindChangedElements(e){e.forEach(s=>{this.processElementBindings(s,!0)})}processElementBindings(e,s=!0){const i=this.extractDomMustacheBindings(e),n=y.getElementComponent(e);i.forEach((r,a)=>{s?this.createMustacheBinding(e,a,r):this.pendingBindings.push({element:e,property:a,expression:r,component:n})}),s&&this.setupEventBindings(e,n)}cleanupElementsBatch(e){e.forEach(s=>this.cleanupElement(s))}cleanupElement(e){this.cleanupRefBinding(e),this.stateManager.subscriptionManager?.cleanupElement(e);const s=this.listeners.get(e)||[];for(const{type:l,fn:h}of s)e.removeEventListener(l,h);this.listeners.delete(e),this.elementCache.delete(e),this.processedElements.delete(e),this.componentManager.cleanupProps(e);const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let n;for(;n=i.nextNode();)this.textNodeManager.cleanupTextNode(n);e.tagName==="TEMPLATE"&&e.hasAttribute("pp-for")&&this.loopManager.cleanupTemplate(e),e.querySelectorAll("template[pp-for]").forEach(l=>{this.loopManager.cleanupTemplate(l)});const a=e.__directEventListeners;a&&(a.forEach(({eventType:l,listener:h})=>{e.removeEventListener(l,h)}),delete e.__directEventListeners);const o=e.__spreadEventHandlers;o&&(o.forEach(l=>{window.__spreadHandlers&&window.__spreadHandlers.delete(l)}),delete e.__spreadEventHandlers);const c=e.__spreadSubscriptions;c&&(c.forEach(l=>{this.stateManager.removeSubscription(l)}),delete e.__spreadSubscriptions),this.lastValueCache.delete(e),this.stringValueCache.size()>1500&&this.stringValueCache.clear()}cleanupRefBinding(e){const s=this.refBindings.get(e);if(s){try{s.callback?s.callback(null):s.refObject&&(s.refObject.current=null)}catch(i){console.error("Failed to cleanup ref:",i)}this.refBindings.delete(e)}}getElementHash(e){const s=[];for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];(n.name===d.ATTR_PREFIXES.COMPONENT||oe.isEventAttribute(n.name)||n.value&&d.MUSTACHE_PATTERN.test(n.value))&&s.push(`${n.name}=${n.value}`)}return s.sort().join("|")}isCacheValid(e){return Date.now()-e.lastProcessed<3e4}refreshAllBindings(){this.elementCache=new WeakMap,this.processedElements=new WeakSet,this.processElement(document.body,!0)}destroy(){this.observer&&this.observer.disconnect(),document.querySelectorAll("[pp-ref]").forEach(s=>{this.cleanupRefBinding(s)}),this.eventDelegation.cleanup(),this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF&&cancelAnimationFrame(this.processingRAF),this.elementCache=new WeakMap,this.listeners=new WeakMap,this.processedElements=new WeakSet,this.loopManager.destroy()}}class se{static eventCache=null;delegatedEvents=new Map;elementHandlers=new WeakMap;handlerCache=new $(200);componentManager;expressionEvaluator;loopManager;setupEvents=new Set;static getAllAvailableEvents(){if(se.eventCache)return se.eventCache;const e=new Set,s=["click","input","change","submit","focus","blur","keydown","keyup","mousedown","mouseup","mouseover","mouseout"];try{Object.getOwnPropertyNames(HTMLElement.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get HTMLElement events:",n),s.forEach(r=>e.add(r))}try{Object.getOwnPropertyNames(Document.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Document events:",n)}try{Object.getOwnPropertyNames(Window.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Window events:",n)}try{Object.getOwnPropertyNames(Element.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Element events:",n)}return new Set(["beforeunload","unload","pagehide","pageshow","popstate","hashchange","storage","message","messageerror","offline","online","languagechange","rejectionhandled","unhandledrejection","afterprint","beforeprint","devicemotion","deviceorientation","deviceorientationabsolute"]).forEach(n=>e.delete(n)),se.eventCache=e,e}setupEventDelegation(){const e=["click","input","change","submit","focus","blur"];for(const s of e)this.ensureEventSetup(s)}getEventOptions(e){const s={capture:!0,passive:!1};return["wheel","touchstart","touchmove","touchend","scroll","mousewheel"].includes(e)&&(s.passive=!0),(e==="focusin"||e==="focusout")&&(s.capture=!1),s}isEventSupported(e){return se.getAllAvailableEvents().has(e.toLowerCase())}getAllSupportedEvents(){return Array.from(se.getAllAvailableEvents()).sort()}getDelegatedEvents(){return Array.from(this.delegatedEvents.keys()).sort()}setDependencies(e,s,i){this.componentManager=e,this.expressionEvaluator=s,this.loopManager=i}createDelegatedListener(e){return s=>{const i=s.target;if(!i)return;const n=this.findHandler(i,e);n&&this.executeHandler(n.handler,n.element,s)}}registerEventHandler(e,s,i,n){const r=s.toLowerCase();if(this.ensureEventSetup(r),!this.isEventSupported(r)){console.warn(`⚠️ Event type "${s}" is not supported`);return}const a=y.getContextComponent(e);this.elementHandlers.has(e)||this.elementHandlers.set(e,new Map);const o=this.elementHandlers.get(e),c={code:i,component:a};o.set(r,c);const l=this.delegatedEvents.get(r);l?l.elements.add(e):(console.warn(`⚠️ No delegated listener for ${r}, attaching directly`),this.attachDirectListener(e,r,c))}ensureEventSetup(e){if(!this.setupEvents.has(e)){if(!this.isEventSupported(e)){console.warn(`⚠️ Attempting to setup unsupported event: ${e}`);return}try{const s=this.createDelegatedListener(e),i=this.getEventOptions(e);document.addEventListener(e,s,i),this.setupEvents.add(e),this.delegatedEvents.set(e,{listener:s,elements:new WeakSet})}catch(s){console.error(`Failed to setup event delegation for ${e}:`,s),this.setupEvents.delete(e)}}}findHandler(e,s){let i=e;for(;i;){const n=this.elementHandlers.get(i);if(n?.has(s))return{handler:n.get(s),element:i};i=i.parentElement}return null}compileHandler(e,s){const i=`${s}:${e}`;if(this.handlerCache.has(i))return this.handlerCache.get(i);let n=e;e.includes("this")&&(n=n.replace(/\bthis\b/g,"thisElement")),e.includes("event")&&(n=n.replace(/\bevent\b/g,"eventObject"));const r=new Function("eventObject","thisElement","context",`
31
+ ⚠️ Expression warnings in attribute "${h.name}":`),console.warn(` Expression: ${v}`),console.warn(" Element:",e),A.warnings.forEach(I=>{console.warn(` • ${I}`)}))}o||c&&y.shouldBeDirectBinding(e,h.name)?s.set(h.name,f):c||s.set(h.name,f)}}}return s}applyBindings(e,s,i,n){s.forEach((r,a)=>{this.createMustacheBinding(e,a,r)}),this.setupEventBindings(e,n)}applyBindingsFromCache(e,s,i){s.bindings.forEach((n,r)=>{try{const a=this.componentManager.buildComponentContextWithProps(s.component,e),o=this.templateRenderer.render(n,a,s.component);this.updateElementProperty(e,r,o)}catch(a){console.error(`Cached binding evaluation error for "${n}":`,a)}})}createMustacheBinding(e,s,i){const n=`mustache_${Date.now()}_${Math.random()}`;let r;const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(a&&this.componentManager?.hasStoredProps(e)){const f=this.componentManager.elementProps.get(e);(f?Array.from(f.keys()):[]).some(C=>i.includes(C))?r=a:r=y.getContextComponent(e)}else r=y.getContextComponent(e);e.removeAttribute(s);const o=new Set;this.templateRenderer.dependencies(i,r,this.stateManager).forEach(f=>o.add(f));const l=this.findComponentElementForMustacheBinding(e,r);l&&this.componentManager&&this.componentManager.getComponentPropDependencies(l,r).forEach(m=>o.add(m));const h=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const f=r===a?e:l||void 0,m=this.componentManager.buildComponentContextWithProps(r,f),x=this.templateRenderer.render(i,m,r);this.scheduleElementUpdate(e,s,x)}catch(f){console.error(`Mustache binding evaluation error for "${i}":`,f)}},p={id:n,selector:"",dependencies:o,callback:h,element:e,component:r};this.stateManager.addSubscription(p),h()}findComponentElementForMustacheBinding(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;n=n.parentElement}const r=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const a of r)if(this.componentManager&&this.componentManager.hasStoredProps(a))return a;return r[0]||null}setupEventBindings(e,s){for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];if(oe.isEventAttribute(n.name)){const r=n.name.substring(2),a=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,r,n.value,a),e.removeAttribute(n.name)}}}scheduleElementUpdate(e,s,i){if(this.isCriticalProperty(s)){this.updateElementProperty(e,s,i);return}this.updateQueue.has(e)||(this.updateQueue.set(e,new Set),this.batchedUpdates.add(e)),this.updateQueue.get(e).add(s),this.processingRAF||(this.processingRAF=requestAnimationFrame(()=>{this.processBatchedElementUpdates()})),e[`__pending_${s}`]=i}isCriticalProperty(e){return["textContent","innerHTML","value","checked","selected","disabled","class","className","style","hidden","display"].includes(e)}processBatchedElementUpdates(){this.applyingUpdates=!0;try{for(const e of this.batchedUpdates){const s=this.updateQueue.get(e);if(s)for(const i of s){const n=e[`__pending_${i}`];this.updateElementProperty(e,i,n),delete e[`__pending_${i}`]}}}finally{this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF=null,this.applyingUpdates=!1}}updateElementProperty(e,s,i){const n=this.lastValueCache.get(e);if(n&&this.isSameValue(n.get(s),i))return;const r=this.applyingUpdates;this.applyingUpdates=!0;try{switch(s){case"textContent":const a=this.cachedValueToString(i);e.textContent!==a&&(e.textContent=a);break;case"innerHTML":const o=this.cachedValueToString(i);e.innerHTML!==o&&(e.innerHTML=o);break;case"value":const c=this.cachedValueToString(i);e instanceof HTMLOptionElement?e.value!==c&&(e.value=c,e.setAttribute("value",c)):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.value!==c&&(e.value=c);break;case"selectedIndex":if(e instanceof HTMLSelectElement){const h=Number(i);e.selectedIndex!==h&&(e.selectedIndex=h)}break;case"checked":case"disabled":case"hidden":case"readonly":case"required":case"multiple":case"selected":case"autofocus":case"autoplay":case"controls":case"defer":case"loop":case"muted":case"open":case"reversed":case"async":case"default":case"formnovalidate":case"novalidate":case"allowfullscreen":case"capture":case"itemscope":this.setBooleanProperty(e,s,i);break;case"indeterminate":if(e instanceof HTMLInputElement&&e.type==="checkbox"){const h=!!i;e.indeterminate!==h&&(e.indeterminate=h)}break;case"class":case"className":const l=this.cachedValueToString(i);e instanceof SVGElement?e.getAttribute("class")!==l&&e.setAttribute("class",l):e.className!==l&&(e.className=l);break;case"htmlFor":case"for":if(e instanceof HTMLLabelElement){const h=this.cachedValueToString(i);e.htmlFor!==h&&(e.htmlFor=h)}break;case"style":if(e instanceof HTMLElement)if(typeof i=="object"&&i&&!Array.isArray(i))this.updateStyleObject(e,i);else{const h=this.cachedValueToString(i);e.style.cssText!==h&&(e.style.cssText=h)}break;case"tabIndex":if(e instanceof HTMLElement){const h=i==null?-1:Number(i);e.tabIndex!==h&&(e.tabIndex=h)}break;case"contentEditable":if(e instanceof HTMLElement){const h=i===!0?"true":i===!1?"false":String(i);e.contentEditable!==h&&(e.contentEditable=h)}break;case"draggable":if(e instanceof HTMLElement){const h=i===!0,p=h?"true":"false";e.draggable!==h&&(e.draggable=h,e.setAttribute("draggable",p))}break;case"spellcheck":if(e instanceof HTMLElement){const h=!!i,p=h?"true":"false";e.spellcheck!==h&&(e.spellcheck=h,e.setAttribute("spellcheck",p))}break;case"src":case"href":case"action":case"alt":case"title":case"placeholder":case"id":case"name":case"type":case"method":case"target":case"rel":case"pattern":case"accept":case"autocomplete":case"enctype":case"wrap":case"download":case"ping":case"referrerpolicy":case"crossorigin":case"integrity":case"loading":case"decoding":case"srcset":case"sizes":case"dir":case"lang":case"translate":case"role":this.setStringAttribute(e,s,i);break;case"min":case"max":case"step":case"maxLength":case"minLength":case"size":case"rows":case"cols":case"rowSpan":case"colSpan":this.setNumericAttribute(e,s,i);break;default:s.startsWith("aria-")?this.setAriaAttribute(e,s,i):s.startsWith("data-")?this.setDataAttribute(e,s,i):this.setGenericAttribute(e,s,i);break}this.updateValueCache(e,s,i)}catch(a){console.error(`Failed to update property "${s}" on element:`,e,a)}finally{this.applyingUpdates=r}}looksLikeSerializedObject(e){if(!e.startsWith("{")||!e.endsWith("}"))return!1;try{const s=JSON.parse(e);return typeof s=="object"&&s!==null&&!Array.isArray(s)&&Object.keys(s).length>0}catch{return!1}}cachedValueToString(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(e==null)return"";if(typeof e=="boolean")return e?"true":"false";if(this.stringValueCache.has(e))return this.stringValueCache.get(e);const s=ie(e);return this.stringValueCache.set(e,s),s}isSameValue(e,s){if(e===s)return!0;if(typeof e=="object"&&typeof s=="object"){if(e===null||s===null)return e===s;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((i,n)=>i===s[n]);if(this.isStyleObject(e)&&this.isStyleObject(s)){const i=Object.keys(e),n=Object.keys(s);return i.length===n.length&&i.every(r=>e[r]===s[r])}}return!1}isStyleObject(e){return e&&typeof e=="object"&&!Array.isArray(e)}setBooleanProperty(e,s,i){const n=!!i;this.setBooleanProp(e,s,i)||(n&&!e.hasAttribute(s)?e.setAttribute(s,""):!n&&e.hasAttribute(s)&&e.removeAttribute(s))}updateStyleObject(e,s){const i=this.lastValueCache.get(e)?.get("style"),n=i&&typeof i=="object"?i:{};for(const[r,a]of Object.entries(s))n[r]!==a&&(e.style[r]=a)}setStringAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setNumericAttribute(e,s,i){const n=String(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setAriaAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}setDataAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setGenericAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}updateValueCache(e,s,i){this.lastValueCache.has(e)||this.lastValueCache.set(e,new Map),this.lastValueCache.get(e).set(s,i)}setBooleanProp(e,s,i){const n=this.BOOL_REFLECTED[s];if(!n)return!1;const r=!!i;return e instanceof HTMLElement&&n in e?(e[n]!==r&&(e[n]=r),!0):(r?e.hasAttribute(s)||e.setAttribute(s,""):e.hasAttribute(s)&&e.removeAttribute(s),!0)}processPendingBindings(){const e=[...this.pendingBindings];this.pendingBindings=[];const s=new Map;for(const i of e)s.has(i.component)||s.set(i.component,[]),s.get(i.component).push(i);for(const[i,n]of s){const r=[...this.componentManager.componentStack];i!=="app"?this.componentManager.componentStack=["app",i]:this.componentManager.componentStack=["app"];for(const a of n)try{if(!document.contains(a.element))continue;this.createMustacheBinding(a.element,a.property,a.expression)}catch(o){console.error(`❌ Failed to create binding for ${i}:`,o)}this.componentManager.componentStack=r}this.processTextNodesPending()}processTextNodesPending(){const e=new Map;for(const s of this.pendingTextNodes)e.has(s.component)||e.set(s.component,[]),e.get(s.component).push(s);this.pendingTextNodes=[];for(const[s,i]of e){const n=[...this.componentManager.componentStack];s!=="app"?this.componentManager.componentStack=["app",s]:this.componentManager.componentStack=["app"];for(const{textNode:r,component:a}of i)if(document.contains(r))try{this.textNodeManager.processTextNode(r,a)}catch(o){console.error(`❌ Failed to process text node for ${a}:`,o)}this.componentManager.componentStack=n}}processMutationsBatch(e){const s=new Set,i=new Set,n=new Set,r=new Set,a=new Set;for(const o of e)if(o.type==="childList"&&(o.addedNodes.forEach(c=>{if(c.nodeType===Node.ELEMENT_NODE)s.add(c);else if(c.nodeType===Node.TEXT_NODE){const l=c;l.textContent&&d.MUSTACHE_PATTERN.test(l.textContent)&&a.add(l)}}),o.removedNodes.forEach(c=>{if(c.nodeType===Node.ELEMENT_NODE)i.add(c);else if(c.nodeType===Node.TEXT_NODE){const l=c;l.textContent&&d.MUSTACHE_PATTERN.test(l.textContent)&&(document.contains(l)||this.textNodeManager.cleanupTextNode(l))}})),o.type==="attributes"&&o.target&&r.add(o.target),o.type==="characterData"&&o.target){const c=o.target;c.textContent&&d.MUSTACHE_PATTERN.test(c.textContent)&&a.add(c)}for(const o of i)(s.has(o)||document.contains(o))&&(n.add(o),i.delete(o),s.has(o)&&s.delete(o));i.size>0&&this.cleanupElementsBatch(Array.from(i)),s.size>0&&this.processElementsBatch(Array.from(s)),a.size>0&&this.processTextNodesBatch(Array.from(a)),r.size>0&&this.rebindChangedElements(Array.from(r))}processTextNodesBatch(e){const s=new Map;for(const i of e){const n=y.getComponentForNode(i);s.has(n)||s.set(n,[]),s.get(n).push(i)}for(const[i,n]of s)n.forEach(r=>{this.textNodeManager.processTextNode(r,i)})}rebindChangedElements(e){e.forEach(s=>{this.processElementBindings(s,!0)})}processElementBindings(e,s=!0){const i=this.extractDomMustacheBindings(e),n=y.getElementComponent(e);i.forEach((r,a)=>{s?this.createMustacheBinding(e,a,r):this.pendingBindings.push({element:e,property:a,expression:r,component:n})}),s&&this.setupEventBindings(e,n)}cleanupElementsBatch(e){e.forEach(s=>this.cleanupElement(s))}cleanupElement(e){this.cleanupRefBinding(e),this.stateManager.subscriptionManager?.cleanupElement(e);const s=this.listeners.get(e)||[];for(const{type:l,fn:h}of s)e.removeEventListener(l,h);this.listeners.delete(e),this.elementCache.delete(e),this.processedElements.delete(e),this.componentManager.cleanupProps(e);const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let n;for(;n=i.nextNode();)this.textNodeManager.cleanupTextNode(n);e.tagName==="TEMPLATE"&&e.hasAttribute("pp-for")&&this.loopManager.cleanupTemplate(e),e.querySelectorAll("template[pp-for]").forEach(l=>{this.loopManager.cleanupTemplate(l)});const a=e.__directEventListeners;a&&(a.forEach(({eventType:l,listener:h})=>{e.removeEventListener(l,h)}),delete e.__directEventListeners);const o=e.__spreadEventHandlers;o&&(o.forEach(l=>{window.__spreadHandlers&&window.__spreadHandlers.delete(l)}),delete e.__spreadEventHandlers);const c=e.__spreadSubscriptions;c&&(c.forEach(l=>{this.stateManager.removeSubscription(l)}),delete e.__spreadSubscriptions),this.lastValueCache.delete(e),this.stringValueCache.size()>1500&&this.stringValueCache.clear()}cleanupRefBinding(e){const s=this.refBindings.get(e);if(s){try{s.callback?s.callback(null):s.refObject&&(s.refObject.current=null)}catch(i){console.error("Failed to cleanup ref:",i)}this.refBindings.delete(e)}}getElementHash(e){const s=[];for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];(n.name===d.ATTR_PREFIXES.COMPONENT||oe.isEventAttribute(n.name)||n.value&&d.MUSTACHE_PATTERN.test(n.value))&&s.push(`${n.name}=${n.value}`)}return s.sort().join("|")}isCacheValid(e){return Date.now()-e.lastProcessed<3e4}refreshAllBindings(){this.elementCache=new WeakMap,this.processedElements=new WeakSet,this.processElement(document.body,!0)}destroy(){this.observer&&this.observer.disconnect(),document.querySelectorAll("[pp-ref]").forEach(s=>{this.cleanupRefBinding(s)}),this.eventDelegation.cleanup(),this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF&&cancelAnimationFrame(this.processingRAF),this.elementCache=new WeakMap,this.listeners=new WeakMap,this.processedElements=new WeakSet,this.loopManager.destroy()}}class se{static eventCache=null;delegatedEvents=new Map;elementHandlers=new WeakMap;handlerCache=new $(200);componentManager;expressionEvaluator;loopManager;setupEvents=new Set;static getAllAvailableEvents(){if(se.eventCache)return se.eventCache;const e=new Set,s=["click","input","change","submit","focus","blur","keydown","keyup","mousedown","mouseup","mouseover","mouseout"];try{Object.getOwnPropertyNames(HTMLElement.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get HTMLElement events:",n),s.forEach(r=>e.add(r))}try{Object.getOwnPropertyNames(Document.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Document events:",n)}try{Object.getOwnPropertyNames(Window.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Window events:",n)}try{Object.getOwnPropertyNames(Element.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Element events:",n)}return new Set(["beforeunload","unload","pagehide","pageshow","popstate","hashchange","storage","message","messageerror","offline","online","languagechange","rejectionhandled","unhandledrejection","afterprint","beforeprint","devicemotion","deviceorientation","deviceorientationabsolute"]).forEach(n=>e.delete(n)),se.eventCache=e,e}setupEventDelegation(){const e=["click","input","change","submit","focus","blur"];for(const s of e)this.ensureEventSetup(s)}getEventOptions(e){const s={capture:!0,passive:!1};return["wheel","touchstart","touchmove","touchend","scroll","mousewheel"].includes(e)&&(s.passive=!0),(e==="focusin"||e==="focusout")&&(s.capture=!1),s}isEventSupported(e){return se.getAllAvailableEvents().has(e.toLowerCase())}getAllSupportedEvents(){return Array.from(se.getAllAvailableEvents()).sort()}getDelegatedEvents(){return Array.from(this.delegatedEvents.keys()).sort()}setDependencies(e,s,i){this.componentManager=e,this.expressionEvaluator=s,this.loopManager=i}createDelegatedListener(e){return s=>{const i=s.target;if(!i)return;const n=this.findHandler(i,e);n&&this.executeHandler(n.handler,n.element,s)}}registerEventHandler(e,s,i,n){const r=s.toLowerCase();if(this.ensureEventSetup(r),!this.isEventSupported(r)){console.warn(`⚠️ Event type "${s}" is not supported`);return}const a=y.getContextComponent(e);this.elementHandlers.has(e)||this.elementHandlers.set(e,new Map);const o=this.elementHandlers.get(e),c={code:i,component:a};o.set(r,c);const l=this.delegatedEvents.get(r);l?l.elements.add(e):(console.warn(`⚠️ No delegated listener for ${r}, attaching directly`),this.attachDirectListener(e,r,c))}ensureEventSetup(e){if(!this.setupEvents.has(e)){if(!this.isEventSupported(e)){console.warn(`⚠️ Attempting to setup unsupported event: ${e}`);return}try{const s=this.createDelegatedListener(e),i=this.getEventOptions(e);document.addEventListener(e,s,i),this.setupEvents.add(e),this.delegatedEvents.set(e,{listener:s,elements:new WeakSet})}catch(s){console.error(`Failed to setup event delegation for ${e}:`,s),this.setupEvents.delete(e)}}}findHandler(e,s){let i=e;for(;i;){const n=this.elementHandlers.get(i);if(n?.has(s))return{handler:n.get(s),element:i};i=i.parentElement}return null}compileHandler(e,s){const i=`${s}:${e}`;if(this.handlerCache.has(i))return this.handlerCache.get(i);let n=e;e.includes("this")&&(n=n.replace(/\bthis\b/g,"thisElement")),e.includes("event")&&(n=n.replace(/\bevent\b/g,"eventObject"));const r=new Function("eventObject","thisElement","context",`
32
32
  try {
33
33
  with(context) {
34
34
  ${n}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.1.0-alpha.4",
3
+ "version": "4.1.0-alpha.5",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",