create-prisma-php-app 4.1.0-alpha.20 → 4.1.0-alpha.21

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: ${t}
14
14
  `),{endIndex:-1,expression:""}}static checkForMismatchedQuotes(e){let t=0,n=0,i=!1;for(let r=0;r<e.length;r++){if(i){i=!1;continue}if(e[r]==="\\"){i=!0;continue}e[r]==="'"&&t++,e[r]==='"'&&n++}return t%2!==0?{hasIssue:!0,message:`Unmatched single quotes (found ${t})`}:n%2!==0?{hasIssue:!0,message:`Unmatched double quotes (found ${n})`}:{hasIssue:!1,message:""}}static isSingleExpression(e){const t=N.decodeEntities(e),n=N.parseContentWithNesting(t);return n.length===1&&n[0].type==="expression"?n[0].expression:null}static extractExpressions(e){const t=N.decodeEntities(e),n=N.parseContentWithNesting(t),i=n.filter(r=>r.type==="expression").map(r=>r.expression).filter(r=>r);return n.some(r=>r.type==="expression")&&i.length===0&&(console.error(`
15
15
  ❌ Failed to extract expressions from content:`),console.error(` Content: ${e}`),console.error(` Parsed ${n.length} parts, but extracted 0 expressions`),console.error(` This usually means malformed mustache syntax
16
- `)),i}}class Os{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,t){this.expressionEvaluator=e,this.stateManager=t,this.cleanupObserver=new MutationObserver(n=>{this.cleanupDetachedNodes(n)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){const t=[];for(const n of e)n.type==="childList"&&n.removedNodes.forEach(i=>{if(i.nodeType===Node.TEXT_NODE)t.push(i);else if(i.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)t.push(a)}});Promise.resolve().then(()=>{t.forEach(n=>{document.contains(n)||this.cleanupTextNode(n)})})}processTextNode(e,t){if(this.textNodeBindings.has(e)||S.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const n=e.parentElement,i=n?S.getContextComponent(n):t,r=e.textContent||"",a=N.parse(r);if(!a.some(p=>p.type==="expression"))return;const c=this.resolveComponentRootForElement(e,i),l={originalContent:r,expressions:a,subscriptionIds:[],component:i,componentElement:c};a.filter(p=>p.type==="expression").forEach(p=>{if(!p.expression)return;const h=`text_${Date.now()}_${Math.random()}`,f=this.expressionEvaluator.extractDependencies(p.expression,i,this.stateManager);if(c&&this.componentManager){const m=this.componentManager.getComponentPropDependencies(c,i);f.push(...m)}const x={id:h,selector:"",dependencies:new Set(f),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:i};this.stateManager.addSubscription(x),l.subscriptionIds.push(h)}),this.textNodeBindings.set(e,l),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let t=e.parentElement;for(;t&&t!==document.body;){const n=t.previousSibling;if(n&&n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:"))return!0;let i=t.parentElement?.firstChild||null;for(;i;){if(i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:")&&i!==t)return!0;i=i.nextSibling}t=t.parentElement}return!1}updateTextNode(e){const t=this.textNodeBindings.get(e);if(!t||!e.parentElement)return;const n=t.component;let i=t.componentElement;(!i||!document.contains(i))&&(i=this.resolveComponentRootForElement(e,n),t.componentElement=i);const r=this.hasInheritedContext(e,n);let a;if(r)i?a=this.getFreshComponentContext(n,i):a=this.getContextForComponent(n,i);else if(this.componentManager){if(a=this.componentManager.buildRestrictedComponentContext(n,!1),i&&this.componentManager.hasStoredProps(i)){const h=this.componentManager.evaluateProps(i);Object.assign(a,h)}const c=t.expressions.filter(h=>h.type==="expression").map(h=>h.expression).filter(h=>h),p=this.extractVariableNames(c).filter(h=>!(h in a));if(p.length>0){const h=this.findVariablesInParentComponents(e,n,p);Object.keys(h).length>0?Object.assign(a,h):console.warn("⚠️ [TextNode Update] Could not find missing variables in parent components")}}else a={};let o="";for(const c of t.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,n);o+=ue(l)}catch(l){const p=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.error(`❌ Text binding evaluation error for "${c.expression}": ${p}`),console.error(" Available context:",Object.keys(a)),console.error(" Component:",n),console.error(" Text node parent:",e.parentElement?.tagName),o+=""}e.textContent!==o&&(e.textContent=o)}extractVariableNames(e){const t=new Set;for(const n of e)try{const i=j(n,{ecmaVersion:2022,sourceType:"script"});W(i,{Identifier:(r,a)=>{const o=a?.[a.length-1];o?.type==="MemberExpression"&&o.property===r&&!o.computed||ge.has(r.name)||t.add(r.name)}})}catch{console.warn("Failed to parse expression for variable extraction:",n)}return Array.from(t)}findVariablesInParentComponents(e,t,n){const i={};if(!this.componentManager)return i;let r=e.parentElement;const a=new Set([t]);for(;r&&r!==document.body;){const o=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(o&&!a.has(o)){a.add(o);const c=this.componentManager.buildComponentContextWithProps(o,r);for(const l of n)l in c&&!(l in i)&&(i[l]=c[l]);if(Object.keys(i).length===n.length)break}r=r.parentElement}if(Object.keys(i).length<n.length){const o=this.componentManager.buildComponentContext("app");for(const c of n)c in o&&!(c in i)&&(i[c]=o[c])}return i}hasInheritedContext(e,t){const n=e.parentElement;if(n?.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;let i=n;for(;i&&i!==document.body;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t){if(i.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;break}i=i.parentElement}for(i=n;i&&i!==document.body;){const r=i.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(r&&r!==t&&i.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;i=i.parentElement}return!1}getFreshComponentContext(e,t){return this.componentManager?(this.componentManager.contextInvalidated.add(e),this.componentManager.contextCache.delete(e),this.componentManager.buildComponentContextWithProps(e,t)):{}}resolveComponentRootForElement(e,t){const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);if(this.componentManager){for(const i of n)if(this.componentManager.hasStoredProps(i))return i}return n[0]||void 0}getContextForComponent(e,t){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,t):{}}cleanupTextNode(e){const t=this.textNodeBindings.get(e);t&&(t.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)}),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 Rs{listeners=new Map;on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Ls{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new Rs;contextCache=new Map;previousValues=new Map;_subscriptionManager=new Is;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}clearSubscriptions(){const e=this._subscriptionManager.getAllSubscriptions();for(const[t]of e)this._subscriptionManager.removeSubscription(t);this.updateQueue.clear()}clearComponentSubscriptions(e){const t=this._subscriptionManager.getAllSubscriptions();for(const[n,i]of t)i.component===e&&this._subscriptionManager.removeSubscription(n)}clearState(){Object.keys(this.stateStore).forEach(e=>{delete this.stateStore[e],delete this.originalStateStore[e]}),this.previousValues.clear(),this.updateQueue.clear(),this.contextCache.clear()}clearComponentState(e){Object.keys(this.stateStore).filter(n=>n.startsWith(`${e}.`)).forEach(n=>{delete this.stateStore[n],delete this.originalStateStore[n],this.previousValues.delete(n)})}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const t=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,t.forEach(n=>{try{n()}catch(i){console.error("DOM update callback error:",i)}})})}))}setInitialState(e,t){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=t,this.previousValues.size>100){const n=this.previousValues.keys().next().value;typeof n=="string"&&this.previousValues.delete(n)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!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,t,n,i)=>{const r=e[t],a=Reflect.set(e,t,n,i);return r!==n&&this.notifySubscribers(t),a},get:(e,t)=>Reflect.get(e,t)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const t=e.split(".")[0];this.updateQueue.add(t)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const t=this.stateStore[e],n=this.previousValues?.get(e);for(const[i,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(n,o),l=this.getPathValue(t,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,t){if(!e||typeof e!="object")return;const n=t.split(".");let i=e;for(const r of n){if(i==null)return;if(Array.isArray(i))return r==="length"?i.length:i.map(a=>a?.[r]).filter(a=>a!==void 0);i=i[r]}return i}deepEqual(e,t){if(e===t)return!0;if(e==null||t==null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((n,i)=>this.deepEqual(n,t[i]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),i=Object.keys(t);return n.length!==i.length?!1:n.every(r=>this.deepEqual(e[r],t[r]))}return!1}scheduleFlush=_s(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,t=this.subscriptionManager.getSubscriptionsForKey("*");if(t&&t.size>0&&this.updateQueue.size>0)for(const n of t){const i=this.subscriptionManager.getSubscription(n);if(!i)continue;if(i.element&&!document.contains(i.element)){this.subscriptionManager.removeSubscription(n);continue}const r=i.element??document.body;try{const a=Array.from(this.updateQueue)[0];i.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const n of this.updateQueue){if(e.has(n))continue;e.add(n);const i=this.subscriptionManager.getSubscriptionsForKey(n);if(i)for(const r of i){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:n})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,t){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=t,this.previousValues.size>100){const n=this.previousValues.keys().next().value;typeof n=="string"&&this.previousValues.delete(n)}}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 t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,t=this.subscriptionManager.getAllSubscriptions();for(const[n,i]of t)for(const r of i.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(n);return e}destroy(){this.clearState(),this.clearSubscriptions(),this.contextCache.clear(),this.previousValues.clear(),this.domUpdateCallbacks=[]}}class me{expressionCache=new z(d.MAX_CACHE_SIZE);dependencyCache=new z(d.MAX_CACHE_SIZE);commonExpressionsCache=new z(100);dependencyParser=new Fs;static CACHE_KEYS={EXPRESSION:(e,t)=>`expr:${e}:${t}`,DEPENDENCY:(e,t)=>`deps:${e}:${t}`,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(t=>{const n={fn:new Function("return "+t),contextMap:new Map,dependencies:[t],timestamp:Date.now(),hitCount:0},i=me.CACHE_KEYS.COMMON(t);this.commonExpressionsCache.set(i,n)})}extractDependencies(e,t,n){const i=this.normalizeExpression(e),r=me.CACHE_KEYS.DEPENDENCY(t,i);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(i,t,n),this.dependencyCache.set(r,a),a)}evaluateExpression(e,t,n){const i=this.normalizeExpression(e),r=me.CACHE_KEYS.COMMON(i);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${i}"`,c);return}}const o=me.CACHE_KEYS.EXPRESSION(n,i);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(i,t,n),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,t);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${i}"`,c),console.error("Available context:",Object.keys(t));return}}compileExpression(e,t,n){const i=this.prepareSafeContext(t),r=new Map,a=[];Object.keys(i).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,n);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,t){const n=new Array(e.size);for(const[i,r]of e)n[r]=t[i];return n}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const t={};for(const[n,i]of Object.entries(e))ge.has(n)||!this.isValidJavaScriptIdentifier(n)||(t[n]=i);return t}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!ge.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(n=>{const i=this.expressionCache.get(n);i&&this.isStale(i)&&(this.expressionCache.delete(n),e++)}),e}}class Fs{parseCache=new z(500);extract(e,t,n){const i=this.normalizeExpression(e),r=`${t}:${i}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(i,t,n);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,t,n){const i=this.extractIdentifiers(e),r=[],a=n?.getState()||{};for(const c of i){if(ge.has(c))continue;const l=c.indexOf("."),p=l===-1?c:c.substring(0,l),h=He.findExistingStateKey(p,t,a);if(h)r.push(h);else{const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}if(l!==-1){const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const t=[];let n=0;for(;n<e.length;){const i=e[n];if(i==="'"){n=this.skipString(e,n,"'");continue}if(i==='"'){n=this.skipString(e,n,'"');continue}if(i==="`"){n=this.skipTemplateLiteral(e,n,t);continue}if(this.isIdentifierStart(i)){const r=this.extractIdentifier(e,n);t.push(r.value),n=r.endIndex;continue}n++}return t}skipString(e,t,n){let i=t+1;for(;i<e.length&&e[i]!==n;)e[i]==="\\"&&i++,i++;return i+1}skipTemplateLiteral(e,t,n){let i=t+1;for(;i<e.length&&e[i]!=="`";){if(e[i]==="$"&&i+1<e.length&&e[i+1]==="{"){i+=2;let r=1;for(;i<e.length&&r>0;){const a=e[i];if(a==='"'||a==="'"){i=this.skipString(e,i,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,i);n.push(o.value),i=o.endIndex-1}i++}continue}e[i]==="\\"&&i++,i++}return i+1}extractIdentifier(e,t){let n=t;for(;n<e.length&&(this.isIdentifierPart(e[n])||e[n]===".");)n++;return{value:e.substring(t,n),endIndex:n}}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 Vs{componentStack=["app"];elementProps=new WeakMap;contextCache=new z(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new it;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new it,this.stateManager.onStateChange(t=>this.invalidateContextCache(t))}getPropDependencies(e,t){const n=this.findElementWithProps(t);if(!n)return[];const i=this.elementProps.get(n);if(!i||!i.has(e))return[];const r=i.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,t=!1){const n={};window[e]&&Object.assign(n,window[e]);const i=this.componentFunctions.get(e);if(i)for(const[a,o]of i)n[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 n||(n[o]=r[a])}if(t){if(window.app)for(const[o,c]of Object.entries(window.app))o in n||(n[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in n||(n[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in n||(n[c]=r[o])}}return n}getComponentPropDependencies(e,t){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const n=[],i=this.elementProps.get(e);i&&this.templateRenderer&&i.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);n.push(...o??[])});const r=Array.from(new Set(n));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 Ye(e),this.loopManager=new jt(this.stateManager,e)}extractProps(e,t){const n=new Map,i=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=t;r&&(r==="app"?o="app":r==="parent"?o=S.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<i.length;c++){const l=i[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)&&!de.isEventAttribute(l.name)&&l.value&&Ms.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const p=this.attributeToPropName(l.name),h={name:p,expression:l.value,component:o,subscriptionIds:[]};n.set(p,h)}}return n}mightReferenceSelfProps(e,t){const n=this.elementProps.get(t);if(!n)return!1;const i=Array.from(n.keys()),r=N.extractExpressions(e);if(r.length===0)return!1;for(const a of r)try{const o=j(a,{ecmaVersion:2022,sourceType:"script"}),c=new Set,l=new Set;W(o,{Identifier:(p,h)=>{const f=h?.[h.length-1];f?.type==="MemberExpression"&&f.property===p&&!f.computed||(f?.type==="FunctionExpression"||f?.type==="ArrowFunctionExpression")&&(f.params||[]).includes(p)||(f?.type==="MemberExpression"&&f.object===p?l.add(p.name):c.add(p.name))}});for(const p of i){if(p==="dataState")continue;const h=c.has(p),f=l.has(p)&&!c.has(p);if(h&&!f)return!0}}catch(o){console.error(`❌ Failed to parse mustache expression "${a}":`,o);continue}return!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}setupProps(e,t){const n=this.extractProps(e,t);n.size!==0&&(this.elementProps.set(e,n),this.expressionEvaluator&&n.forEach((i,r)=>{this.setupPropBinding(e,i)}))}setupPropBinding(e,t){if(!this.expressionEvaluator)return;const n=`prop_${Date.now()}_${Math.random()}`,i=this.templateRenderer?.dependencies(t.expression,t.component,this.stateManager)||[],r={id:n,selector:"",dependencies:new Set(i),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:t.component};this.stateManager.addSubscription(r),t.subscriptionIds.push(n)}refreshComponentBindings(e,t){this.contextInvalidated.add(t),this.contextCache.delete(t),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,t)}evaluateProps(e){const t={},n=this.elementProps.get(e);if(!n||!this.expressionEvaluator)return t;const i=n.values().next().value;if(!i)return t;const r=this.buildComponentContext(i.component);return n.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?t[o]=(...l)=>c.apply(this,l):t[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),t[o]=void 0}}),t}cleanupProps(e){const t=this.elementProps.get(e);t&&(t.forEach(n=>{n.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,t){const n=this.buildComponentContext(e);let i=this.findElementWithProps(e);if(t&&this.elementProps.has(t)&&(i=t),i)try{const r=this.evaluatePropsWithContext(i,e,t);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{n[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return n}evaluatePropsWithContext(e,t,n){const i={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return i;const a=r.values().next().value;if(!a)return i;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 b=S.getParentOfComponent(l||"app",e);o=this.buildComponentContext(b)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const p=this.loopManager?.getLoopContextForElement(e);p&&(o={...o,...p});const h=new Map,f=new Map,x=Array.from(r.keys());r.forEach((b,g)=>{x.some(A=>A!==g&&b.expression.includes(A))?f.set(g,b):h.set(g,b)}),h.forEach((b,g)=>{try{const C=this.templateRenderer?.render(b.expression,o,c||b.component);typeof C=="function"?this.isFunctionExplicitlyPassed(b.expression)?i[g]=(...k)=>C.apply(this,k):(console.warn(`⚠️ Function "${g}" not passed - not from shared namespace or explicitly passed`),i[g]=void 0):i[g]=C}catch(C){console.error(`❌ Failed to evaluate simple prop "${g}":`,C),console.error("Expression:",b.expression),console.error("Available context keys:",Object.keys(o)),i[g]=void 0}});const m={...o,...i};return f.forEach((b,g)=>{try{const C=this.templateRenderer?.render(b.expression,m,c||b.component);typeof C=="function"?this.isFunctionExplicitlyPassed(b.expression)?i[g]=(...k)=>C.apply(this,k):(console.warn(`⚠️ Function "${g}" not passed - not from shared namespace or explicitly passed`),i[g]=void 0):i[g]=C}catch(C){console.error(`❌ Failed to evaluate complex prop "${g}":`,C),console.error("Expression:",b.expression),console.error("Available context keys:",Object.keys(m)),i[g]=void 0}}),i}isFunctionExplicitlyPassed(e){const t=N.isSingleExpression(e);return t?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t.trim()):!1}findElementWithProps(e){const t=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const n of t){const i=this.elementProps.get(n);if(i&&i.size>0)return n}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 t=this.computeComponentContext(e);return this.contextCache.set(e,t),this.contextInvalidated.delete(e),t}computeComponentContext(e){const t={};if(e.includes("_loop_")||e.match(/_[a-zA-Z0-9]{8}$/)){const r=e.split("_");r.pop();const a=r.join("_");window[a]&&Object.assign(t,window[a])}e!=="app"&&window[e]&&Object.assign(t,window[e]),e==="app"&&window.app&&Object.assign(t,window.app);const n=this.componentFunctions.get(e);if(n)for(const[r,a]of n)t[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in t||(t[a]=o);if(window.app)for(const[a,o]of Object.entries(window.app))a in t||(t[a]=o)}const i=this.stateManager.getState();for(const r of Object.keys(i))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in t||(t[a]=i[r])}if(e!=="app"){for(const r of Object.keys(i))if(r.startsWith("app.")){const a=r.substring(4);a in t||(t[a]=i[r])}}return t}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const n of this.contextInvalidated.keys())this.contextInvalidated.add(n);return}const t=e.indexOf(".");if(t!==-1){const n=e.slice(0,t);this.invalidateComponent(n)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const t=this.componentStack.length,n=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),i=e===document.body;if(n||i){if(n){this.pushComponent(n);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,i).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==n?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>t;)this.popComponent()}getParentComponent(e){let t=e.parentElement;for(;t;){const n=t.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(n)return n;t=t.parentElement}return"app"}getRelevantScripts(e,t){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(n=>{if(this.processedScripts.has(n))return!1;if(t)return n.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!n.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let i=n.parentElement;for(;i&&i!==e;){if(i.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;i=i.parentElement}return i===e||e.contains(n)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const t=this.getCurrentComponent(),n=e.textContent||"",i=N.decodeEntities(n);try{const r=this.findComponentElementForScript(e,t);if(r===e){const o=this.getParentComponent(e);this.setupProps(e,o)}const a=this.buildComponentContextWithProps(t,r);window[t]||(window[t]={}),this.executeScriptFunctions(i,t,a)}catch(r){console.error(`Script execution failed in component ${t}:`,r),console.error("Script content:",i)}}findComponentElementForScript(e,t){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return n;n=n.parentElement}const i=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);for(const r of i)if(this.elementProps.has(r))return r;return i[0]||void 0}executeScriptFunctions(e,t,n){const i=this.extractFunctionNames(e),r=this.findElementWithProps(t),a=this.extractVariableDeclarations(e);let o={...n};if(a.forEach(m=>{delete o[m];const b=`set${$t(m)}`,g=`${m}Getter`;delete o[b],delete o[g]}),r){const m=this.evaluateProps(r);Object.assign(o,m)}o.getContext=()=>this.buildComponentContextWithProps(t),o.withContext=m=>{const b=this.buildComponentContextWithProps(t);return m.call(b,b)},o.__getProp=m=>{if(r)return this.evaluateProps(r)[m]};let l=Z.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,t,r||void 0);const p=`
16
+ `)),i}}class Os{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,t){this.expressionEvaluator=e,this.stateManager=t,this.cleanupObserver=new MutationObserver(n=>{this.cleanupDetachedNodes(n)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){const t=[];for(const n of e)n.type==="childList"&&n.removedNodes.forEach(i=>{if(i.nodeType===Node.TEXT_NODE)t.push(i);else if(i.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(i,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)t.push(a)}});Promise.resolve().then(()=>{t.forEach(n=>{document.contains(n)||this.cleanupTextNode(n)})})}processTextNode(e,t){if(this.textNodeBindings.has(e)||S.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const n=e.parentElement,i=n?S.getContextComponent(n):t,r=e.textContent||"",a=N.parse(r);if(!a.some(p=>p.type==="expression"))return;const c=this.resolveComponentRootForElement(e,i),l={originalContent:r,expressions:a,subscriptionIds:[],component:i,componentElement:c};a.filter(p=>p.type==="expression").forEach(p=>{if(!p.expression)return;const h=`text_${Date.now()}_${Math.random()}`,f=this.expressionEvaluator.extractDependencies(p.expression,i,this.stateManager);if(c&&this.componentManager){const m=this.componentManager.getComponentPropDependencies(c,i);f.push(...m)}const x={id:h,selector:"",dependencies:new Set(f),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:i};this.stateManager.addSubscription(x),l.subscriptionIds.push(h)}),this.textNodeBindings.set(e,l),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let t=e.parentElement;for(;t&&t!==document.body;){const n=t.previousSibling;if(n&&n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:"))return!0;let i=t.parentElement?.firstChild||null;for(;i;){if(i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:")&&i!==t)return!0;i=i.nextSibling}t=t.parentElement}return!1}updateTextNode(e){const t=this.textNodeBindings.get(e);if(!t||!e.parentElement)return;const n=t.component;let i=t.componentElement;(!i||!document.contains(i))&&(i=this.resolveComponentRootForElement(e,n),t.componentElement=i);const r=this.hasInheritedContext(e,n);let a;if(r)i?a=this.getFreshComponentContext(n,i):a=this.getContextForComponent(n,i);else if(this.componentManager){if(a=this.componentManager.buildRestrictedComponentContext(n,!1),i&&this.componentManager.hasStoredProps(i)){const h=this.componentManager.evaluateProps(i);Object.assign(a,h)}const c=t.expressions.filter(h=>h.type==="expression").map(h=>h.expression).filter(h=>h),p=this.extractVariableNames(c).filter(h=>!(h in a));if(p.length>0){const h=this.findVariablesInParentComponents(e,n,p);Object.keys(h).length>0?Object.assign(a,h):console.warn("⚠️ [TextNode Update] Could not find missing variables in parent components")}}else a={};let o="";for(const c of t.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,n);o+=ue(l)}catch(l){const p=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.error(`❌ Text binding evaluation error for "${c.expression}": ${p}`),console.error(" Available context:",Object.keys(a)),console.error(" Component:",n),console.error(" Text node parent:",e.parentElement?.tagName),o+=""}e.textContent!==o&&(e.textContent=o)}extractVariableNames(e){const t=new Set;for(const n of e)try{const i=j(n,{ecmaVersion:2022,sourceType:"script"});W(i,{Identifier:(r,a)=>{const o=a?.[a.length-1];o?.type==="MemberExpression"&&o.property===r&&!o.computed||ge.has(r.name)||t.add(r.name)}})}catch{console.warn("Failed to parse expression for variable extraction:",n)}return Array.from(t)}findVariablesInParentComponents(e,t,n){const i={};if(!this.componentManager)return i;let r=e.parentElement;const a=new Set([t]);for(;r&&r!==document.body;){const o=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(o&&!a.has(o)){a.add(o);const c=this.componentManager.buildComponentContextWithProps(o,r);for(const l of n)l in c&&!(l in i)&&(i[l]=c[l]);if(Object.keys(i).length===n.length)break}r=r.parentElement}if(Object.keys(i).length<n.length){const o=this.componentManager.buildComponentContext("app");for(const c of n)c in o&&!(c in i)&&(i[c]=o[c])}return i}hasInheritedContext(e,t){const n=e.parentElement;if(n?.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;let i=n;for(;i&&i!==document.body;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t){if(i.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;break}i=i.parentElement}for(i=n;i&&i!==document.body;){const r=i.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(r&&r!==t&&i.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;i=i.parentElement}return!1}getFreshComponentContext(e,t){return this.componentManager?(this.componentManager.contextInvalidated.add(e),this.componentManager.contextCache.delete(e),this.componentManager.buildComponentContextWithProps(e,t)):{}}resolveComponentRootForElement(e,t){const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);if(this.componentManager){for(const i of n)if(this.componentManager.hasStoredProps(i))return i}return n[0]||void 0}getContextForComponent(e,t){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,t):{}}cleanupTextNode(e){const t=this.textNodeBindings.get(e);t&&(t.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)}),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 Rs{listeners=new Map;on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,...t){const n=this.listeners.get(e);n&&n.forEach(i=>{try{i(...t)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Ls{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new Rs;contextCache=new Map;previousValues=new Map;_subscriptionManager=new Is;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}clearSubscriptions(){const e=this._subscriptionManager.getAllSubscriptions();for(const[t]of e)this._subscriptionManager.removeSubscription(t);this.updateQueue.clear()}clearComponentSubscriptions(e){const t=this._subscriptionManager.getAllSubscriptions();for(const[n,i]of t)i.component===e&&this._subscriptionManager.removeSubscription(n)}clearState(){Object.keys(this.stateStore).forEach(e=>{delete this.stateStore[e],delete this.originalStateStore[e]}),this.previousValues.clear(),this.updateQueue.clear(),this.contextCache.clear()}clearComponentState(e){Object.keys(this.stateStore).filter(n=>n.startsWith(`${e}.`)).forEach(n=>{delete this.stateStore[n],delete this.originalStateStore[n],this.previousValues.delete(n)})}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const t=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,t.forEach(n=>{try{n()}catch(i){console.error("DOM update callback error:",i)}})})}))}setInitialState(e,t){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=t,this.previousValues.size>100){const n=this.previousValues.keys().next().value;typeof n=="string"&&this.previousValues.delete(n)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!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,t,n,i)=>{const r=e[t],a=Reflect.set(e,t,n,i);return r!==n&&this.notifySubscribers(t),a},get:(e,t)=>Reflect.get(e,t)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const t=e.split(".")[0];this.updateQueue.add(t)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const t=this.stateStore[e],n=this.previousValues?.get(e);for(const[i,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(n,o),l=this.getPathValue(t,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,t){if(!e||typeof e!="object")return;const n=t.split(".");let i=e;for(const r of n){if(i==null)return;if(Array.isArray(i))return r==="length"?i.length:i.map(a=>a?.[r]).filter(a=>a!==void 0);i=i[r]}return i}deepEqual(e,t){if(e===t)return!0;if(e==null||t==null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((n,i)=>this.deepEqual(n,t[i]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),i=Object.keys(t);return n.length!==i.length?!1:n.every(r=>this.deepEqual(e[r],t[r]))}return!1}scheduleFlush=_s(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,t=this.subscriptionManager.getSubscriptionsForKey("*");if(t&&t.size>0&&this.updateQueue.size>0)for(const n of t){const i=this.subscriptionManager.getSubscription(n);if(!i)continue;if(i.element&&!document.contains(i.element)){this.subscriptionManager.removeSubscription(n);continue}const r=i.element??document.body;try{const a=Array.from(this.updateQueue)[0];i.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const n of this.updateQueue){if(e.has(n))continue;e.add(n);const i=this.subscriptionManager.getSubscriptionsForKey(n);if(i)for(const r of i){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:n})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,t){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=t,this.previousValues.size>100){const n=this.previousValues.keys().next().value;typeof n=="string"&&this.previousValues.delete(n)}}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 t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,t=this.subscriptionManager.getAllSubscriptions();for(const[n,i]of t)for(const r of i.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(n);return e}destroy(){this.clearState(),this.clearSubscriptions(),this.contextCache.clear(),this.previousValues.clear(),this.domUpdateCallbacks=[]}}class me{expressionCache=new z(d.MAX_CACHE_SIZE);dependencyCache=new z(d.MAX_CACHE_SIZE);commonExpressionsCache=new z(100);dependencyParser=new Fs;static CACHE_KEYS={EXPRESSION:(e,t)=>`expr:${e}:${t}`,DEPENDENCY:(e,t)=>`deps:${e}:${t}`,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(t=>{const n={fn:new Function("return "+t),contextMap:new Map,dependencies:[t],timestamp:Date.now(),hitCount:0},i=me.CACHE_KEYS.COMMON(t);this.commonExpressionsCache.set(i,n)})}extractDependencies(e,t,n){const i=this.normalizeExpression(e),r=me.CACHE_KEYS.DEPENDENCY(t,i);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(i,t,n),this.dependencyCache.set(r,a),a)}evaluateExpression(e,t,n){const i=this.normalizeExpression(e),r=me.CACHE_KEYS.COMMON(i);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${i}"`,c);return}}const o=me.CACHE_KEYS.EXPRESSION(n,i);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(i,t,n),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,t);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${i}"`,c),console.error("Available context:",Object.keys(t));return}}compileExpression(e,t,n){const i=this.prepareSafeContext(t),r=new Map,a=[];Object.keys(i).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,n);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,t){const n=new Array(e.size);for(const[i,r]of e)n[r]=t[i];return n}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const t={};for(const[n,i]of Object.entries(e))ge.has(n)||!this.isValidJavaScriptIdentifier(n)||(t[n]=i);return t}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!ge.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(n=>{const i=this.expressionCache.get(n);i&&this.isStale(i)&&(this.expressionCache.delete(n),e++)}),e}}class Fs{parseCache=new z(500);extract(e,t,n){const i=this.normalizeExpression(e),r=`${t}:${i}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(i,t,n);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,t,n){const i=this.extractIdentifiers(e),r=[],a=n?.getState()||{};for(const c of i){if(ge.has(c))continue;const l=c.indexOf("."),p=l===-1?c:c.substring(0,l),h=He.findExistingStateKey(p,t,a);if(h)r.push(h);else{const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}if(l!==-1){const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const t=[];let n=0;for(;n<e.length;){const i=e[n];if(i==="'"){n=this.skipString(e,n,"'");continue}if(i==='"'){n=this.skipString(e,n,'"');continue}if(i==="`"){n=this.skipTemplateLiteral(e,n,t);continue}if(this.isIdentifierStart(i)){const r=this.extractIdentifier(e,n);t.push(r.value),n=r.endIndex;continue}n++}return t}skipString(e,t,n){let i=t+1;for(;i<e.length&&e[i]!==n;)e[i]==="\\"&&i++,i++;return i+1}skipTemplateLiteral(e,t,n){let i=t+1;for(;i<e.length&&e[i]!=="`";){if(e[i]==="$"&&i+1<e.length&&e[i+1]==="{"){i+=2;let r=1;for(;i<e.length&&r>0;){const a=e[i];if(a==='"'||a==="'"){i=this.skipString(e,i,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,i);n.push(o.value),i=o.endIndex-1}i++}continue}e[i]==="\\"&&i++,i++}return i+1}extractIdentifier(e,t){let n=t;for(;n<e.length&&(this.isIdentifierPart(e[n])||e[n]===".");)n++;return{value:e.substring(t,n),endIndex:n}}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 Vs{componentStack=["app"];elementProps=new WeakMap;contextCache=new z(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new it;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new it,this.stateManager.onStateChange(t=>this.invalidateContextCache(t))}getPropDependencies(e,t){const n=this.findElementWithProps(t);if(!n)return[];const i=this.elementProps.get(n);if(!i||!i.has(e))return[];const r=i.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,t=!1){const n={};window[e]&&Object.assign(n,window[e]);const i=this.componentFunctions.get(e);if(i)for(const[a,o]of i)n[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 n||(n[o]=r[a])}if(t){if(window.app)for(const[o,c]of Object.entries(window.app))o in n||(n[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in n||(n[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in n||(n[c]=r[o])}}return n}getComponentPropDependencies(e,t){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const n=[],i=this.elementProps.get(e);i&&this.templateRenderer&&i.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);n.push(...o??[])});const r=Array.from(new Set(n));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 Ye(e),this.loopManager=new jt(this.stateManager,e)}extractProps(e,t){const n=new Map,i=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=t;r&&(r==="app"?o="app":r==="parent"?o=S.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<i.length;c++){const l=i[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)&&!de.isEventAttribute(l.name)&&l.value&&Ms.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const p=this.attributeToPropName(l.name),h={name:p,expression:l.value,component:o,subscriptionIds:[]};n.set(p,h)}}return n}mightReferenceSelfProps(e,t){const n=this.elementProps.get(t);if(!n)return!1;const i=Array.from(n.keys()),r=N.extractExpressions(e);if(r.length===0)return!1;for(const a of r)try{const o=j(a,{ecmaVersion:2022,sourceType:"script"}),c=new Set,l=new Set;W(o,{Identifier:(p,h)=>{const f=h?.[h.length-1];f?.type==="MemberExpression"&&f.property===p&&!f.computed||(f?.type==="FunctionExpression"||f?.type==="ArrowFunctionExpression")&&(f.params||[]).includes(p)||(f?.type==="MemberExpression"&&f.object===p?l.add(p.name):c.add(p.name))}});for(const p of i){if(p==="dataState")continue;const h=c.has(p),f=l.has(p)&&!c.has(p);if(h&&!f)return!0}}catch(o){console.error(`❌ Failed to parse mustache expression "${a}":`,o);continue}return!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}setupProps(e,t){const n=this.extractProps(e,t);n.size!==0&&(this.elementProps.set(e,n),this.expressionEvaluator&&n.forEach((i,r)=>{this.setupPropBinding(e,i)}))}setupPropBinding(e,t){if(!this.expressionEvaluator)return;const n=`prop_${Date.now()}_${Math.random()}`,i=this.templateRenderer?.dependencies(t.expression,t.component,this.stateManager)||[],r={id:n,selector:"",dependencies:new Set(i),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:t.component};this.stateManager.addSubscription(r),t.subscriptionIds.push(n)}refreshComponentBindings(e,t){this.contextInvalidated.add(t),this.contextCache.delete(t),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,t)}evaluateProps(e){const t={},n=this.elementProps.get(e);if(!n||!this.expressionEvaluator)return t;const i=n.values().next().value;if(!i)return t;const r=this.buildComponentContext(i.component);return n.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?t[o]=(...l)=>c.apply(this,l):t[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),t[o]=void 0}}),t}cleanupProps(e){const t=this.elementProps.get(e);t&&(t.forEach(n=>{n.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,t){const n=this.buildComponentContext(e);let i=this.findElementWithProps(e);if(t&&this.elementProps.has(t)&&(i=t),i)try{const r=this.evaluatePropsWithContext(i,e,t);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{n[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return n}evaluatePropsWithContext(e,t,n){const i={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return i;const a=r.values().next().value;if(!a)return i;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 b=S.getParentOfComponent(l||"app",e);o=this.buildComponentContext(b)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const p=this.loopManager?.getLoopContextForElement(e);p&&(o={...o,...p});const h=new Map,f=new Map,x=Array.from(r.keys());r.forEach((b,g)=>{x.some(A=>A!==g&&b.expression.includes(A))?f.set(g,b):h.set(g,b)}),h.forEach((b,g)=>{try{const C=this.templateRenderer?.render(b.expression,o,c||b.component);typeof C=="function"?this.isFunctionExplicitlyPassed(b.expression)?i[g]=(...k)=>C.apply(this,k):(console.warn(`⚠️ Function "${g}" not passed - not from shared namespace or explicitly passed`),i[g]=void 0):i[g]=C}catch(C){console.error(`❌ Failed to evaluate simple prop "${g}":`,C),console.error("Expression:",b.expression),console.error("Available context keys:",Object.keys(o)),i[g]=void 0}});const m={...o,...i};return f.forEach((b,g)=>{try{const C=this.templateRenderer?.render(b.expression,m,c||b.component);typeof C=="function"?this.isFunctionExplicitlyPassed(b.expression)?i[g]=(...k)=>C.apply(this,k):(console.warn(`⚠️ Function "${g}" not passed - not from shared namespace or explicitly passed`),i[g]=void 0):i[g]=C}catch(C){console.error(`❌ Failed to evaluate complex prop "${g}":`,C),console.error("Expression:",b.expression),console.error("Available context keys:",Object.keys(m)),i[g]=void 0}}),i}isFunctionExplicitlyPassed(e){const t=N.isSingleExpression(e);return t?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t.trim()):!1}findElementWithProps(e){const t=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const n of t){const i=this.elementProps.get(n);if(i&&i.size>0)return n}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 t=this.computeComponentContext(e);return this.contextCache.set(e,t),this.contextInvalidated.delete(e),t}computeComponentContext(e){const t={};if(e.includes("_loop_")||e.match(/_[a-zA-Z0-9]{8}$/)){const r=e.split("_");r.pop();const a=r.join("_");window[a]&&Object.assign(t,window[a])}e!=="app"&&window[e]&&Object.assign(t,window[e]),e==="app"&&window.app&&Object.assign(t,window.app);const n=this.componentFunctions.get(e);if(n)for(const[r,a]of n)t[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in t||(t[a]=o);if(window.app)for(const[a,o]of Object.entries(window.app))a in t||(t[a]=o)}const i=this.stateManager.getState();for(const r of Object.keys(i))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in t||(t[a]=i[r])}if(e!=="app"){for(const r of Object.keys(i))if(r.startsWith("app.")){const a=r.substring(4);a in t||(t[a]=i[r])}}return t}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const n of this.contextInvalidated.keys())this.contextInvalidated.add(n);return}const t=e.indexOf(".");if(t!==-1){const n=e.slice(0,t);this.invalidateComponent(n)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const t=this.componentStack.length,n=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),i=e===document.body;if(n||i){if(n){this.pushComponent(n);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,i).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==n?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>t;)this.popComponent()}getParentComponent(e){let t=e.parentElement;for(;t;){const n=t.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(n)return n;t=t.parentElement}return"app"}getRelevantScripts(e,t){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(n=>{if(this.processedScripts.has(n))return!1;if(t)return n.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!n.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let i=n.parentElement;for(;i&&i!==e;){if(i.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;i=i.parentElement}return i===e||e.contains(n)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const t=this.getCurrentComponent(),n=e.textContent||"",i=N.decodeEntities(n);try{const r=this.findComponentElementForScript(e,t);if(r===e){const c=this.getParentComponent(e);this.setupProps(e,c)}const a=this.hasExplicitContext(r||e,t);let o;if(a)o=this.buildComponentContextWithProps(t,r);else if(o=this.buildRestrictedComponentContext(t,!1),r&&this.hasStoredProps(r)){const c=this.evaluateProps(r);Object.assign(o,c)}window[t]||(window[t]={}),this.executeScriptFunctions(i,t,o)}catch(r){console.error(`Script execution failed in component ${t}:`,r),console.error("Script content:",i)}}hasExplicitContext(e,t){if(e.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;let n=e;for(;n&&n!==document.body;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t){if(n.hasAttribute(d.ATTR_PREFIXES.CONTEXT))return!0;break}n=n.parentElement}for(n=e.parentElement;n&&n!==document.body;){if(n.hasAttribute(d.ATTR_PREFIXES.CONTEXT)){const i=n.getAttribute(d.ATTR_PREFIXES.CONTEXT);if(i==="app"||i==="parent")return!0}n=n.parentElement}return!1}findComponentElementForScript(e,t){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return n;n=n.parentElement}const i=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);for(const r of i)if(this.elementProps.has(r))return r;return i[0]||void 0}executeScriptFunctions(e,t,n){const i=this.extractFunctionNames(e),r=this.findElementWithProps(t),a=this.extractVariableDeclarations(e);let o={...n};if(a.forEach(m=>{delete o[m];const b=`set${$t(m)}`,g=`${m}Getter`;delete o[b],delete o[g]}),r){const m=this.evaluateProps(r);Object.assign(o,m)}o.getContext=()=>this.buildComponentContextWithProps(t),o.withContext=m=>{const b=this.buildComponentContextWithProps(t);return m.call(b,b)},o.__getProp=m=>{if(r)return this.evaluateProps(r)[m]};let l=Z.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,t,r||void 0);const p=`
17
17
  ${l}
18
18
 
19
19
  ${i.map(m=>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.1.0-alpha.20",
3
+ "version": "4.1.0-alpha.21",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",